Exemplo n.º 1
0
 def fetch_nexson(self, study_id, output_filepath=None, store_raw=False):
     '''Calls export_gzipNexSON URL and unzips response.
     Raises HTTP error, gzip module error, or RuntimeError
     '''
     if study_id.startswith('pg_'):
         study_id = study_id[3:]  #strip pg_ prefix
     uri = self.domain + '/study/export_gzipNexSON.json/' + study_id
     _LOG.debug('Downloading %s using "%s"\n', study_id, uri)
     resp = requests.get(uri,
                         headers=GZIP_REQUEST_HEADERS,
                         allow_redirects=True)
     resp.raise_for_status()
     try:
         uncompressed = gzip.GzipFile(mode='rb',
                                      fileobj=StringIO(
                                          resp.content)).read()
         results = uncompressed
     except:
         raise
     if is_str_type(results):
         if output_filepath is None:
             return anyjson.loads(results)
         else:
             if store_raw:
                 write_to_filepath(results, output_filepath)
             else:
                 write_as_json(anyjson.loads(results), output_filepath)
             return True
     raise RuntimeError(
         'gzipped response from phylografter export_gzipNexSON.json, but not a string is:',
         results)
Exemplo n.º 2
0
 def fetch_nexson(self, study_id, output_filepath=None, store_raw=False):
     '''Calls export_gzipNexSON URL and unzips response.
     Raises HTTP error, gzip module error, or RuntimeError
     '''
     if study_id.startswith('pg_'):
         study_id = study_id[3:] #strip pg_ prefix
     uri = self.domain + '/study/export_gzipNexSON.json/' + study_id
     _LOG.debug('Downloading %s using "%s"\n', study_id, uri)
     resp = requests.get(uri,
                         headers=GZIP_REQUEST_HEADERS,
                         allow_redirects=True)
     resp.raise_for_status()
     try:
         uncompressed = gzip.GzipFile(mode='rb',
                                      fileobj=StringIO(resp.content)).read()
         results = uncompressed
     except:
         raise
     if is_str_type(results):
         if output_filepath is None:
             return anyjson.loads(results)
         else:
             if store_raw:
                 write_to_filepath(results, output_filepath)
             else:
                 write_as_json(anyjson.loads(results), output_filepath)
             return True
     raise RuntimeError('gzipped response from phylografter export_gzipNexSON.json, but not a string is:', results)
Exemplo n.º 3
0
 def _write_master_branch_resource(self, content, fn, commit_msg, is_json=False):
     '''This will force the current branch to master! '''
     #TODO: we might want this to push, but currently it is only called in contexts in which
     # we are about to push any way (study creation)
     with self._master_branch_repo_lock:
         ga = self._create_git_action_for_global_resource()
         with ga.lock():
             ga.checkout_master()
             if is_json:
                 write_as_json(content, fn)
             else:
                 write_to_filepath(content, fn)
             ga._add_and_commit(fn, self._infrastructure_commit_author, commit_msg)
Exemplo n.º 4
0
 def _write_master_branch_resource(self, content, fn, commit_msg, is_json=False):
     '''This will force the current branch to master! '''
     #TODO: we might want this to push, but currently it is only called in contexts in which
     # we are about to push any way (study creation)
     with self._master_branch_repo_lock:
         ga = self._create_git_action_for_global_resource()
         with ga.lock():
             ga.checkout_master()
             if is_json:
                 write_as_json(content, fn)
             else:
                 write_to_filepath(content, fn)
             ga._add_and_commit(fn, self._infrastructure_commit_author, commit_msg)