# Path: doodad/utils/cmd_builder.py
# class CommandBuilder(object):
#     def __init__(self):
#     def append(self, cmd, *args):
#     def echo(self, msg):
#     def to_string(self, separator=';'):
#     def __str__(self):
#     def __iter__(self):
#     def dump_script(self):


import os
import pathlib
import sys
import tempfile
import shutil
import time
import subprocess
import uuid
import contextlib
import uuid
import doodad
from doodad.utils import cmd_builder
    docker_hook_file = os.path.join(arch_dir, script_name)
    builder = cmd_builder.CommandBuilder()
    builder.append('#!/bin/bash')
    #if verbose:
    #    builder.echo('All script arguments:')
    #    builder.echo('$@')
    mnt_cmd = ''.join([' -v %s:%s' % (mnt.sync_dir, mnt.mount_point)
        for mnt in mounts if mnt.writeable])
    # mount the script into the docker image
    mnt_cmd += ' -v $(pwd):/'+DAR_PAYLOAD_MOUNT
    docker_cmd = ('docker run {gpu_opt} {mount_cmds} {extra_flags} -t {img} /bin/bash -c "cd /{dar_payload};./run.sh $*"'.format(
        gpu_opt='--gpus all' if use_nvidia_docker else '',
        img=image_name,
        extra_flags=extra_flags,
        mount_cmds=mnt_cmd,
        dar_payload=DAR_PAYLOAD_MOUNT
    ))
    if verbose:
        builder.echo('Docker command:' + docker_cmd)
    builder.append(docker_cmd)

    with open(docker_hook_file, 'w') as f:
        f.write(builder.dump_script())
    os.chmod(docker_hook_file, 0o777)

def write_singularity_hook(arch_dir, image_name, mounts,
                           script_name,
                           extra_flags='',
                           verbose=False, use_nvidia_docker=False):
    singularity_hook_file = os.path.join(arch_dir, script_name)

# Path: doodad/utils/cmd_builder.py
# class CommandBuilder(object):
#     def __init__(self):
#     def append(self, cmd, *args):
#     def echo(self, msg):
#     def to_string(self, separator=';'):
#     def __str__(self):
#     def __iter__(self):
#     def dump_script(self):


# Path: doodad/darchive/archive_builder_docker.py
import os
import pathlib
import sys
import tempfile
import shutil
import time
import subprocess
import uuid
import contextlib
import uuid
import doodad
from doodad.utils import cmd_builder

    docker_hook_file = os.path.join(arch_dir, script_name)
    builder = cmd_builder.CommandBuilder()
    builder.append('#!/bin/bash')
    #if verbose:
    #    builder.echo('All script arguments:')
    #    builder.echo('$@')
    mnt_cmd = ''.join([' -v %s:%s' % (mnt.sync_dir, mnt.mount_point)
        for mnt in mounts if mnt.writeable])
    # mount the script into the docker image
    mnt_cmd += ' -v $(pwd):/'+DAR_PAYLOAD_MOUNT
    docker_cmd = ('docker run {gpu_opt} {mount_cmds} {extra_flags} -t {img} /bin/bash -c "cd /{dar_payload};./run.sh $*"'.format(
        gpu_opt='--gpus all' if use_nvidia_docker else '',
        img=image_name,
        extra_flags=extra_flags,
        mount_cmds=mnt_cmd,
        dar_payload=DAR_PAYLOAD_MOUNT
    ))
    if verbose:
        builder.echo('Docker command:' + docker_cmd)
    builder.append(docker_cmd)

    with open(docker_hook_file, 'w') as f:
        f.write(builder.dump_script())
    os.chmod(docker_hook_file, 0o777)

def write_singularity_hook(arch_dir, image_name, mounts,
                           script_name,
                           extra_flags='',
                           verbose=False, use_nvidia_docker=False):
    singularity_hook_file = os.path.join(arch_dir, script_name)

    builder = cmd_builder.CommandBuilder()