#! /usr/bin/env python import sys, re if len(sys.argv)<2: sys.stderr.write('''Synopsis: Instructs Rocoto to rerun some tests or builds. Format: Rewind all tasks: rtrewind -a Rewind some tasks: rtrewind taskname [ taskname [... ] ] Where "taskname" is the build or test name, minus the "build_" or "test_" part. Examples: Recompile gsm.x and nmm.x: rtrewind gsm.x nmm.x Recompile and rerun everything: rtrewind -a Warning: rtrewind has no knowledge of dependencies. Without -a, you need to make sure you rewind any tasks that are dependent on any tasks you wish to rerun. ''') exit(1) if sys.argv[1] == '-a': joblist=None else: joblist=sys.argv[1:] jobfound=[False]*len(joblist) command="rocotorewind -w workflow.xml -d workflow.db" sent_cycle=False def process_line(line,m): match=False if joblist is not None: for ijob in xrange(len(joblist)): job=joblist[ijob] task=m.group(2) if task=="test_"+job: match="test_"+job if task=="build_"+job: match="build_"+job if task==job: match=job if match: jobfound[ijob]=True break if not match: return global sent_cycle, command if not sent_cycle: command+=" -c "+m.group(1) sent_cycle=True if match: command+=" -t "+match for line in sys.stdin.readlines(): m=re.match('^(\d+)\s+(\S+)',line) if m: process_line(line,m) bad=True for ijob in xrange(len(joblist)): if not jobfound[ijob]: sys.stderr.write(' ===> no such job: %s <==\n'%(joblist[ijob],)) else: bad=False if bad: sys.stderr.write(' ===> No jobs found <===\n') print '/bin/false' sys.exit(1) if joblist is None: command+=' -a' print(command+'\n')