|
Package pyCmdline ::
Module cmdlineBackEnd
|
|
1 '''
2 A class that implements the standard Qube! cmdline jobtype in python.
3 It should be simpler to maintain and extend than the older C++ variant.
4 '''
5
6
7
8
9
10
11 import sys
12 import os
13 import re
14 import time
15 import select
16 import pprint
17 import logging
18
19 import qb.backend.commandBackEnd
20 import qb.backend.logParser
21 import qb.backend.utils as backendUtils
22
23 try:
24 import subprocess
25 except ImportError:
26 if os.name == 'posix':
27 import popen2
28
29
31 '''
32 A backend for a python-based cmdline jobtype which allows for extensible log parsing.
33 '''
35 '''
36 Now that we've got a job from the supervisor it's time to do the work.
37 Everything we need to know to get the work done is in the job's package dict.
38 '''
39 self.status = 1
40
41
42
43
44 cmd = self.job['package']['cmdline']
45 retCode = self.runCmd(self.job, cmd)
46
47 if retCode > 0:
48 backendUtils.flushPrint('ERROR: Proccesing work failed\n', fhList=[sys.stdout, sys.stderr])
49
50 self.status = retCode
51
52
53 if self.status == 0:
54 self.job['status'] = 'complete'
55 else:
56 self.job['status'] = 'failed'
57
58
59 backendUtils.bannerPrint('Setting job instance to %(status)s' % self.job, fhList=[sys.stdout, sys.stderr])
60
61
62 if __name__ == '__main__':
63 import sys, os
64 import qb
65
66 cwd = os.getcwd()
67
68 testDir = os.path.join(cwd, 'test')
69 testScript = os.path.join(testDir, 'printProgressPercent.py')
70
71 cmd = '%s 0.1' % testScript
72
73 if 'dev' in sys.argv:
74 dev = True
75 else:
76 dev = False
77
78 job = {
79 'prototype': 'pyCmdline',
80 'dev': dev,
81 'cpus': 2,
82 'package': {
83 'cmdline': cmd,
84
85
86 'regex_outputPaths': 'Rendered out (.*) in',
87 'regex_progress': 'Progress:(\d+)%',
88
89
90 'logParser': {'className': 'ProgressPercentageLogParser', 'modulePath': 'qb.backend.logParser'}
91 },
92 }
93
94 if '--arc' in sys.argv:
95 arcFile = './job.qja'
96 arcSize = qb.archivejob(arcFile, job, qb.QB_API_BINARY)
97 print 'exported job. wrote: %s bytes to file: %s' % (arcSize, arcFile)
98 else:
99 for j in qb.submit(job):
100 print 'submitted: %(id)s' % j
101