some usage text improvements
[paralleljobs.git] / paralleljobs.py
index e97a4f71a009c52f18dea26a1da3350e3b474466..6a1da0df60929f5aa29367fc1f5c06c1a0bc9b45 100755 (executable)
@@ -33,7 +33,6 @@ def printStatusInfo(conn):
 
     c.close()
 
-    print(nototal, nodone, wldone, wltotal)
     perdone = 100.0*float(nodone)/float(nototal)
     perwl = 100.0*float(wldone)/float(wltotal)
 
@@ -67,12 +66,13 @@ def runCmd(cmd):
     return exitcode, out, err
 
 def processJob(conn, jobid):
-    print("Process job %d" % (jobid))
 
     c = conn.cursor()
     c.execute("SELECT cmd FROM jobs WHERE id=?", (jobid,))
     cmd, = c.fetchone()
 
+    print("Process job %d: %s" % (jobid, cmd))
+
     ec, out, err = runCmd(cmd)
     c.execute("UPDATE jobs SET exitcode=?, done=1 WHERE id=?;", (ec, jobid))
 
@@ -162,13 +162,14 @@ Usage:
 COMMANDS:
   -c cmdfn        add jobs from the file with list of commands
   -h              print this text
-  -s              print status information
-  -w              work on the database
+  -s              print progress information
+  -w              do work and process jobs
 
 OPTIONS:
   -d database     the database to process
+  -n num          in -w mode, only process num-many jobs
   -p cols-def     create properties table with SQL column spec
-  -v              print output of the job's command
+  -v              verbose output
 
 Commands may be combined in one call of {0}.
 
@@ -207,9 +208,10 @@ if __name__ == "__main__":
     propdef = None
     work = False
     status = False
+    numjobs = None
 
     try:
-        opts, args = getopt.getopt(sys.argv[1:], "hd:c:p:wsv")
+        opts, args = getopt.getopt(sys.argv[1:], "hd:c:p:wsvn:")
 
         for opt, arg in opts:
             if opt == "-h":
@@ -227,6 +229,8 @@ if __name__ == "__main__":
                 status = True
             elif opt == "-v":
                 verbose = True
+            elif opt == "-n":
+                numjobs = int(arg)
             else:
                 print("Unknown option '", opt, "'.")
 
@@ -255,12 +259,15 @@ if __name__ == "__main__":
         insertJobs(conn, cmds)
 
     if work:
-        while True:
+        n = 0
+        while not numjobs or n < numjobs:
+
             jobid = getNextJobId(conn)
             if jobid == None:
                 print("All jobs have been started.")
                 break
             processJob(conn, jobid)
+            n += 1
 
 
     conn.close()