Esempio n. 1
0
def clean(context, force, date, case_name):
    """Clean up files for an analysis."""
    manager = api.manager(context.obj['database'])
    run_obj = run_orabort(context, case_name, date)
    if force or click.confirm('Are you sure?'):
        api.clean_up(context.obj['root'], run_obj, force=force)
        manager.commit()
Esempio n. 2
0
def scout(context, madeline_exe, date, replace, case_name):
    """Prepare a config and files for Scout."""
    madeline_exe = madeline_exe or context.obj['madeline_exe']
    manager = api.manager(context.obj['database'])
    root_path = context.obj['root']
    run_obj = run_orabort(context, case_name, date)
    if not run_obj.pipeline_version.startswith('v4'):
        log.error("unsupported pipeline version: %s", run_obj.pipeline_version)
        context.abort()

    existing_conf = (api.assets(category='scout-config', run_id=run_obj.id)
                        .first())
    if existing_conf:
        if replace:
            log.info("deleting existing scout config: %s", existing_conf.path)
            api.delete_asset(existing_conf)
            existing_mad = (api.assets(category='madeline', run_id=run_obj.id)
                               .first())
            if existing_mad:
                log.info("deleting existing madeline: %s", existing_mad.path)
                api.delete_asset(existing_mad)
            manager.commit()
        else:
            log.error("scout config already generated")
            context.abort()

    prepare_scout(run_obj, root_path, madeline_exe)
    manager.commit()
Esempio n. 3
0
def extend(context, no_link, date, category, sample, archive_type, case_name,
           asset_path):
    """Add an additional asset to a run."""
    manager = api.manager(context.obj['database'])
    run_obj = run_orabort(context, case_name, date)
    if sample:
        sample_map = {smpl.name: smpl for smpl in run_obj.samples}
        sample_obj = sample_map[sample]
    else:
        sample_obj = None
    new_asset = api.add_asset(run_obj, asset_path, category, archive_type,
                              sample=sample_obj)

    root_path = context.obj['root']
    run_root = get_rundir(root_path, run_obj.case.name, run_obj)
    filename = new_asset.basename()
    if no_link:
        new_path = asset_path
    else:
        new_path = run_root.joinpath(filename)
        log.debug("link asset: %s -> %s", new_asset.original_path, new_path)
        path(new_asset.original_path).link(new_path)

    new_asset.path = new_path
    run_obj.assets.append(new_asset)
    log.info("add asset: %s", new_asset.path)
    manager.commit()
Esempio n. 4
0
def postpone(context, days, case_name):
    """Ask Housekeeper for a file."""
    manager = api.manager(context.obj['database'])
    run_obj = run_orabort(case_name)
    api.postpone(run_obj, time=datetime.timedelta(days=days))
    manager.commit()
    click.echo("analysis will be archived on: {}"
               .format(run_obj.will_cleanup_at))
Esempio n. 5
0
def status(context, date, now, run_date, sample_status, run_status,
           extra_status, identifier):
    """Mark dates for resources."""
    manager = api.manager(context.obj['database'])

    # determine which date to set: custom or now!
    if date:
        status_date = parse_date(date)
    elif now:
        status_date = datetime.datetime.now()
    else:
        status_date = None

    if sample_status:
        # update a date for a sample
        model_obj = api.sample(identifier)
        if model_obj is None:
            click.echo("can't find sample")
            context.abort()
        # types are predefined; no need to check!
        status_type = sample_status
    else:
        # update a date for an analysis run
        model_obj = run_orabort(context, identifier, run_date)
        # types are predefined as well
        status_type = run_status

    if extra_status:
        if model_obj.extra is None:
            log.info("adding extra data record")
            model_obj.extra = ExtraRunData()
            manager.commit()
        extra_date_key = "{}_date".format(extra_status)
        if status_date is None:
            # show a custom date for an analysis run
            current_date = getattr(model_obj.extra, extra_date_key)
        else:
            # update a custom date for a run
            setattr(model_obj.extra, extra_date_key, status_date)
            status_field = extra_status
    else:
        status_field = "{}_at".format(status_type)
        if status_date is None:
            # show a predfined date for a model
            current_date = getattr(model_obj, status_field)
        else:
            # update a predefined date on a model
            setattr(model_obj, status_field, status_date)

    if status_date is None:
        if current_date is None:
            context.abort()
        else:
            click.echo(current_date)
    else:
        log.info("updating %s -> %s", status_field, status_date)
        manager.commit()
Esempio n. 6
0
def delete_analysis(context, date, yes, case_name):
    """Delete an analysis run and files."""
    manager = api.manager(context.obj['database'])
    run_obj = run_orabort(context, case_name, date)
    root_path = context.obj['root']
    run_root = get_rundir(root_path, case_name, run_obj)
    click.echo("you are about to delete: {}".format(run_root))
    if yes or click.confirm('Are you sure?'):
        api.delete(root_path, run_obj)
        manager.commit()
Esempio n. 7
0
def archive(context, date, force, case_name):
    """Archive compiled assets to PDC."""
    manager = api.manager(context.obj['database'])
    run_obj = run_orabort(context, case_name, date)
    if not run_obj.compiled_at:
        log.warn("run not compiled yet: %s", case_name)
        if force or click.confirm("do you want to compile the run?"):
            date_str = run_obj.analyzed_at.date().isoformat()
            context.invoke(compile_cmd, date=date_str, force=True,
                           case_name=case_name)
            # refresh the run object
            run_obj = AnalysisRun.query.get(run_obj.id)
        else:
            context.abort()

    if force or click.confirm("are you sure you want to archive the run?"):
        archive_run(run_obj, force=force)
        manager.commit()