コード例 #1
0
ファイル: __init__.py プロジェクト: poguez/crosscompute
def run_script(
        target_folder, tool_definition, result_arguments, data_type_by_suffix,
        environment=None):
    result_properties, timestamp = OrderedDict(), time.time()
    result_arguments = dict(result_arguments, target_folder=target_folder)
    result_configuration = _ResultConfiguration(target_folder)
    result_configuration.write_header(tool_definition, result_arguments)
    command_terms = split_arguments(render_command(tool_definition[
        'command_template'], result_arguments).replace('\n', ' '))
    try:
        with cd(tool_definition['configuration_folder']):
            command_process = subprocess.Popen(
                command_terms, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                env=environment or SCRIPT_ENVIRONMENT)
    except OSError:
        standard_output, standard_error = None, 'Command not found'
    else:
        standard_output, standard_error = [
            x.rstrip().decode('utf-8') for x in command_process.communicate()]
        if command_process.returncode:
            result_properties['return_code'] = command_process.returncode
    result_properties.update(_process_streams(
        standard_output, standard_error, target_folder, tool_definition,
        data_type_by_suffix))
    result_properties['execution_time_in_seconds'] = time.time() - timestamp
    result_configuration.write_footer(result_properties)
    return result_properties
コード例 #2
0
def run_git(command_args, folder=None, exception_by_error=None):
    if not folder:
        folder = getcwd()
    exception_by_error = dict(
        {
            "Could not read": BadURL,
            "Not a git repository": BadRepository,
            "not found": BadURL,
            "not a tree object": BadCommitHash,
            "Not a valid object name": BadCommitHash,
        },
        **(exception_by_error or {})
    )
    with cd(folder):
        output = run_command(command_args, exception_by_error)
    return str(output)  # Convert bytes to str in Python 3
コード例 #3
0
ファイル: __init__.py プロジェクト: salah93/crosscompute
def run_script(tool_definition,
               result_arguments,
               result_folder,
               target_folder=None,
               environment=None):
    timestamp, environment = time.time(), environment or {}
    if 'target_folder' in tool_definition['argument_names']:
        y = make_folder(abspath(target_folder or join(result_folder, 'y')))
        result_arguments = OrderedDict(result_arguments, target_folder=y)
    # Record
    result_configuration = ResultConfiguration(result_folder)
    result_configuration.save_tool_location(tool_definition)
    result_configuration.save_result_arguments(result_arguments, environment)
    # Run
    command_terms = split_arguments(
        render_command(tool_definition['command_template'],
                       result_arguments).replace('\n', ' '))
    result_properties = OrderedDict()
    try:
        with cd(tool_definition['configuration_folder']):
            command_process = subprocess.Popen(command_terms,
                                               stdout=subprocess.PIPE,
                                               stderr=subprocess.PIPE,
                                               env=merge_dictionaries(
                                                   environment,
                                                   SCRIPT_ENVIRONMENT))
    except OSError:
        standard_output, standard_error = None, 'Command not found'
    else:
        standard_output, standard_error = [
            x.rstrip().decode('utf-8') for x in command_process.communicate()
        ]
        if command_process.returncode:
            result_properties['return_code'] = command_process.returncode
    # Save
    result_properties.update(
        _process_streams(standard_output, standard_error, result_folder,
                         tool_definition))
    result_properties['execution_time_in_seconds'] = time.time() - timestamp
    result_configuration.save_result_properties(result_properties)
    result_configuration.save_result_script(tool_definition, result_arguments)
    if 'target_folder' in tool_definition['argument_names']:
        link_path(join(result_folder, 'y'), result_arguments['target_folder'])
    return result_properties
コード例 #4
0
ファイル: __init__.py プロジェクト: crosscompute/crosscompute
def run_script(
        tool_definition, result_arguments, result_folder, target_folder=None,
        environment=None):
    timestamp, environment = time.time(), environment or {}
    if 'target_folder' in tool_definition['argument_names']:
        y = make_folder(abspath(target_folder or join(result_folder, 'y')))
        result_arguments = OrderedDict(result_arguments, target_folder=y)
    # Record
    result_configuration = ResultConfiguration(result_folder)
    result_configuration.save_tool_location(tool_definition)
    result_configuration.save_result_arguments(result_arguments, environment)
    # Run
    command_terms = split_arguments(render_command(tool_definition[
        'command_template'], result_arguments).replace('\n', ' '))
    result_properties = OrderedDict()
    try:
        with cd(tool_definition['configuration_folder']):
            command_process = subprocess.Popen(
                command_terms, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                env=merge_dictionaries(environment, SCRIPT_ENVIRONMENT))
    except OSError:
        standard_output, standard_error = None, 'Command not found'
    else:
        standard_output, standard_error = [x.rstrip().decode(
            'utf-8') for x in command_process.communicate()]
        if command_process.returncode:
            result_properties['return_code'] = command_process.returncode
    # Save
    result_properties.update(_process_streams(
        standard_output, standard_error, result_folder, tool_definition))
    result_properties['execution_time_in_seconds'] = time.time() - timestamp
    result_configuration.save_result_properties(result_properties)
    result_configuration.save_result_script(tool_definition, result_arguments)
    if 'target_folder' in tool_definition['argument_names']:
        link_path(join(result_folder, 'y'), result_arguments['target_folder'])
    return result_properties