-
Notifications
You must be signed in to change notification settings - Fork 0
/
settingsreader.py
79 lines (59 loc) · 1.77 KB
/
settingsreader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import sys
import os
import fnmatch
import threading
import json
import time
class Settings():
def __init__(self):
self.stopped = False
self.initialized = False
try:
with open('config.json') as data_file:
config = json.load(data_file)
except Exception as e:
pass
if config.get("useInternal", False):
return config
def stop(self):
self.stopped = True
def get_settings(self):
print "Start Checking Drives"
while (not self.stopped):
try:
self.drive = ""
matches = []
for root, folders, files in os.walk("/media/"):
#print root
for file in fnmatch.filter(files, "config.json"):
matches.append(os.path.join(root))
# Check if we found excactly one USB Flashdrive
if len(matches) == 1:
print "Possible candidate found. Path:"
print matches[0]
self.drive = matches[0]
elif len(matches) > 1:
print "Too much candidates found. Please plug only one USB drive in."
print matches
if (self.initialized == False and len(self.drive) > 1):
with open('%s/config.json' % self.drive) as data_file:
config = json.load(data_file)
config["basedir"] = self.drive
for outer in config.get("audio_playlist", []):
for inner in config.get("audio_playlist").get(outer, []):
file = config.get("audio_playlist").get(outer).get(inner, False)
if not file:
continue
if type(file) is not str and type(file) is not unicode:
continue
if file.startswith("/"):
continue
config["audio_playlist"][outer][inner] = self.drive + "/" + file
self.initialized = True
self.stopped = True
print "Flashdrive initialised."
return config
time.sleep(1)
except KeyboardInterrupt:
print "Aborting"
return False