Пример #1
0
def _default_import_run(run, dest, move, copy_resources):
    if move:
        log.info("Moving %s", run.id)
        if copy_resources:
            shutil.copytree(run.path, dest)
            util.safe_rmtree(run.path)
        else:
            shutil.move(run.path, dest)
    else:
        log.info("Copying %s", run.id)
        shutil.copytree(run.path, dest, symlinks=not copy_resources)
Пример #2
0
def _init_published_run(state):
    """Ensure empty target directory for published run.

    As a side effect, lazily creates `state.dest_home` and creates
    `.guild-nocopy` to ensure that the published runs home is not
    considered by Guild for source snapshots.
    """
    util.ensure_dir(state.dest_home)
    util.touch(os.path.join(state.dest_home, ".guild-nocopy"))
    if os.path.exists(state.run_dest):
        util.safe_rmtree(state.run_dest)
    os.mkdir(state.run_dest)
Пример #3
0
def _copy_source(source_path, dest_path, replace_existing=False):
    assert os.path.isabs(dest_path), dest_path
    if os.path.lexists(dest_path) or os.path.exists(dest_path):
        if not replace_existing:
            log.warning("%s already exists, skipping copy", dest_path)
            return
        log.debug("deleting existing source dest %s", dest_path)
        util.safe_rmtree(dest_path)
    util.ensure_dir(os.path.dirname(dest_path))
    log.debug("resolving source %s as copy %s", source_path, dest_path)
    if os.path.isdir(source_path):
        util.copytree(source_path, dest_path)
    else:
        util.copyfile(source_path, dest_path)
Пример #4
0
def _link_to_source(source_path, link, replace_existing=False):
    assert os.path.isabs(link), link
    source_path = util.strip_trailing_sep(source_path)
    if os.path.lexists(link) or os.path.exists(link):
        if not replace_existing:
            log.warning("%s already exists, skipping link", link)
            return
        log.debug("deleting existing source link %s", link)
        util.safe_rmtree(link)
    util.ensure_dir(os.path.dirname(link))
    log.debug("resolving source %s as link %s", source_path, link)
    source_rel_path = _source_rel_path(source_path, link)
    try:
        util.symlink(source_rel_path, link)
    except OSError as e:
        _handle_source_link_error(e)
Пример #5
0
def _export_runs_to_dir(runs, dir, move, copy_resources, quiet):
    _init_export_dir(dir)
    exported = []
    for run in runs:
        dest = os.path.join(dir, run.id)
        if os.path.exists(dest):
            log.warning("%s exists, skipping", dest)
            continue
        if move:
            if not quiet:
                log.info("Moving %s", run.id)
            if copy_resources:
                shutil.copytree(run.path, dest)
                util.safe_rmtree(run.path)
            else:
                shutil.move(run.path, dest)
        else:
            if not quiet:
                log.info("Copying %s", run.id)
            follow_links = not copy_resources
            shutil.copytree(run.path, dest, follow_links)
        exported.append(run)
    return exported
Пример #6
0
 def _delete_run(self, name):
     path = os.path.join(self.logdir, name)
     util.safe_rmtree(path)
Пример #7
0
def _delete_exported_runs(runs):
    for run in runs:
        util.safe_rmtree(run.path)