Esempio n. 1
0
def generate_activate_file(print_env,
                           deploy_dir,
                           append_to_bashrc=False,
                           append_to_bashprofile=False):
    log.info('Generating activate.sh file')

    lines = []
    for env_name in print_env:
        old_var = print_env[env_name]
        if (env_name.upper() == 'PATH') or \
           (env_name.upper() == 'PYTHONPATH'):
            new_var = old_var + ':$%s' % env_name.upper()
        else:
            new_var = old_var
        var_string = 'export %s=%s' % (env_name, new_var)
        var_string += '\n'
        lines.append(var_string)

    output_file = os.path.join(deploy_dir, 'activate.sh')

    old_contents = []
    if os.path.exists(output_file):
        oldFile = open(output_file, 'r')
        old_contents = oldFile.readlines()
        oldFile.close()

    if lines != old_contents:
        util.backup_file(output_file)
        if os.path.exists(output_file):
            os.remove(output_file)

        util.write_new_file(output_file, lines)

    appendStr = 'echo "source %s" >> ~/.bashrc' % output_file
    appendFile = '~/.bashrc'
    compStr = 'source %s\n' % output_file
    if (append_to_bashrc) and (not util.line_in_file(compStr, appendFile)):
        log.debug('Appending environment settings to ~/.bashrc')
        (appendStatus, appendOut) = commands.getstatusoutput(appendStr)
        if appendStatus != 0:
            log.error('Error appending to ~/.bashrc')
            log.error('Output:')
            log.error(appendOut)
        else:
            log.info('Successfully appended to ~/.bashrc')

    appendStr = 'echo "source %s" >> ~/.bash_profile' % output_file
    appendFile = '~/.bash_profile'
    compStr = 'source %s\n' % output_file
    if (append_to_bashprofile) and (not util.line_in_file(compStr,
                                                          appendFile)):
        log.debug('Appending environment settings to ~/.bash_profile')
        (appendStatus, appendOut) = commands.getstatusoutput(appendStr)
        if appendStatus != 0:
            log.error('Error appending to ~/.bash_profile')
            log.error('Output:')
            log.error(appendOut)
        else:
            log.info('Successfully appended to ~/.bash_profile')
Esempio n. 2
0
def generate_activate_file(print_env, 
                           deploy_dir, 
                           append_to_bashrc=False,
                           append_to_bashprofile=False):
    log.info('Generating activate.sh file')

    lines = []
    for env_name in print_env:
        old_var = print_env[env_name]
        if (env_name.upper() == 'PATH') or \
           (env_name.upper() == 'PYTHONPATH'):
            new_var = old_var + ':$%s' % env_name.upper()
        else:
            new_var = old_var
        var_string = 'export %s=%s' % (env_name, new_var)
        var_string += '\n'
        lines.append(var_string)

    output_file = os.path.join(deploy_dir, 'activate.sh')

    old_contents = []
    if os.path.exists(output_file):
        oldFile = open(output_file, 'r')
        old_contents = oldFile.readlines()
        oldFile.close()

    if lines != old_contents:
        util.backup_file(output_file)
        if os.path.exists(output_file):
            os.remove(output_file)

        util.write_new_file(output_file, lines)

    appendStr = 'echo "source %s" >> ~/.bashrc' % output_file
    appendFile = '~/.bashrc'
    compStr = 'source %s\n' % output_file
    if (append_to_bashrc) and (not util.line_in_file(compStr, appendFile)):
        log.debug('Appending environment settings to ~/.bashrc')
        (appendStatus, appendOut) = commands.getstatusoutput(appendStr)
        if appendStatus != 0:
            log.error('Error appending to ~/.bashrc')
            log.error('Output:')
            log.error(appendOut)
        else:
            log.info('Successfully appended to ~/.bashrc')

    appendStr = 'echo "source %s" >> ~/.bash_profile' % output_file
    appendFile = '~/.bash_profile'
    compStr = 'source %s\n' % output_file
    if (append_to_bashprofile) and (not util.line_in_file(compStr, appendFile)):
        log.debug('Appending environment settings to ~/.bash_profile')
        (appendStatus, appendOut) = commands.getstatusoutput(appendStr)
        if appendStatus != 0:
            log.error('Error appending to ~/.bash_profile')
            log.error('Output:')
            log.error(appendOut)
        else:
            log.info('Successfully appended to ~/.bash_profile')
Esempio n. 3
0
def _generate_qiime_config(python_path, deploy_dir, all_apps_to_deploy, log,
                           qiime_config_path):
    qiime_path = None
    blast_path = None
    blast_data_path = None
    deploy_dir_contents = os.listdir(deploy_dir)
    for app in all_apps_to_deploy:
        if app.name == 'qiime':
            qiime_path = os.path.join(app.deploy_dir, 'bin')
        if app.name == 'blast':
            blast_path = os.path.join(app.deploy_dir, 'bin/blastall')
            blast_data_path = os.path.join(app.deploy_dir, 'data')

    log.info('Generating new %s file' % qiime_config_path)

    lines = []
    lines.append('# autogenerated by qiime-deploy\n')

    if qiime_path:
        # If we have a [qiime] target, write out additional QIIME config lines
        # for qiime_scripts_dir, etc.. These values have since been removed (or
        # replaced by defaults) in QIIME, but we'll continue to write them here
        # to maintain backwards compatibility with older qiime-deploy conf
        # files that still deploy QIIME instead of assuming that QIIME's python
        # code is already installed (e.g., via pip).
        line = 'qiime_scripts_dir\t%s\n' % qiime_path
        lines.append(line)

        line = 'python_exe_fp\t%s\n' % python_path
        lines.append(line)

        lines.append('working_dir\t/tmp/\n')
        lines.append('temp_dir\t/tmp/\n')

        # for n3phele
        lines.append('cloud_environment\tFalse\n')

        path = deploy_dir + '/lanemask_in_1s_and_0s'
        line = 'template_alignment_lanemask_fp\t%s\n' % path
        lines.append(line)

        path = deploy_dir + '/core_set_aligned.fasta.imputed'
        line = 'pynast_template_alignment_fp\t%s\n' % path
        lines.append(line)

        # lines for Greengenes files
        path = deploy_dir + '/gg_otus-13_8-release/rep_set/97_otus.fasta'
        line = 'assign_taxonomy_reference_seqs_fp\t%s\n' % path
        lines.append(line)

        path = deploy_dir + '/gg_otus-13_8-release/taxonomy/97_otu_taxonomy.txt'
        line = 'assign_taxonomy_id_to_taxonomy_fp\t%s\n' % path
        lines.append(line)

        parallel_jobs_path = os.path.join(qiime_path, 'start_parallel_jobs.py')
        lines.append('cluster_jobs_fp\t%s\n' % parallel_jobs_path)

    # The following QIIME config values are set regardless of whether we're
    # deploying the latest QIIME or previous versions.
    if blast_path:
        line = 'blastall_fp\t%s\n' % blast_path
        lines.append(line)

    if blast_data_path:
        line = 'blastmat_dir\t%s\n' % blast_data_path
        lines.append(line)

    lines.append('')
    lines.append('')

    old_contents = []
    if os.path.exists(qiime_config_path):
        oldFile = open(qiime_config_path, 'r')
        old_contents = oldFile.readlines()
        oldFile.close()

    if lines != old_contents:
        util.backup_file(qiime_config_path)
        if os.path.exists(qiime_config_path):
            os.remove(qiime_config_path)

        util.write_new_file(qiime_config_path, lines)

        log.info('Generated new %s file' % qiime_config_path)

    return 0
Esempio n. 4
0
def _generate_qiime_config(python_path, deploy_dir, all_apps_to_deploy, log):
    qiime_path = None
    blast_path = None
    blast_data_path = None
    deploy_dir_contents = os.listdir(deploy_dir)
    for app in all_apps_to_deploy:
        if app.name == 'qiime':
            qiime_path = os.path.join(app.deploy_dir, 'bin')
        if app.name == 'blast':
            blast_path = os.path.join(app.deploy_dir, 'bin/blastall')
            blast_data_path = os.path.join(app.deploy_dir, 'data')

    if not qiime_path:
        # No qiime target so skip.
        return 0

    qiime_config_path = os.path.join(deploy_dir, 'qiime_config')
    log.info('Generating new %s file' % qiime_config_path)

    if not (blast_path and blast_data_path):
        log.error('Missing necessary paths for %s file.' % qiime_config_path)
        log.error('Skipping generation of %s' % qiime_config_path)
        return 1

    lines = []
    lines.append('# autogenerated by qiime-deploy\n')

    parallel_jobs_path = os.path.join(qiime_path, 'start_parallel_jobs.py')
    lines.append('cluster_jobs_fp\t%s\n' % parallel_jobs_path)
    
    line = 'python_exe_fp\t%s\n' % python_path
    lines.append(line)

    line = 'qiime_scripts_dir\t%s\n' % qiime_path
    lines.append(line)

    line = 'blastmat_dir\t%s\n' % blast_data_path
    lines.append(line)
    line = 'blastall_fp\t%s\n' % blast_path
    lines.append(line)

    path = deploy_dir + '/lanemask_in_1s_and_0s'
    line = 'template_alignment_lanemask_fp\t%s\n' % path
    lines.append(line)

    path = deploy_dir + '/core_set_aligned.fasta.imputed'
    line = 'pynast_template_alignment_fp\t%s\n' % path
    lines.append(line)

    #line = 'pyronoise_data_fp\t%s' % denoiser_path
    #lines.append(line)

    lines.append('pynast_template_alignment_blastdb\t\n')

    lines.append('working_dir\t/tmp/\n')
    lines.append('jobs_to_start\t1\n')
    lines.append('seconds_to_sleep\t60\n')
    lines.append('temp_dir\t/tmp/\n')
    
    # lines for n3phele
    lines.append('cloud_environment\tFalse\n')
    
    #lines for Greengenes files
    path = deploy_dir + '/gg_otus-12_10-release/rep_set/97_otus.fasta'
    line = 'assign_taxonomy_reference_seqs_fp\t%s\n' % path
    lines.append(line)
    path = deploy_dir + '/gg_otus-12_10-release/taxonomy/97_otu_taxonomy.txt'
    line = 'assign_taxonomy_id_to_taxonomy_fp\t%s\n' % path
    lines.append(line)
    
    lines.append('')
    lines.append('')

    old_contents = []
    if os.path.exists(qiime_config_path):
        oldFile = open(qiime_config_path, 'r')
        old_contents = oldFile.readlines()
        oldFile.close()

    if lines != old_contents:
        util.backup_file(qiime_config_path)
        if os.path.exists(qiime_config_path):
            os.remove(qiime_config_path)

        util.write_new_file(qiime_config_path, lines)

        log.info('Generated new %s file' % qiime_config_path)

    return 0