Fixed the problem when deleting cams folder

This commit is contained in:
Sagi Frimer
2019-04-01 00:26:58 +03:00
parent f959b4de75
commit e47b571145
6 changed files with 18 additions and 13 deletions

View File

@@ -25,14 +25,18 @@ class ChameleonWebSocket(tornado.websocket.WebSocketHandler):
self.init_cameras_settings()
def init_cameras_settings(self):
if os.path.exists(self.cams_path):
for curr_dir in os.listdir(self.cams_path):
pipelines = {}
for file in os.listdir(os.path.join(self.cams_path, curr_dir)):
with open(os.path.join(self.cams_path, curr_dir, file)) as pipeline:
pipelines[os.path.splitext(file)[0]] = json.load(pipeline)
for curr_dir in os.listdir(self.cams_path):
pipelines = {}
for file in os.listdir(os.path.join(self.cams_path, curr_dir)):
with open(os.path.join(self.cams_path, curr_dir, file)) as pipeline:
pipelines[os.path.splitext(file)[0]] = json.load(pipeline)
self.cams[curr_dir] = pipelines
self.cams[curr_dir] = pipelines
else:
self.create_new_cam("cam1")
self.settings["curr_camera"] = "cam1"
self.settings["curr_pipeline"] = "pipeline1"
def init_actions(self):
self.actions["camera"] = self.change_curr_camera
@@ -124,7 +128,12 @@ class ChameleonWebSocket(tornado.websocket.WebSocketHandler):
def save_cameras(self):
for cam in self.cams:
for pipeline in self.cams[cam]:
with open(os.path.join(self.cams_path, cam, pipeline + '.json'), 'w') as pipeline_file:
path = os.path.join(self.cams_path, cam)
if not os.path.exists(path):
os.makedirs(path)
with open(os.path.join(path, pipeline + '.json'), 'w+') as pipeline_file:
json.dump(self.cams[cam][pipeline], pipeline_file)
def save_settings(self):

View File

@@ -1 +1 @@
{"exposure": 32, "brightness": 36, "hue": [10, 45], "orientation": "Normal", "camera": "3", "resolution": "Normal"}
{"exposure": 50, "brightness": 50}

View File

@@ -1 +0,0 @@
{"exposure": 23, "brightness": 12}

View File

@@ -1 +0,0 @@
{"exposure": 50, "brightness": 50}

View File

@@ -1 +0,0 @@
{"exposure": 0, "brightness": 100}

View File

@@ -1 +0,0 @@
{"exposure": 2, "brightness": 3}