Skip to content
Snippets Groups Projects
Commit 8e72424b authored by Wact B. Prot's avatar Wact B. Prot
Browse files

.get()

parent 976be479
Branches
No related tags found
No related merge requests found
......@@ -100,7 +100,7 @@ class Anselm(System):
line_key = self.get_line_key(line)
doc_id = self.state[line_key]['doc_id']
doc_id = self.state.get(line_key).get('doc_id')
task_name = combo.currentText()
self.state[line_key]['task_name'] = task_name
......
......@@ -12,9 +12,9 @@ class DB(System):
self.log.info("database ")
def init_db(self):
db_dict = self.config['couchdb']
port = db_dict['port']
host = db_dict['host']
db_dict = self.config.get('couchdb')
port = db_dict.get('port')
host = db_dict.get('host')
url = 'http://{}:{}/'.format(host, port)
self.db_dict = db_dict
......@@ -23,10 +23,10 @@ class DB(System):
self.log.info("long-term memory system ok")
def store_doc(self, doc):
id = doc['_id']
id = doc.get('_id')
dbdoc = self.db[id]
if dbdoc:
doc['_rev'] = dbdoc['_rev']
doc['_rev'] = dbdoc.get('_rev')
else:
doc.pop('_rev', None)
......@@ -34,19 +34,19 @@ class DB(System):
def get_auxobj_ids(self):
view = self.db_dict['view']['auxobj']
view = self.db_dict.get('view').get('auxobj')
return [doc['id'] for doc in self.db.view(view)]
return [doc.get('id') for doc in self.db.view(view)]
def get_red_doc(self, doc_id):
doc = self.db[doc_id]
red_doc = None
if doc:
if 'AuxObject' in doc:
red_doc = doc['AuxObject']
red_doc = doc.get('AuxObject')
if 'CalibrationObject' in doc:
red_doc = doc['CalibrationObject']
red_doc = doc.get('CalibrationObject')
else:
self.log.error("no doc with id {}".format(doc_id))
......@@ -58,20 +58,20 @@ class DB(System):
def get_task_names(self, doc_id):
doc = self.get_red_doc(doc_id)
if doc and 'Task' in doc:
return [task['TaskName'] for task in doc['Task']]
return [task.get('TaskName') for task in doc.get('Task')]
else:
return []
def get_task(self, doc_id, task_name):
doc = self.get_red_doc(doc_id)
if doc and 'Task' in doc:
tasks = doc['Task']
tasks = doc.get('Task')
for task in tasks:
if task['TaskName'] == task_name:
if task.get('TaskName') == task_name:
break
if 'Defaults' in doc:
defaults = doc['Defaults']
defaults = doc.get('Defaults')
task = self.replace_defaults(task=task, defaults=defaults)
return task
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment