Esempio n. 1
0
 def test_with_stdin_stdout(self):
     with open("data.in", "w") as fp:
         fp.write("1 2 3\n")
     commands.run(["--stdin=data.in", "--stdout=data.out"])
     self.assertEqual(self.prj.launch_args["script_args"],
                      "< data.in > data.out")
     os.remove("data.in")
Esempio n. 2
0
 def test_with_stdin_stdout(self):
     with open("data.in", "w") as fp:
         fp.write("1 2 3\n")
     commands.run(["--stdin=data.in", "--stdout=data.out"])
     self.assertEqual(self.prj.launch_args["script_args"],
                      "< data.in > data.out")
     os.remove("data.in")
Esempio n. 3
0
 def test_with_single_input_file(self):
     data_content = b"0.0 242\n0.1 2345\n0.2 42451\n"
     with open("this.is.not.a.parameter.file", "wb") as f:
         f.write(data_content)
     commands.run(
         ["this.is.not.a.parameter.file"]
     )  # file exists but is not a parameter file so is treated as input data
     self.assertEqual(
         self.prj.launch_args,
         {
             "executable": "default",
             "parameters": {},
             "main_file": "default",
             "label": None,
             "input_data": [
                 datastore.DataKey(
                     "this.is.not.a.parameter.file", hashlib.sha1(data_content).hexdigest(), back_to_the_future
                 )
             ],
             "reason": "",
             "version": "current",
             "script_args": "this.is.not.a.parameter.file",
         },
     )
     os.remove("this.is.not.a.parameter.file")
Esempio n. 4
0
 def test_with_single_input_file(self):
     data_content = b"0.0 242\n0.1 2345\n0.2 42451\n"
     with open("this.is.not.a.parameter.file", 'wb') as f:
         f.write(data_content)
     commands.run(
         ["this.is.not.a.parameter.file"]
     )  # file exists but is not a parameter file so is treated as input data
     self.assertEqual(
         self.prj.launch_args, {
             'executable':
             'default',
             'parameters': {},
             'main_file':
             'default',
             'label':
             None,
             'input_data': [
                 datastore.DataKey('this.is.not.a.parameter.file',
                                   hashlib.sha1(data_content).hexdigest(),
                                   back_to_the_future)
             ],
             'reason':
             '',
             'version':
             'current',
             'script_args':
             'this.is.not.a.parameter.file'
         })
     os.remove("this.is.not.a.parameter.file")
Esempio n. 5
0
def run(request):
    """Running a default simulation with Sumatra.

    This will call ``smt run lo=3``.
    """
    print("Running a simulation. Now.")
    commands.run(["lo=3"])
    return HttpResponse('OK')
Esempio n. 6
0
 def test_with_single_script_arg(self):
     commands.run(["some_parameter_file"])  # file doesn't exist so is treated as argument
     self.assertEqual(self.prj.launch_args,
                      {'executable': 'default',
                      'parameters': {},
                      'main_file': 'default',
                      'label': None,
                      'input_data': [],
                      'reason': '',
                      'version': 'current',
                      'script_args': 'some_parameter_file'})
Esempio n. 7
0
 def test_with_single_script_arg(self):
     commands.run(["some_parameter_file"])  # file doesn't exist so is treated as argument
     self.assertEqual(self.prj.launch_args,
                      {'executable': 'default',
                      'parameters': {},
                      'main_file': 'default',
                      'label': None,
                      'input_data': [],
                      'reason': '',
                      'version': 'current',
                      'script_args': 'some_parameter_file'})
Esempio n. 8
0
 def test_with_no_args(self):
     commands.run([])
     expected = {'executable': 'default',
                 'parameters': {},
                 'main_file': 'default',
                 'label': None,
                 'input_data': [],
                 'reason': '',
                 'version': 'current',
                 'script_args': ''}
     self.assertEqual(self.prj.launch_args, expected)
Esempio n. 9
0
 def test_with_no_args(self):
     commands.run([])
     expected = {'executable': 'default',
                 'parameters': {},
                 'main_file': 'default',
                 'label': None,
                 'input_data': [],
                 'reason': '',
                 'version': 'current',
                 'script_args': ''}
     self.assertEqual(self.prj.launch_args, expected)
Esempio n. 10
0
 def test_with_no_args(self):
     commands.run([])
     expected = {
         "executable": "default",
         "parameters": {},
         "main_file": "default",
         "label": None,
         "input_data": [],
         "reason": "",
         "version": "current",
         "script_args": "",
     }
     self.assertEqual(self.prj.launch_args, expected)
Esempio n. 11
0
 def test_with_single_input_file(self):
     data_content = b"0.0 242\n0.1 2345\n0.2 42451\n"
     with open("this.is.not.a.parameter.file", 'wb') as f:
         f.write(data_content)
     commands.run(["this.is.not.a.parameter.file"])  # file exists but is not a parameter file so is treated as input data
     self.assertEqual(self.prj.launch_args,
                      {'executable': 'default',
                      'parameters': {},
                      'main_file': 'default',
                      'label': None,
                      'input_data': [datastore.DataKey('this.is.not.a.parameter.file', hashlib.sha1(data_content).hexdigest(), back_to_the_future)],
                      'reason': '',
                      'version': 'current',
                      'script_args': 'this.is.not.a.parameter.file'})
     os.remove("this.is.not.a.parameter.file")
Esempio n. 12
0
 def test_with_single_script_arg(self):
     commands.run(["some_parameter_file"])  # file doesn't exist so is treated as argument
     self.assertEqual(
         self.prj.launch_args,
         {
             "executable": "default",
             "parameters": {},
             "main_file": "default",
             "label": None,
             "input_data": [],
             "reason": "",
             "version": "current",
             "script_args": "some_parameter_file",
         },
     )
Esempio n. 13
0
 def test_with_everything(self):
     with open("test.param", "w") as f:
         f.write("a = 2\nb = 3\n")
     data_content = b"23496857243968b24cbc4275dc82470a\n"
     with open("this.is.not.a.parameter.file", "wb") as f:
         f.write(data_content)
     commands.run(
         [
             "-l",
             "vikings",
             "-v",
             "234",
             "--reason='test'",
             "-e",
             "python",
             "--main=main.py",
             "spam",
             "test.param",
             "eggs",
             "this.is.not.a.parameter.file",
             "a=17",
             "umlue=43",
             "beans",
         ]
     )
     self.assertEqual(
         self.prj.launch_args,
         {
             "executable": MockExecutable("python"),
             "parameters": {"this": "mock", "a": 17, "umlue": 43},
             "main_file": "main.py",
             "label": "vikings",
             "input_data": [
                 datastore.DataKey(
                     "this.is.not.a.parameter.file", hashlib.sha1(data_content).hexdigest(), back_to_the_future
                 )
             ],
             "reason": "test",
             "version": "234",
             "script_args": "spam <parameters> eggs this.is.not.a.parameter.file beans",
         },
     )
     os.remove("this.is.not.a.parameter.file")
     os.remove("test.param")
Esempio n. 14
0
def run_sim(request, project):
    if request.POST.has_key('content'):  # save the edited argument file
        content = request.POST.get(
            'content', False)  # in case user changed the argument file
        arg_file = request.POST.get('arg_file', False)
        if os.name == 'posix':
            fow = open(os.getcwd() + '/' + arg_file, 'w')
        else:
            fow = open(os.getcwd() + '\\' + arg_file, 'w')
        fow.write(content)
        fow.close()
        return HttpResponse('ok')
    else:  # run computation
        run_opt = {
            '--label': request.POST.get('label', False),
            '--reason': request.POST.get('reason', False),
            '--tag': request.POST.get('tag', False),
            'exec': request.POST.get('execut', False),
            '--main': request.POST.get('main_file', False),
            'args': request.POST.get('args', False)
        }
        options_list = []
        for key, item in run_opt.iteritems():
            if item:
                if key == 'args':
                    options_list.append(item)
                elif key == 'exec':
                    executable = str(os.path.basename(item))
                    if '.exe' in executable:
                        executable = executable.split('.')[0]
                    options_list.append('='.join(['--executable', executable]))
                else:
                    options_list.append('='.join([key, item]))
        run(options_list)
        ajaxTempOb = AjaxTemplate(project)
        ajaxTempOb.init_object_list(1)  # taking into consideration pagination
        if len(Record.objects.filter(project__id=project)) == 1:
            return HttpResponse('OK')
        else:
            return render_to_response('content.html', ajaxTempOb.getDict())
Esempio n. 15
0
 def test_with_everything(self):
     f = open("test.param", 'w')
     f.write("a = 2\nb = 3\n")
     f.close()
     data_content = b"23496857243968b24cbc4275dc82470a\n"
     f = open("this.is.not.a.parameter.file", 'wb')
     f.write(data_content)
     f.close()
     commands.run([
         "-l", "vikings", "-v", "234", "--reason='test'", "-e", "python",
         "--main=main.py", "spam", "test.param", "eggs",
         "this.is.not.a.parameter.file", "a=17", "umlue=43", "beans"
     ])
     self.assertEqual(
         self.prj.launch_args, {
             'executable':
             MockExecutable('python'),
             'parameters': {
                 'this': 'mock',
                 'a': 17,
                 'umlue': 43
             },
             'main_file':
             'main.py',
             'label':
             'vikings',
             'input_data': [
                 datastore.DataKey('this.is.not.a.parameter.file',
                                   hashlib.sha1(data_content).hexdigest())
             ],
             'reason':
             'test',
             'version':
             '234',
             'script_args':
             "spam <parameters> eggs this.is.not.a.parameter.file beans"
         })
     os.remove("this.is.not.a.parameter.file")
     os.remove("test.param")
Esempio n. 16
0
 def test_with_everything(self):
     with open("test.param", 'w') as f:
         f.write("a = 2\nb = 3\n")
     data_content = b"23496857243968b24cbc4275dc82470a\n"
     with open("this.is.not.a.parameter.file", 'wb') as f:
         f.write(data_content)
     commands.run(["-l", "vikings", "-v", "234", "--reason='test'",
                   "-e", "python", "--main=main.py", "spam", "test.param",
                   "eggs", "this.is.not.a.parameter.file", "a=17",
                   "umlue=43", "beans"])
     self.assertEqual(self.prj.launch_args,
                      {'executable': MockExecutable('python'),
                      'parameters': {'this': 'mock', 'a': 17, 'umlue': 43},
                      'main_file': 'main.py',
                      'label': 'vikings',
                      'input_data': [datastore.DataKey('this.is.not.a.parameter.file',
                                                       hashlib.sha1(data_content).hexdigest(),
                                                       back_to_the_future)],
                      'reason': 'test',
                      'version': '234',
                      'script_args': "spam <parameters> eggs this.is.not.a.parameter.file beans"})
     os.remove("this.is.not.a.parameter.file")
     os.remove("test.param")
Esempio n. 17
0
def run_sim(request, project):
    if request.POST.has_key('content'):  # save the edited argument file
        content = request.POST.get('content', False)  # in case user changed the argument file
        arg_file = request.POST.get('arg_file', False)
        if os.name == 'posix':
            fow = open(os.getcwd() + '/' + arg_file, 'w')
        else:
            fow = open(os.getcwd() + '\\' + arg_file, 'w')
        fow.write(content)
        fow.close()
        return HttpResponse('ok')
    else:  # run computation
        run_opt = {'--label': request.POST.get('label', False),
                   '--reason': request.POST.get('reason', False),
                   '--tag': request.POST.get('tag', False),
                   'exec': request.POST.get('execut', False),
                   '--main': request.POST.get('main_file', False),
                   'args': request.POST.get('args', False)}
        options_list = []
        for key, item in run_opt.iteritems():
            if item:
                if key == 'args':
                    options_list.append(item)
                elif key == 'exec':
                    executable = str(os.path.basename(item))
                    if '.exe' in executable:
                        executable = executable.split('.')[0]
                    options_list.append('='.join(['--executable', executable]))
                else:
                    options_list.append('='.join([key, item]))
        run(options_list)
        ajaxTempOb = AjaxTemplate(project)
        ajaxTempOb.init_object_list(1)  # taking into consideration pagination
        if len(Record.objects.filter(project__id=project)) == 1:
            return HttpResponse('OK')
        else:
            return render_to_response('content.html', ajaxTempOb.getDict())
Esempio n. 18
0
 def test_with_command_line_params_disallowed(self):
     self.prj.allow_command_line_parameters = False
     commands.run(["a=17", "umlue=43", "beans"])
     self.assertEqual(self.prj.launch_args["script_args"],
                      "a=17 umlue=43 beans")
     self.prj.allow_command_line_parameters = True
Esempio n. 19
0
def run_sim(request, project):
    run_opt = {
        '--label': request.POST.get('label', False),
        '--reason': request.POST.get('reason', False),
        '--tag': request.POST.get('tag', False),
        'exec': request.POST.get('execut', False),
        '--main': request.POST.get('main_file', False),
        'args': request.POST.get('args', False)
    }
    content = request.POST.get('content',
                               False)  # in case user changed the argument file
    arg_file = request.POST.get('arg_file', False)
    if content:
        fow = open(os.getcwd() + '/' + arg_file, 'w')
        fow.write(content)
        fow.close()
        return HttpResponse('ok')
    options_list = []
    for key, item in run_opt.iteritems():
        if item:
            if key == 'args':
                options_list.append(item)
            elif key == 'exec':
                executable = str(os.path.basename(item))
                if '.exe' in executable:
                    executable = executable.split('.')[0]
                options_list.append('='.join(['--executable', executable]))
            else:
                options_list.append('='.join([key, item]))
    run(options_list)
    records = models.Record.objects.order_by('-db_id')
    '''
    if not(len(record.launch_mode.get_parameters())):
        nbproc = 1
    repo_short = short_repo(record.repository.url)
    version_short = short_version(record.version)
    timestamp = record.timestamp
    date = timestamp.strftime("%d/%m/%Y")
    time = timestamp.strftime("%H:%M:%S")
    to_sumatra = {'Label-t':record.label,
                  'Tag-t':record.tags,
                  'Reason-t':record.reason,
                  'Outcome-t':record.outcome,
                  'Duration-t':filters.human_readable_duration(record.duration),
                  'Processes-t':nbproc,
                  'Name-t':record.executable.name,
                  'Version-t':record.executable.version,
                  'Repository-t':repo_short,
                  'Main_file-t':record.main_file,
                  'S-Version-t':version_short,
                  'Arguments-t':record.script_arguments,
                  'Date-t':date,
                  'Time-t':time}
    return HttpResponse(simplejson.dumps(to_sumatra))
    '''
    paginator = Paginator(
        records, int(load_project().web_settings['nb_records_per_page']))
    page_list = paginator.page(1)
    dic = {
        'project_name': project,
        'settings': load_project().web_settings,
        'paginator': paginator,
        'object_list': page_list.object_list,
        'page_list': page_list
    }
    return render_to_response('content.html', dic)
Esempio n. 20
0
 def test_with_command_line_params_disallowed(self):
     self.prj.allow_command_line_parameters = False
     commands.run(["a=17", "umlue=43", "beans"])
     self.assertEqual(self.prj.launch_args["script_args"],
                      "a=17 umlue=43 beans")
     self.prj.allow_command_line_parameters = True
Esempio n. 21
0
def run_sim(request, project):   
    run_opt = {'--label': request.POST.get('label', False),
               '--reason': request.POST.get('reason', False),
               '--tag': request.POST.get('tag', False),
               'exec': request.POST.get('execut', False),
               '--main': request.POST.get('main_file', False),
               'args': request.POST.get('args', False)
              }
    content = request.POST.get('content', False) # in case user changed the argument file
    arg_file = request.POST.get('arg_file', False)
    if content:
        fow = open(os.getcwd() + '/' + arg_file, 'w')
        fow.write(content)
        fow.close()
        return HttpResponse('ok')
    options_list = []
    for key, item in run_opt.iteritems():
        if item:
            if key == 'args':
                options_list.append(item)
            elif key == 'exec':
                executable = str(os.path.basename(item))
                if '.exe' in executable:
                    executable = executable.split('.')[0]
                options_list.append('='.join(['--executable', executable]))
            else:
                options_list.append('='.join([key, item])) 
    run(options_list)
    records = models.Record.objects.order_by('-db_id')
    '''
    if not(len(record.launch_mode.get_parameters())):
        nbproc = 1
    repo_short = short_repo(record.repository.url)
    version_short = short_version(record.version)
    timestamp = record.timestamp
    date = timestamp.strftime("%d/%m/%Y")
    time = timestamp.strftime("%H:%M:%S")
    to_sumatra = {'Label-t':record.label,
                  'Tag-t':record.tags,
                  'Reason-t':record.reason,
                  'Outcome-t':record.outcome,
                  'Duration-t':filters.human_readable_duration(record.duration),
                  'Processes-t':nbproc,
                  'Name-t':record.executable.name,
                  'Version-t':record.executable.version,
                  'Repository-t':repo_short,
                  'Main_file-t':record.main_file,
                  'S-Version-t':version_short,
                  'Arguments-t':record.script_arguments,
                  'Date-t':date,
                  'Time-t':time}
    return HttpResponse(simplejson.dumps(to_sumatra))
    '''
    paginator = Paginator(records, int(load_project().web_settings['nb_records_per_page']))
    page_list = paginator.page(1)
    dic = {'project_name': project,
           'settings':load_project().web_settings,
           'paginator':paginator,
           'object_list':page_list.object_list,
           'page_list':page_list}
    return render_to_response('content.html', dic)