In [2]:
# sudo -i -u couchdb /home/couchdb/couchdb/bin/couchdb
import couchdb
couch = couchdb.Server('http://stephan:stephan123@localhost:5984')
#db = couch.create('test')
db = couch['test']
In [12]:
import dkrz_forms.utils
In [14]:
workflow_dict = dkrz_forms.utils.jsonfile_to_dict('/home/stephan/tmp/Repos/form_repo/CORDEX/CORDEX_bb_bb1.json')
In [22]:
def clean_dict(a_dict):
if '__doc__' in a_dict.keys():
a_dict.pop('__doc__')
for a,b in a_dict.iteritems():
if isinstance(b,dict):
clean_dict(b)
In [23]:
clean_dict(workflow_dict)
In [24]:
workflow_dict
Out[24]:
{u'da': {u'activity': {u'comment': u'',
u'status': u'',
u'ticket_id': u'',
u'timestamp': u''},
u'agent': {u'responsible_person': u''},
u'entities out': {u'facet_string': u'',
u'pid_collections': u'',
u'publish_date': u'',
u'search_string': u''},
u'entities_in': {u'comment': u'',
u'date': u'',
u'facet_string': u'# e.g. project=A&model=B& ....',
u'i_name': u'publication_report',
u'repo': u'',
u'report': {},
u'status': u'',
u'tag': u''}},
u'form_dir': u'/home/stephan/Repos/ENES-EUDAT/submission_forms/test/forms/CORDEX',
u'ing': {u'activity': {u'comment': u'',
u'end_time': u'',
u'i_name': u'ingest_activity',
u'report': {u'comment': u''},
u'start_time': u'',
u'status': u'',
u'ticket_id': 0},
u'agent': {u'i_name': u'ingest_agent', u'responsible_person': u''},
u'entity_in': {u'comment': u'',
u'date': u'',
u'i_name': u'review_report',
u'repo': u'',
u'report': {},
u'status': u'',
u'tag': u''},
u'entity_out': {u'comment': u'',
u'date': u'',
u'i_name': u'ingest_report',
u'report': {},
u'status': u'',
u'tag': u''},
u'i_name': u'data_ingest'},
u'project': u'CORDEX',
u'pub': {u'activity': {u'comment': u'...',
u'end_time': u'..',
u'follow_up_ticket': u'',
u'i_name': u'publication_activity',
u'report': {},
u'start_time': u'',
u'status': u'',
u'ticket_id': u''},
u'agent': {u'i_name': u'publication_agent',
u'publication_tool': u'',
u'responsible_person': u'katharina'},
u'entity_in': {u'comment': u'',
u'date': u'',
u'i_name': u'qua_report',
u'repo': u'',
u'report': {},
u'status': u'',
u'tag': u''},
u'entity_out': {u'comment': u'',
u'date': u'',
u'facet_string': u'# e.g. project=A&model=B& ....',
u'i_name': u'publication_report',
u'repo': u'',
u'report': {},
u'status': u'',
u'tag': u''},
u'i_name': u'data_publication'},
u'qua': {u'activity': {u'comment': u'',
u'end_time': u'',
u'follow_up_ticket': u'',
u'i_name': u'qua_activity',
u'report': {},
u'start_time': u'',
u'status': u'',
u'ticket_id': u''},
u'agent': {u'i_name': u'qua_agent', u'responsible_person': u''},
u'entity_in': {u'comment': u'',
u'date': u'',
u'i_name': u'ingest_report',
u'report': {},
u'status': u'',
u'tag': u''},
u'entity_out': {u'comment': u'',
u'date': u'',
u'i_name': u'qua_report',
u'repo': u'',
u'report': {},
u'status': u'',
u'tag': u''},
u'i_name': u'data_quality_assurance'},
u'rev': {u'activity': {u'comment': u'',
u'end_time': u'...',
u'i_name': u'review_activity',
u'report': {},
u'review_comment': u'corrected information related to quality of submitted data',
u'review_status': u'reviewed',
u'start_time': u'...',
u'status': u'',
u'ticket_id': u'25389',
u'ticket_url': u'https://dm-rt.dkrz.de/Ticket/Display.html?'},
u'agent': {u'i_name': u'review_agent', u'responsible_person': u'stephan'},
u'entity_in': {u'checks_done': u'',
u'form_dir': u'',
u'form_json': u'',
u'form_name': u'',
u'form_path': u'',
u'form_repo': u'',
u'form_repo_path': u'',
u'i_name': u'submission_form_entity',
u'repo': u'',
u'report': {},
u'status': u'',
u'tag': u''},
u'entity_out': {u'comment': u'This submission is related to submission abc_cde',
u'date': u'...',
u'i_name': u'review_report',
u'repo': u'',
u'report': {u'x': u'y'},
u'status': u'',
u'tag': u'abc_cde'},
u'i_name': u'data_submission_review'},
u'sub': {u'activity': {u'i_name': u'submission_activity',
u'keyword': u'bb1',
u'pwd': u'7AXT2W',
u'submission_comment': u'',
u'submission_method': u''},
u'agent': {u'email': u'bb',
u'first_name': u'bb',
u'i_name': u'submission_agent',
u'key_word': u'',
u'last_name': u'bb'},
u'entity_in': {u'form_json': u'/home/stephan/Repos/ENES-EUDAT/submission_forms/test/forms/CORDEX/CORDEX_bb_bb1.json',
u'form_path': u'/home/stephan/Repos/ENES-EUDAT/submission_forms/test/forms/CORDEX/CORDEX_bb_bb1.ipynb',
u'form_template_version': u'',
u'i_name': u'submission_form_template_entity',
u'source_path': u'',
u'tag': u''},
u'entity_out': {u'checks_done': u'',
u'form_dir': u'',
u'form_json': u'/home/stephan/tmp/Repos/form_repo/CORDEX/CORDEX_bb_bb1.json',
u'form_name': u'CORDEX_bb_bb1',
u'form_path': u'',
u'form_repo': u'/home/stephan/tmp/Repos/form_repo/CORDEX',
u'form_repo_path': u'/home/stephan/tmp/Repos/form_repo/CORDEX/CORDEX_bb_bb1.ipynb',
u'i_name': u'submission_form_entity',
u'pwd': u'7AXT2W',
u'repo': u'',
u'report': {u'data_information': u'',
u'data_path': u'',
u'data_qc_comment': u'',
u'data_qc_status': u'',
u'directory_structure': u'',
u'email': u'',
u'example_file_name': u'',
u'exclude_variables_list': u'',
u'experiment_id': u'',
u'first_name': u'',
u'grid_as_specified_if_rotated_pole': u'',
u'grid_mapping_name': u'',
u'institute_id': u'',
u'institution': u'',
u'last_name': u'',
u'model_id': u'',
u'project': u'CORDEX',
u'submission_type': u'',
u'terms_of_use': u'',
u'time_period': u'',
u'uniqueness_of_tracking_id': u'',
u'variable_list_day': u'',
u'variable_list_fx': u'',
u'variable_list_mon': u'',
u'variable_list_sem': u''},
u'status': u'',
u'tag': u''},
u'i_name': u'data_submission',
u'id': u'61724afc-510f-11e7-bf03-080027f178b4',
u'submission_repo': u'/home/stephan/tmp/Repos/submission_repo/CORDEX'},
u'workflow': [[u'sub', u'data_submission'],
[u'rev', u'data_submission_review'],
[u'ing', u'data_ingest'],
[u'qua', u'data_quality_assurance'],
[u'pub', u'data_publication'],
[u'da', u'data_archival']]}
In [25]:
db.save(workflow_dict)
Out[25]:
(u'127ecf70d984145afd29a04e15000e6e', u'1-210809cc002b5e90a1710916fe1c89ef')
In [27]:
test = db['127ecf70d984145afd29a04e15000e6e']
In [32]:
def fun(doc):
if 'project' in doc:
yield doc['project'], doc
In [33]:
for row in db.query(fun):
print row.key
---------------------------------------------------------------------------
ServerError Traceback (most recent call last)
<ipython-input-33-943a50fbf3ac> in <module>()
----> 1 for row in db.query(fun):
2 print row.key
/home/stephan/.conda/envs/generic1/lib/python2.7/site-packages/couchdb/client.pyc in __iter__(self)
1257
1258 def __iter__(self):
-> 1259 return iter(self.rows)
1260
1261 def __len__(self):
/home/stephan/.conda/envs/generic1/lib/python2.7/site-packages/couchdb/client.pyc in rows(self)
1277 """
1278 if self._rows is None:
-> 1279 self._fetch()
1280 return self._rows
1281
/home/stephan/.conda/envs/generic1/lib/python2.7/site-packages/couchdb/client.pyc in _fetch(self)
1263
1264 def _fetch(self):
-> 1265 data = self.view._exec(self.options)
1266 wrapper = self.view.wrapper or Row
1267 self._rows = [wrapper(row) for row in data['rows']]
/home/stephan/.conda/envs/generic1/lib/python2.7/site-packages/couchdb/client.pyc in _exec(self, options)
1163 _, _, data = self.resource.post_json(body=content, headers={
1164 'Content-Type': 'application/json'
-> 1165 }, **_encode_view_options(options))
1166 return data
1167
/home/stephan/.conda/envs/generic1/lib/python2.7/site-packages/couchdb/http.pyc in post_json(self, path, body, headers, **params)
564 def post_json(self, path=None, body=None, headers=None, **params):
565 return self._request_json('POST', path, body=body, headers=headers,
--> 566 **params)
567
568 def put_json(self, path=None, body=None, headers=None, **params):
/home/stephan/.conda/envs/generic1/lib/python2.7/site-packages/couchdb/http.pyc in _request_json(self, method, path, body, headers, **params)
583 def _request_json(self, method, path=None, body=None, headers=None, **params):
584 status, headers, data = self._request(method, path, body=body,
--> 585 headers=headers, **params)
586 if 'application/json' in headers.get('content-type', ''):
587 data = json.decode(data.read().decode('utf-8'))
/home/stephan/.conda/envs/generic1/lib/python2.7/site-packages/couchdb/http.pyc in _request(self, method, path, body, headers, **params)
579 return self.session.request(method, url, body=body,
580 headers=all_headers,
--> 581 credentials=self.credentials)
582
583 def _request_json(self, method, path=None, body=None, headers=None, **params):
/home/stephan/.conda/envs/generic1/lib/python2.7/site-packages/couchdb/http.pyc in request(self, method, url, body, headers, credentials, num_redirects)
419 raise PreconditionFailed(error)
420 else:
--> 421 raise ServerError((status, error))
422
423 # Store cachable responses
ServerError: (403, (u'forbidden', u'Temporary views are not supported in CouchDB'))
In [ ]:
Content source: IS-ENES-Data/submission_forms
Similar notebooks: