def importcalc(host, calc_id, username, password):
    """
    Import a remote calculation into the local database
    """
    if '/' in host.split('//', 1)[1]:
        sys.exit('Wrong host ending with /%s' % host.rsplit('/', 1)[1])
    calc_url = '/'.join([host, 'v1/calc', str(calc_id)])
    dbserver.ensure_on()
    job = logs.dbcmd('get_job', calc_id)
    if job is not None:
        sys.exit('There is already a job #%d in the local db' % calc_id)

    datadir = datastore.get_datadir()
    session = login(host, username, password)
    status = session.get('%s/status' % calc_url)
    if 'Log in to an existing account' in status.text:
        sys.exit('Could not login')
    json = status.json()
    if json["parent_id"]:
        sys.exit('The job has a parent (#%(parent_id)d) and cannot be '
                 'downloaded' % json)
    resp = session.get('%s/datastore' % calc_url, stream=True)
    assert resp.status_code == 200, resp.status_code
    fname = '%s/calc_%d.hdf5' % (datadir, calc_id)
    down = 0
    with open(fname, 'wb') as f:
        logging.info('%s -> %s', calc_url, fname)
        for chunk in resp.iter_content(CHUNKSIZE):
            f.write(chunk)
            down += len(chunk)
            general.println('Downloaded {:,} bytes'.format(down))
    print()
    with datastore.read(calc_id) as dstore:
        engine.expose_outputs(dstore, json['owner'], json['status'])
    logging.info('Imported calculation %d successfully', calc_id)
Exemple #2
0
 def dump(self, fname):
     """
     Dump the remote datastore on a local path.
     """
     url = '%s/v1/calc/%d/datastore' % (self.server, self.calc_id)
     resp = self.sess.get(url, stream=True)
     down = 0
     with open(fname, 'wb') as f:
         logging.info('Saving %s', fname)
         for chunk in resp.iter_content(CHUNKSIZE):
             f.write(chunk)
             down += len(chunk)
             println('Downloaded {:,} bytes'.format(down))
     print()
Exemple #3
0
 def dump(self, fname):
     """
     Dump the remote datastore on a local path.
     """
     url = '%s/v1/calc/%d/datastore' % (self.server, self.calc_id)
     resp = self.sess.get(url, stream=True)
     down = 0
     with open(fname, 'wb') as f:
         logging.info('Saving %s', fname)
         for chunk in resp.iter_content(CHUNKSIZE):
             f.write(chunk)
             down += len(chunk)
             println('Downloaded {:,} bytes'.format(down))
     print()