Esempio n. 1
0
 def save_result_properties(self, result_properties):
     d = {'result_properties': result_properties}
     if not self.quiet:
         print(format_settings(d))
     d = filter_nested_dictionary(d, lambda x: x.startswith('_'))
     d = make_relative_paths(d, self.result_folder)
     return save_settings(join(self.result_folder, 'y.cfg'), d)
Esempio n. 2
0
 def save_result_properties(self, result_properties):
     d = {
         'result_properties': result_properties,
     }
     print(format_settings(filter_nested_dictionary(d, lambda x: x in [
         'standard_output', 'standard_error'])))
     d = filter_nested_dictionary(d, lambda x: x.startswith('_'))
     d = make_relative_paths(d, self.result_folder)
     return save_settings(join(self.result_folder, 'y.cfg'), d)
Esempio n. 3
0
 def save_result_arguments(self, result_arguments, environment):
     d = {
         'result_arguments': result_arguments,
     }
     if environment:
         d['result_environment'] = environment
     print(format_settings(d))
     print('')
     d = filter_nested_dictionary(
         d, lambda x: x.startswith('_') or x in ['target_folder'])
     d = make_relative_paths(d, self.result_folder)
     return save_settings(join(self.result_folder, 'x.cfg'), d)
def test_make_relative_path():
    assert make_relative_paths({
        'empty_path': '',
        'a_path': 'x',
        'b_path': '/var/x',
        'c_path': '/tmp/x',
    }, '/tmp') == {
        'empty_path': '',
        'a_path': 'x',
        'b_path': '',
        'c_path': 'x',
    }
def test_make_relative_path():
    assert make_relative_paths(
        {
            'empty_path': '',
            'a_path': 'x',
            'b_path': '/var/x',
            'c_path': '/tmp/x',
        }, '/tmp') == {
            'empty_path': '',
            'a_path': 'x',
            'b_path': '',
            'c_path': 'x',
        }
Esempio n. 6
0
 def save_result_arguments(self, result_arguments, environment):
     d = {
         'result_arguments':
         OrderedDict((k, get_data_type(k).render(v))
                     for k, v in result_arguments.items())
     }
     if environment:
         d['result_environment'] = environment
     if not self.quiet:
         print(format_settings(d))
         print('')
     d = filter_nested_dictionary(
         d, lambda x: x.startswith('_') or x in RESERVED_ARGUMENT_NAMES)
     d = make_relative_paths(d, self.result_folder)
     return save_settings(join(self.result_folder, 'x.cfg'), d)
Esempio n. 7
0
def prepare_script_folder(script_folder,
                          notebook_path,
                          tool_name,
                          with_debugging=False):
    notebook = load_notebook(notebook_path)
    notebook_folder = dirname(abspath(notebook_path))
    copy_folder(script_folder, notebook_folder)
    # Prepare arguments
    tool_arguments = load_tool_arguments(notebook)
    for k in RESERVED_ARGUMENT_NAMES:
        tool_arguments[k] = ''
    tool_arguments = make_absolute_paths(tool_arguments, script_folder)
    for k, v in tool_arguments.items():
        if k.endswith('_path') and not exists(v):
            raise CrossComputeError(
                {k: 'file not found (%s)' % relpath(v, script_folder)})
    kw = {'with_debugging': with_debugging}
    # Save script
    script_content = prepare_script(tool_arguments, notebook)
    script_name = 'run.py'
    copy_text(join(script_folder, script_name), script_content)
    # Save tool template
    cell = notebook['cells'][0]
    if cell['cell_type'] == u'markdown':
        template_name = 'tool.md'
        copy_text(join(script_folder, template_name), cell['source'])
        kw['tool_template_path'] = template_name
    # Save result template
    cell = notebook['cells'][-1]
    if cell['cell_type'] == u'markdown':
        template_name = 'result.md'
        copy_text(join(script_folder, template_name), cell['source'])
        kw['result_template_path'] = template_name
    # Save configuration
    command_name = notebook['metadata']['kernelspec']['name']
    configuration_content = prepare_configuration(
        tool_name, command_name, script_name,
        make_relative_paths(tool_arguments, script_folder), **kw)
    configuration_name = 'cc.ini'
    copy_text(join(script_folder, configuration_name), configuration_content)