def stats(args): '''Displays a coarse summary of the jobs state. ''' if not args: job_list = all_jobs() else: job_list = parse_job_list(args) display_stats(job_list)
def list(args): '''Lists the status of the selected targets (or all targets \ if not specified). If only one job is specified, then it is listed in more detail. ''' if not args: job_list = all_jobs() else: job_list = parse_job_list(args) list_jobs(job_list)
def go(path): db = StorageFilesystem(path, compress=True) args = ['failed'] cq = CacheQueryDB(db) context = Context(db) if not list(db.keys()): msg = 'Compmake DB is empty' logger.error(msg) else: job_list = parse_job_list(args, context=context, cq=cq) s = "" if job_list: job_list = job_list[:2] s += 'Running on host: %s' % hostname s += "\nJob failed in path %s" % path for job_id in job_list: if job_cache_exists(job_id, db): cache = get_job_cache(job_id, db) status = Cache.state2desc[cache.state] s += "\nFailure of job %s" % job_id if cache.state in [Cache.FAILED, Cache.BLOCKED]: why = str(cache.exception).strip() else: why = 'No why for job done.' s += '\n' + "```\n" + why + "\n```" s += '\n\n' else: logger.warning('no cache for %s' % job_id) s += '\n@censi' s += '\n@jacopo' s += '\n@paull' s += '\n@walter' s += '\n@daniele' print(s) slack.chat.post_message(channel, s, link_names=1) else: s = 'Everything is fine' # slack.chat.post_message(channel, s) logger.info('No jobs found')
def interpret_commands(commands): if isinstance(commands, str): commands = commands.split() ui_commands = get_commands() command_name = commands[0] # Check if this is an alias if command_name in alias2name: command_name = alias2name[command_name] if not command_name in ui_commands.keys(): raise UserError("Unknown command %r (try 'help'). " % command_name) # XXX: use more elegant method cmd = ui_commands[command_name] function = cmd.function function_args = \ function.func_code.co_varnames[:function.func_code.co_argcount] args = commands[1:] # look for key=value pairs other = [] kwargs = {} argspec = inspect.getargspec(function) if argspec.defaults: num_args_with_default = len(argspec.defaults) else: num_args_with_default = 0 num_args = len(argspec.args) num_args_without_default = num_args - num_args_with_default args_without_default = argspec.args[0:num_args_without_default] for a in args: if a.find('=') > 0: k, v = a.split('=') if not k in argspec.args: msg = ("You passed the argument %r for command %r, but the only " "available arguments are %s." % (k, cmd.name, function_args)) raise UserError(msg) # look if we have a default value index = argspec.args.index(k) if index < num_args_without_default: # no default, pass as string kwargs[k] = v else: default_value = \ argspec.defaults[index - num_args_without_default] try: kwargs[k] = interpret_strings_like(v, default_value) except ValueError: msg = 'Could not parse %s=%s as %s.' % (k, v, type(default_value)) raise UserError(msg) #print "%s : %s (%s)" % (k, kwargs[k], type(kwargs[k])) else: other.append(a) args = other if 'args' in function_args: kwargs['args'] = args if 'non_empty_job_list' in function_args: if not args: msg = ("The command %r requires a non empty list of jobs as " "argument." % command_name) raise UserError(msg) job_list = parse_job_list(args) # TODO: check non empty kwargs['non_empty_job_list'] = job_list if 'job_list' in function_args: kwargs['job_list'] = parse_job_list(args) for x in args_without_default: if not x in kwargs: raise UserError('Required argument %r not given.' % x) return function(**kwargs)