Пример #1
0
def persist_file(f, experiment_id, run_group):
    """
    Persist a file in the FileContent relation.

    Args:
        f (str):
            The filename we want to persist.
        experiment_id (uuid):
            The experiment uuid this file needs to be assigned to.
        run_group (uuid):
            The run group uuid this file needs to be assigned to.
    """
    from benchbuild.utils.schema import Session
    import pathlib
    session = Session()

    filename = os.path.basename(f)
    filepath = pathlib.Path(f)
    session = Session()
    session.add(
        FileContent(experience_id=experiment_id,
                    rungroup_id=run_group,
                    filename=filename,
                    content=filepath.read_bytes()))
    session.commit()
Пример #2
0
def persist_experiment(experiment):
    """
    Persist this experiment in the benchbuild database.

    Args:
        experiment: The experiment we want to persist.
    """
    from benchbuild.utils.schema import Experiment, Session

    session = Session()

    cfg_exp = experiment.id
    LOG.debug("Using experiment ID stored in config: %s", cfg_exp)
    exps = session.query(Experiment).filter(Experiment.id == cfg_exp)
    desc = str(CFG["experiment_description"])
    name = experiment.name

    if exps.count() == 0:
        newe = Experiment()
        newe.id = cfg_exp
        newe.name = name
        newe.description = desc
        session.add(newe)
        ret = newe
    else:
        exps.update({'name': name, 'description': desc})
        ret = exps.first()

    try:
        session.commit()
    except IntegrityError:
        session.rollback()
        persist_experiment(experiment)

    return (ret, session)
Пример #3
0
def persist_experiment(experiment):
    """
    Persist this experiment in the benchbuild database.

    Args:
        experiment: The experiment we want to persist.
    """
    from benchbuild.utils.schema import Experiment, Session

    session = Session()

    cfg_exp = CFG['experiment_id'].value()
    exps = session.query(Experiment).filter(Experiment.id == cfg_exp)
    desc = CFG["experiment_description"].value()
    name = experiment.name

    if exps.count() == 0:
        newe = Experiment()
        newe.id = cfg_exp
        newe.name = name
        newe.description = desc
        session.add(newe)
        ret = newe
        logger.debug("New experiment: %s", newe)
    else:
        exps.update({'name': name, 'description': desc})
        logger.debug("Update experiments: %s", exps)
        ret = exps.first()
    try:
        session.commit()
    except IntegrityError as ie:
        session.rollback()
        persist_experiment(experiment)

    return (ret, session)
Пример #4
0
def persist_experiment(experiment):
    """
    Persist this experiment in the benchbuild database.

    Args:
        experiment: The experiment we want to persist.
    """
    from benchbuild.utils.schema import Experiment, Session

    session = Session()

    cfg_exp = experiment.id
    LOG.debug("Using experiment ID stored in config: %s", cfg_exp)
    exps = session.query(Experiment).filter(Experiment.id == cfg_exp)
    desc = str(CFG["experiment_description"])
    name = experiment.name

    if exps.count() == 0:
        newe = Experiment()
        newe.id = cfg_exp
        newe.name = name
        newe.description = desc
        session.add(newe)
        ret = newe
    else:
        exps.update({'name': name, 'description': desc})
        ret = exps.first()

    try:
        session.commit()
    except IntegrityError:
        session.rollback()
        persist_experiment(experiment)

    return (ret, session)
Пример #5
0
def persist_project(project):
    """
    Persist this project in the benchbuild database.

    Args:
        project: The project we want to persist.
    """
    from benchbuild.utils.schema import Project, Session
    session = Session()
    projects = session.query(Project) \
        .filter(Project.name == project.name) \
        .filter(Project.group_name == project.group)

    name = project.name
    desc = project.__doc__
    domain = project.domain
    group_name = project.group
    version = project.version() \
        if callable(project.version) else project.version
    try:
        src_url = project.src_uri
    except AttributeError:
        src_url = 'unknown'

    if projects.count() == 0:
        newp = Project()
        newp.name = name
        newp.description = desc
        newp.src_url = src_url
        newp.domain = domain
        newp.group_name = group_name
        newp.version = version
        LOG.debug("Poject INSERT: %s", newp)
        session.add(newp)
    else:
        newp_value = {
            "name": name,
            "description": desc,
            "src_url": src_url,
            "domain": domain,
            "group_name": group_name,
            "version": version
        }
        LOG.debug("Project UPDATE: %s", newp_value)
        projects.update(newp_value)

    session.commit()
    return (projects, session)
Пример #6
0
def persist_project(project):
    """
    Persist this project in the benchbuild database.

    Args:
        project: The project we want to persist.
    """
    from benchbuild.utils.schema import Project, Session
    session = Session()
    projects = session.query(Project) \
        .filter(Project.name == project.name) \
        .filter(Project.group_name == project.group)

    name = project.name
    desc = project.__doc__
    domain = project.domain
    group_name = project.group
    version = project.version() \
        if callable(project.version) else project.version
    try:
        src_url = project.src_uri
    except AttributeError:
        src_url = 'unknown'

    if projects.count() == 0:
        newp = Project()
        newp.name = name
        newp.description = desc
        newp.src_url = src_url
        newp.domain = domain
        newp.group_name = group_name
        newp.version = version
        session.add(newp)
    else:
        newp_value = {
            "name": name,
            "description": desc,
            "src_url": src_url,
            "domain": domain,
            "group_name": group_name,
            "version": version
        }
        projects.update(newp_value)

    session.commit()
    return (projects, session)