92 import os,atexit,tempfile,shutil
94 keep_files = [os.path.abspath(item)
95 for item
in os.listdir(os.getcwd())]
96 keep_files.append (os.path.abspath(options.oname))
97 keep_files.append (os.path.abspath(
"%s.log"%options.oname))
99 def _cleanup(keep_files):
101 for item
in os.listdir(os.getcwd()):
102 item = os.path.abspath(item)
103 if os.path.basename(item).startswith((
'.__afs',
108 if item
in keep_files:
111 if os.path.isfile (item): os.remove (item)
112 elif os.path.islink (item): os.unlink (item)
113 elif os.path.isdir (item): shutil.rmtree (item)
115 msg.warning (
"don't know what kind of stuff this is: %s",
117 except Exception
as err:
118 errors.append (
"%s"%err)
121 msg.error (
"problem during workdir clean-up")
122 map (msg.error, errors)
124 msg.debug (
"workdir clean-up [ok]")
127 if options.do_clean_up:
128 atexit.register (_cleanup, keep_files)
131 sc,out = subprocess.getstatusoutput (
'which athena.py')
133 msg.error(
"could not locate 'athena.py':\n%s", out)
138 sc,out = subprocess.getstatusoutput (
'which sh')
140 msg.error(
"could not locate 'sh':\n%s",out)
144 logfile = tempfile.NamedTemporaryFile(prefix=
'sg_dumper_job_',
145 suffix=
'.logfile.txt',
152 env = dict(os.environ)
153 env[
'ROOTENV_NO_HOME'] = os.getenv(
'ROOTENV_NO_HOME',
'1')
157 if options.athena_opts:
159 athena_opts = shlex.split(options.athena_opts)
160 cmd = [sh, app,] + athena_opts + [
'--CA'] + [jobo.name,]
161 import subprocess
as sub
162 app_handle = sub.Popen (args=cmd,
169 pat = re.compile (
'.*')
171 pat = re.compile (
r'^Py:pyalg .*')
172 evt_pat = re.compile (
173 r'^Py:pyalg .*? ==> processing event \[(?P<evtnbr>\d*?)\].*'
177 _watcher = open (logfile.name,
'r'); _watcher.seek (0, 2)
178 end = _watcher.tell(); _watcher.seek (pos)
179 mon = [l
for l
in _watcher
182 pos = _watcher.tell()
185 if l.count (
'==> initialize...'):
186 msg.info (
'athena initialized')
188 ievt = evt_pat.match(l).
group(
'evtnbr')
190 msg.info (
'processed event [%s]', ievt)
191 if l.count (
'==> finalize...'):
192 msg.info (
'athena finalized')
197 while app_handle.poll()
is None:
204 sc = app_handle.returncode
208 from io
import StringIO
212 print (l, end=
'', file=err)
214 msg.error (
'problem running jobo')
215 return sc, err.getvalue()
218 from io
import StringIO
222 print (l, end=
'', file=out)
223 return sc, out.getvalue()