示例#1
0
def docker_run(image, args, mount=None, env_mount=None, flags=()):
    cmds_mount = []
    cmds_env_mount = []
    if mount:
        for (f1, f2) in mount:
            cmds_mount += [
                docker_opt_mount(el.expand_file_name(f1),
                                 el.expand_file_name(f2))
            ]
    if env_mount:
        for (d, e) in env_mount:
            el.make_directory(d)
            cmds_env_mount += [docker_opt_env_mount(e, el.expand_file_name(d))]
    cmds = [
        "docker run", "-i" if "-T" in flags else docker_opt_tty(),
        docker_opt_cleanup(), "" if "-H" in flags else docker_opt_all_ports(),
        docker_opt_user(),
        docker_opt_display(),
        docker_opt_mount(dd, dd),
        lf("-w '{dd}'")
    ]
    cmds += cmds_env_mount
    cmds += cmds_mount
    cmds += [
        docker_opt_mount("/etc/group", "/etc/group", "ro"),
        docker_opt_mount("/etc/passwd", "/etc/passwd", "ro"),
        docker_opt_mount(dd, dd),
        lf("{image} bash -e -c '{args}'")
    ]
    return " ".join(cmds)
示例#2
0
def log_file_name(base_dir, book, recipe):
    sub_dir = "_".join(el.delete("",
                                 os.path.normpath(book).split(os.sep)[:-1]))
    full_dir = el.expand_file_name(sub_dir, base_dir)
    el.make_directory(full_dir)
    ts = el.replace_regexp_in_string(" ", "_", el.timestamp())
    name = el.lf("{ts}-{recipe}.txt")
    return el.expand_file_name(name, full_dir)
示例#3
0
def git_clone(url, target_dir, commit=None):
    target_dir = el.expand_file_name(target_dir)
    if el.file_exists_p(target_dir):
        print(lf("{target_dir}: OK"))
    else:
        gdir = el.expand_file_name(target_dir)
        pdir = el.file_name_directory(gdir)
        if not el.file_exists_p(pdir):
            el.make_directory(pdir)
        (_, gdir) = el.parse_fname(gdir)
        sc("git clone --recursive {url} {gdir}")
        if commit:
            sc("cd {gdir} && git reset --hard {commit}")
示例#4
0
def clone(remote, local):
    res = []
    local = el.expand_file_name(local)
    if el.file_exists_p(local):
        if el.file_exists_p(el.expand_file_name(".git", local)):
            res += ["cd " + local, "git pull"]
        else:
            raise RuntimeError("Directory exists and is not a git repo", local)
    else:
        (bd, repo) = os.path.split(local)
        el.make_directory(bd)
        res += [lf("cd {bd}"), lf("git clone {remote} {repo}")]
    return res