예제 #1
0
	def call_method(self, method, options={}, datasets={}, jobs={}, record_in=None, record_as=None, why_build=False, caption=None, workdir=None, **kw):
		if method not in self._method_info:
			raise Exception('Unknown method %s' % (method,))
		info = self._method_info[method]
		params = dict(options=dict(options), datasets=dict(datasets), jobs=dict(jobs))
		argmap = defaultdict(list)
		for thing in ('options', 'datasets', 'jobs'):
			for n in info[thing]:
				argmap[n].append(thing)
		for k, v in kw.items():
			if k not in argmap:
				raise Exception('Keyword %s not in options/datasets/jobs for method %s' % (k, method,))
			if len(argmap[k]) != 1:
				raise Exception('Keyword %s has several targets on method %s: %r' % (k, method, argmap[k],))
			params[argmap[k][0]][k] = v
		jid, res = self._submit(method, caption=caption, why_build=why_build, workdir=workdir, **params)
		if why_build: # specified by caller
			return res.why_build
		if 'why_build' in res: # done by server anyway (because --flags why_build)
			print("Would have built from:")
			print("======================")
			print(setupfile.encode_setup(self.history[-1][0], as_str=True))
			print("Could have avoided build if:")
			print("============================")
			print(json_encode(res.why_build, as_str=True))
			print()
			from inspect import stack
			stk = stack()[2]
			print("Called from %s line %d" % (stk[1], stk[2],))
			exit()
		jid = Job(jid, record_as or method)
		self.record[record_in].append(jid)
		return jid
예제 #2
0
 def _server_submit(self, json):
     # submit json to server
     postdata = urlencode({'json': setupfile.encode_setup(json)})
     res = self._url_json('submit', data=postdata)
     if 'error' in res:
         raise DaemonError('Submit failed: ' + res.error)
     if 'why_build' not in res:
         if not self.subjob_cookie:
             self._printlist(res.jobs)
         self.validate_response(res.jobs)
     return res
예제 #3
0
def show(url, job, show_output):
    print(job.path)
    print('=' * len(job.path))
    setup = job.json_load('setup.json')
    setup.pop('_typing', None)
    setup.starttime = str(datetime.fromtimestamp(setup.starttime))
    if 'endtime' in setup:
        setup.endtime = str(datetime.fromtimestamp(setup.endtime))
    print(encode_setup(setup, as_str=True))
    try:
        with job.open('datasets.txt') as fh:
            print()
            print('datasets:')
            for line in fh:
                print('    %s/%s' % (
                    job,
                    line[:-1],
                ))
    except IOError:
        pass
    try:
        post = job.json_load('post.json')
    except FileNotFoundError:
        print('\x1b[31mWARNING: Job did not finish\x1b[m')
        post = None
    if post and post.subjobs:
        print()
        print('subjobs:')
        for sj in sorted(post.subjobs):
            print('   ', sj)
    if post and post.files:
        print()
        print('files:')
        for fn in sorted(post.files):
            print('   ', job.filename(fn))
    if post and not call(url + '/job_is_current/' + job):
        print('\x1b[34mJob is not current\x1b[m')
    print()
    out = job.output()
    if show_output:
        if out:
            print('output (use --just-output/-O to see only the output):')
            print(out)
            if not out.endswith('\n'):
                print()
        else:
            print(job, 'produced no output')
            print()
    elif out:
        print('%s produced %d bytes of output, use --output/-o to see it' % (
            job,
            len(out),
        ))
        print()
예제 #4
0
파일: job.py 프로젝트: berkeman/accelerator
def show(url, job, show_output):
    print(job.path)
    print('=' * len(job.path))
    setup = job.json_load('setup.json')
    setup.pop('_typing', None)
    setup.starttime = str(datetime.fromtimestamp(setup.starttime))
    if 'endtime' in setup:
        setup.endtime = str(datetime.fromtimestamp(setup.endtime))
    print(encode_setup(setup, as_str=True))
    if job.datasets:
        print()
        print('datasets:')
        for ds in job.datasets:
            print('   ', ds.quoted)
    try:
        post = job.json_load('post.json')
    except FileNotFoundError:
        print(colour('WARNING: Job did not finish', 'job/warning'))
        post = None
    if post and post.subjobs:
        print()
        print('subjobs:')
        for sj in sorted(post.subjobs):
            print('   ', sj)
    if post and post.files:
        print()
        print('files:')
        for fn in sorted(post.files):
            print('   ', job.filename(fn))
    if post and not call(url + '/job_is_current/' + url_quote(job)):
        print(colour('Job is not current', 'job/info'))
    print()
    out = job.output()
    if show_output:
        if out:
            print('output (use --just-output/-O to see only the output):')
            print(out)
            if not out.endswith('\n'):
                print()
        else:
            print(job, 'produced no output')
            print()
    elif out:
        print('%s produced %d bytes of output, use --output/-o to see it' % (
            job,
            len(out),
        ))
        print()
예제 #5
0
 def call_method(self,
                 method,
                 options={},
                 datasets={},
                 jobids={},
                 record_in=None,
                 record_as=None,
                 why_build=False,
                 caption=None,
                 workdir=None):
     jid, res = self._submit(method,
                             options,
                             datasets,
                             jobids,
                             caption,
                             why_build=why_build,
                             workdir=workdir)
     if why_build:  # specified by caller
         return res.why_build
     if 'why_build' in res:  # done by server anyway (because --flags why_build)
         print("Would have built from:")
         print("======================")
         print(setupfile.encode_setup(self.history[-1][0], as_str=True))
         print("Could have avoided build if:")
         print("============================")
         print(json_encode(res.why_build, as_str=True))
         print()
         from inspect import stack
         stk = stack()[2]
         print("Called from %s line %d" % (
             stk[1],
             stk[2],
         ))
         exit()
     jid = Job(jid, record_as or method)
     self.record[record_in].append(jid)
     return jid