1
2 '''
3 A base class for any job that uses the qube qb.backend.pythonChildBackEnd modules
4 '''
5
6
7
8
9
10 import sys
11 import os
12 import logging
13
14 try:
15 import qb
16 except:
17 if 'QBDIR' in os.environ:
18 QBDIR = os.environ['QBDIR']
19 else:
20 if os.name == 'posix':
21 if os.uname()[0] == 'Darwin':
22 QBDIR = '/Applications/pfx/qube'
23 else:
24 QBDIR = '/usr/local/pfx/qube'
25
26 sys.path.append('%s/api/python' % QBDIR)
27 import qb
28
29
30 try:
31 from qb import frontend
32 except ImportError:
33 from AppUI import frontend
34
35
37 - def __init__(self, prototype='', dev=False):
38 '''
39 @param dev: Set the 'dev' value for the Qube job, enables debug output on the farm.
40 @type dev: bool
41 '''
42 super(PythonChildJob, self).__init__(prototype=prototype)
43
44 pkg = self['package']
45
46 pkg['dev'] = dev
47
48 pkg['jobSetupCmds'] = []
49 pkg['jobTeardownCmds'] = []
50
51 pkg['pyExecutable'] = ''
52
54 '''
55 Add commands to the job that will be run once every time a worker is
56 started up or shut down.
57
58 @param cmds: The list of cmds to run.
59 @type cmds: list
60
61 @param cmdType: Specify where the commands are run before or after
62 the worker requests agenda items (work) from the supervisor.
63 - B{setup} commands are run before any work is performed, and can
64 be used to set up the job's work environment, load a file, create
65 temp dirs, etc.
66 - B{teardown} commands are run after all work has been processed.
67 Common uses may be to clean up temp dirs, etc.
68 @type cmdType: str
69
70 @raise TypeError: Raised when an unknown value is passed in for cmdType parameter.
71 '''
72 if not cmds:
73 cmds = []
74
75 if cmdType not in ['setup', 'teardown']:
76 raise TypeError, 'Unknown command type: %s' % cmdType
77
78 if isinstance(cmds, str):
79 cmds = [cmds]
80
81 self['package']['job%sCmds' % cmdType.capitalize()].extend(cmds)
82
83 return []
84