Exemplo n.º 1
0
#!/usr/bin/env python
'Requeue pending scenarios'
# Import custom modules
import script_process
from np import model
from np.model import Session


# If we are running the command as a script,
if __name__ == '__main__':
    # Connect
    script_process.connect()
    # List
    for processorIP, processorWhen in Session.query(model.Processor.ip, model.Processor.when_updated).order_by(model.Processor.when_updated):
        print '{}\t{}'.format(processorIP, processorWhen.strftime('%Y%m%d %H:%M'))
    # Commit
    Session.commit()
    """ Save scenario leve inputs """
    scenarioFolder = scenario.getFolder()
    store.makeFolderSafely(scenarioFolder)

    expandPath = lambda x: os.path.join(scenarioFolder, x)

    metricConfiguration = scenario.input['metric configuration'] 
    metric.saveMetricsConfigurationCSV(expandPath('metrics-job-input'), metricConfiguration)

    store.zipFolder(scenarioFolder + '.zip', scenarioFolder)


# If the user is running the script from the command-line,
if __name__ == '__main__':
    # Connect (get config and setup model from appropriate DB)
    configuration = script_process.connect()
    config['storage_path'] = configuration.get('app:main', 'storage_path')

    # get ids from stdin into a list
    ids = sys.stdin.readlines()

    # Iterate through scenarios saving input files
    scenarios = Session.query(model.Scenario).\
            filter(and_(model.Scenario.id.in_(ids), 
                   (model.Scenario.status == model.statusDone))).\
            order_by(model.Scenario.id)

    for scenario in scenarios:
        print "saving metric inputs for scenario id: %s" % scenario.id
        save_job_input_file(scenario)
Exemplo n.º 3
0
"""
Reset database
"""
# Import custom modules
import script_process
from fp.model import meta


def run():
    'Reset database'
    # Connect
    meta.metadata.bind = meta.engine
    # Reflect
    meta.metadata.reflect()
    # Clear database
    meta.metadata.drop_all()
    meta.metadata.create_all()
    # Return
    return 'Reset'


# If we are running standalone,
if __name__ == '__main__':
    # Parse
    optionParser = script_process.buildOptionParser()
    options, arguments = optionParser.parse_args()
    # Initialize
    script_process.connect(options)
    # Run
    print run()