Deleted Added
sdiff udiff text old ( 1386:793290a922ee ) new ( 1916:fe8d4e92c0a7 )
full compact
1# Copyright (c) 2005 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 77 unchanged lines hidden (view full) ---

86 if self.status < 0:
87 pid, status = os.waitpid(self.pid, 0)
88 if pid == self.pid:
89 self.status = status
90 return self.status
91
92class qsub:
93 def __init__(self):
94 self.hold = False
95 self.join = False
96 self.keep_stdout = False
97 self.keep_stderr = False
98 self.node_type = ''
99 self.mail_abort = False
100 self.mail_begin = False
101 self.mail_end = False
102 self.name = ''
103 self.stdout = ''
104 self.priority = 0
105 self.queue = ''
106 self.pbshost = ''
107 self.qsub = 'qsub'
108 self.env = {}
109
110 def build(self, script, args = []):
111 self.cmd = [ self.qsub ]
112
113 if self.env:
114 arg = '-v'
115 arg += ','.join([ '%s=%s' % i for i in self.env.iteritems() ])
116 self.cmd.append(arg)
117
118 if self.hold:
119 self.cmd.append('-h')
120
121 if len(self.stdout):
122 self.cmd.append('-olocalhost:' + self.stdout)
123
124 if self.keep_stdout and self.keep_stderr:
125 self.cmd.append('-koe')
126 elif self.keep_stdout:
127 self.cmd.append('-ko')
128 elif self.keep_stderr:
129 self.cmd.append('-ke')
130 else:
131 self.cmd.append('-kn')
132
133 if self.join:
134 self.cmd.append('-joe')
135
136 if len(self.node_type):
137 self.cmd.append('-lnodes=' + self.node_type)
138
139 if self.mail_abort or self.mail_begin or self.mail_end:
140 flags = ''
141 if self.mail_abort:
142 flags.append('a')
143 if self.mail_begin:
144 flags.append('b')
145 if self.mail_end:
146 flags.append('e')
147 if len(flags):
148 self.cmd.append('-m ' + flags)
149
150 if len(self.name):
151 self.cmd.append("-N%s" % self.name)
152
153 if self.priority != 0:
154 self.cmd.append('-p' + self.priority)
155
156 if len(self.queue):
157 self.cmd.append('-q' + self.queue)
158
159 self.cmd.extend(args)
160 self.script = script
161 self.command = ' '.join(self.cmd + [ self.script ])
162
163 def do(self):
164 pbs = MyPOpen(self.cmd + [ self.script ])
165 self.result = pbs.fromchild.read()
166 ec = pbs.wait()
167
168 if ec != 0 and self.pbshost:
169 cmd = ' '.join(self.cmd + [ '-' ])
170 cmd = [ 'ssh', '-x', self.pbshost, cmd ]
171 self.command = ' '.join(cmd)
172 ssh = MyPOpen(cmd, input = self.script)
173 self.result = ssh.fromchild.read()
174 ec = ssh.wait()
175
176 return ec