Example #1
0
def run_extension(this, deployment, step, method):
    app.log(this, 'Running %s extension:' % step, method)
    extensions = utils.find_extensions()
    tempfile.tempdir = tmp = app.settings['tmp']
    cmd_tmp = tempfile.NamedTemporaryFile(delete=False)
    cmd_bin = extensions[step][method]

    if method == 'ssh-rsync':
        envlist = ['UPGRADE=yes']
    else:
        envlist = ['UPGRADE=no']

    if 'PYTHONPATH' in os.environ:
        envlist.append('PYTHONPATH=%s:%s' % (os.environ['PYTHONPATH'],
                                             app.settings['extsdir']))
    else:
        envlist.append('PYTHONPATH=%s' % app.settings['extsdir'])

    for key, value in deployment.iteritems():
        if key.isupper():
            envlist.append("%s=%s" % (key, value))

    command = ["env"] + envlist + [cmd_tmp.name]

    if step in ('write', 'configure'):
        command.append(this['sandbox'])

    if step in ('write', 'check'):
        command.append(deployment['location'])

    with app.chdir(app.settings['defdir']):
        try:
            with open(cmd_bin, "r") as infh:
                shutil.copyfileobj(infh, cmd_tmp)
            cmd_tmp.close()
            os.chmod(cmd_tmp.name, 0o700)

            if call(command):
                app.log(this, 'ERROR: %s extension failed:' % step, cmd_bin)
                raise SystemExit
        finally:
            os.remove(cmd_tmp.name)
    return
Example #2
0
def run_extension(dn, deployment, step, method):
    app.log(dn, 'Running %s extension:' % step, method)
    extensions = utils.find_extensions()
    tempfile.tempdir = app.config['tmp']
    cmd_tmp = tempfile.NamedTemporaryFile(delete=False)
    cmd_bin = extensions[step][method]

    envlist = ['UPGRADE=yes'] if method == 'ssh-rsync' else ['UPGRADE=no']

    if 'PYTHONPATH' in os.environ:
        envlist.append('PYTHONPATH=%s:%s' %
                       (os.environ['PYTHONPATH'], app.config['extsdir']))
    else:
        envlist.append('PYTHONPATH=%s' % app.config['extsdir'])

    for key, value in deployment.iteritems():
        if key.isupper():
            envlist.append("%s=%s" % (key, value))

    command = ["env"] + envlist + [cmd_tmp.name]

    if step in ('write', 'configure'):
        command.append(dn['sandbox'])

    if step in ('write', 'check'):
        command.append(
            deployment.get('location') or deployment.get('upgrade-location'))

    with app.chdir(app.config['defdir']):
        try:
            with open(cmd_bin, "r") as infh:
                shutil.copyfileobj(infh, cmd_tmp)
            cmd_tmp.close()
            os.chmod(cmd_tmp.name, 0o700)

            if call(command):
                app.log(dn, 'ERROR: %s extension failed:' % step, cmd_bin)
                raise SystemExit
        finally:
            os.remove(cmd_tmp.name)
    return
Example #3
0
def run_extension(this, deployment, step, method):
    app.log(this, "Running %s extension:" % step, method)
    extensions = utils.find_extensions()
    tempfile.tempdir = tmp = app.config["tmp"]
    cmd_tmp = tempfile.NamedTemporaryFile(delete=False)
    cmd_bin = extensions[step][method]

    envlist = ["UPGRADE=yes"] if method == "ssh-rsync" else ["UPGRADE=no"]

    if "PYTHONPATH" in os.environ:
        envlist.append("PYTHONPATH=%s:%s" % (os.environ["PYTHONPATH"], app.config["extsdir"]))
    else:
        envlist.append("PYTHONPATH=%s" % app.config["extsdir"])

    for key, value in deployment.iteritems():
        if key.isupper():
            envlist.append("%s=%s" % (key, value))

    command = ["env"] + envlist + [cmd_tmp.name]

    if step in ("write", "configure"):
        command.append(this["sandbox"])

    if step in ("write", "check"):
        command.append(deployment["location"])

    with app.chdir(app.config["defdir"]):
        try:
            with open(cmd_bin, "r") as infh:
                shutil.copyfileobj(infh, cmd_tmp)
            cmd_tmp.close()
            os.chmod(cmd_tmp.name, 0o700)

            if call(command):
                app.log(this, "ERROR: %s extension failed:" % step, cmd_bin)
                raise SystemExit
        finally:
            os.remove(cmd_tmp.name)
    return
def move_datafiles(file_data_dicts, 
                   event, 
                   destination, 
                   current_trial, 
                   trial_doc_folder, 
                   default_folder, 
                   expnum):
    '''Moves datafile from mysql-descripted location to file structure.
    file_                   = mySQL-created dictionary that hold data location info.
    event                   = Dictionary containing event information for the event that "file_" belongs to.
    destination             = Location of Experiment file structure as defined by configuration
    current_trial           = Actually is the trial number that is being worked on.
    trial_doc_folder        = Location of Documentation Files for the event. '''
    mysqldb                 = bui.conn
    julian_folder           = datetime.datetime.utcfromtimestamp(event['time']).strftime(data_retrieval_time_format)

    # Upload every file associated with event.
    for file_ in file_data_dicts:
        filename                = file_[cfg_fl_dfile]
        oscommand_source        = "%s%s%s" % (default_folder, julian_folder, filename)
        oscommand_destination   = "%sTrial-%s/Rep-1/" % (destination, current_trial)
        pubChan                 = "%s_%s_%s" % (file_[cfg_fl_net], file_[cfg_fl_sta], file_[cfg_fl_chan])
        channel_data_dict       = mysqldb.retrieve_channel_position(pubChan, event[cfg_evt_time])
        file_extensions         = utils.find_extensions(oscommand_source)            

        report.append_report_if_valid(trial_doc_folder, 
                                      file_, 
                                      channel_data_dict, 
                                      event[cfg_evt_evid])

        utils.copy_file_exts(oscommand_source, 
                             oscommand_destination, 
                             file_extensions)

        upload_and_post(expnum, 
                        current_trial, 
                        oscommand_destination, 
                        filename, 
                        file_extensions)