Пример #1
0
 def colour_item(item):
     pos = 0
     parts = []
     for m in pat_s.finditer(item):
         a, b = m.span()
         parts.extend((item[pos:a], colour.red(item[a:b])))
         pos = b
     parts.append(item[pos:])
     return ''.join(parts)
Пример #2
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))
	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.red('WARNING: Job did not finish'))
		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.blue('Job is not current'))
	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()
Пример #3
0
	def log(self, action, data):
		if self._initialised:
			if action == 'truncate':
				user, build = data.key.split('/')
			else:
				user, build = data.user, data.build
			assert '/' not in user
			assert '/' not in build
			path = os.path.join(self.path, user)
			if not os.path.isdir(path):
				os.makedirs(path)
			fn = os.path.join(path, build + '.urd')
			with open(fn, 'a') as fh:
				start_pos = fh.tell()
				try:
					fh.write(self._serialise(action, data) + '\n')
					fh.flush()
				except IOError as e:
					try:
						try:
							# Try to avoid leaving a partial line in the file.
							fh.truncate(start_pos)
							fh.close()
							extra = ''
						except:
							extra = "  Also failed to remove partially written data."
							stars = colour.red('****')
							extra2 = "  " + stars + " YOUR URD DB IS PROBABLY BROKEN NOW! " + stars
						msg = "  Failed to write %s: %s" % (fn, e)
						brk = "#" * (max(len(msg), len(extra)) + 2)
						print("", file=sys.stderr)
						print(brk, file=sys.stderr)
						print(msg, file=sys.stderr)
						if extra:
							print(extra, file=sys.stderr)
							print(extra2, file=sys.stderr)
						print(brk, file=sys.stderr)
						print("", file=sys.stderr)
					finally:
						# This is a fatal error.
						os.killpg(os.getpgid(0), signal.SIGTERM)
Пример #4
0
 def try_print(data=b'\n' + colour.red(b'*** Some output not printed ***') +
               b'\n'):
     try:
         os.write(out_fd, data)
     except OSError:
         missed[0] = True