69 from __future__
import absolute_import
70 from __future__
import print_function
80 from project_modules.ifdherror
import IFDHError
102 for var
in (
'X509_USER_CERT',
'X509_USER_KEY'):
103 if var
in os.environ:
104 save_vars[var] = os.environ[var]
109 cmd = [
'ifdh',
'cp', source, destination]
110 jobinfo = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
113 thread = threading.Thread(target=wait_for_subprocess, args=[jobinfo, q])
115 thread.join(timeout=31000000)
116 if thread.is_alive():
117 print(
'Terminating subprocess.')
124 for var
in list(save_vars.keys()):
125 os.environ[var] = save_vars[var]
126 raise IFDHError(cmd, rc, jobout, joberr)
130 for var
in list(save_vars.keys()):
131 os.environ[var] = save_vars[var]
147 for var
in (
'X509_USER_CERT',
'X509_USER_KEY'):
148 if var
in os.environ:
149 save_vars[var] = os.environ[var]
154 cmd = [
'ifdh',
'ls', path,
'%d' % depth]
155 jobinfo = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
158 thread = threading.Thread(target=wait_for_subprocess, args=[jobinfo, q])
160 thread.join(timeout=600)
161 if thread.is_alive():
162 print(
'Terminating subprocess.')
169 for var
in list(save_vars.keys()):
170 os.environ[var] = save_vars[var]
171 raise IFDHError(cmd, rc, jobout, joberr)
175 for var
in list(save_vars.keys()):
176 os.environ[var] = save_vars[var]
180 return jobout.splitlines()
196 for var
in (
'X509_USER_CERT',
'X509_USER_KEY'):
197 if var
in os.environ:
198 save_vars[var] = os.environ[var]
203 cmd = [
'ifdh',
'll', path,
'%d' % depth]
204 jobinfo = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
207 thread = threading.Thread(target=wait_for_subprocess, args=[jobinfo, q])
209 thread.join(timeout=60)
210 if thread.is_alive():
211 print(
'Terminating subprocess.')
218 for var
in list(save_vars.keys()):
219 os.environ[var] = save_vars[var]
220 raise IFDHError(cmd, rc, jobout, joberr)
224 for var
in list(save_vars.keys()):
225 os.environ[var] = save_vars[var]
229 return jobout.splitlines()
244 for var
in (
'X509_USER_CERT',
'X509_USER_KEY'):
245 if var
in os.environ:
246 save_vars[var] = os.environ[var]
251 cmd = [
'ifdh',
'mkdir', path]
252 jobinfo = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
255 thread = threading.Thread(target=wait_for_subprocess, args=[jobinfo, q])
257 thread.join(timeout=60)
258 if thread.is_alive():
259 print(
'Terminating subprocess.')
266 for var
in list(save_vars.keys()):
267 os.environ[var] = save_vars[var]
268 raise IFDHError(cmd, rc, jobout, joberr)
272 for var
in list(save_vars.keys()):
273 os.environ[var] = save_vars[var]
292 for var
in (
'X509_USER_CERT',
'X509_USER_KEY'):
293 if var
in os.environ:
294 save_vars[var] = os.environ[var]
299 cmd = [
'ifdh',
'rmdir', path]
300 jobinfo = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
303 thread = threading.Thread(target=wait_for_subprocess, args=[jobinfo, q])
305 thread.join(timeout=60)
306 if thread.is_alive():
307 print(
'Terminating subprocess.')
314 for var
in list(save_vars.keys()):
315 os.environ[var] = save_vars[var]
316 raise IFDHError(cmd, rc, jobout, joberr)
320 for var
in list(save_vars.keys()):
321 os.environ[var] = save_vars[var]
340 for var
in (
'X509_USER_CERT',
'X509_USER_KEY'):
341 if var
in os.environ:
342 save_vars[var] = os.environ[var]
347 cmd = [
'ifdh',
'chmod',
'%o' % mode, path]
348 jobinfo = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
351 thread = threading.Thread(target=wait_for_subprocess, args=[jobinfo, q])
353 thread.join(timeout=60)
354 if thread.is_alive():
355 print(
'Terminating subprocess.')
362 for var
in list(save_vars.keys()):
363 os.environ[var] = save_vars[var]
364 raise IFDHError(cmd, rc, jobout, joberr)
368 for var
in list(save_vars.keys()):
369 os.environ[var] = save_vars[var]
388 for var
in (
'X509_USER_CERT',
'X509_USER_KEY'):
389 if var
in os.environ:
390 save_vars[var] = os.environ[var]
395 cmd = [
'ifdh',
'mv', src, dest]
396 jobinfo = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
399 thread = threading.Thread(target=wait_for_subprocess, args=[jobinfo, q])
401 thread.join(timeout=60)
402 if thread.is_alive():
403 print(
'Terminating subprocess.')
410 for var
in list(save_vars.keys()):
411 os.environ[var] = save_vars[var]
412 raise IFDHError(cmd, rc, jobout, joberr)
416 for var
in list(save_vars.keys()):
417 os.environ[var] = save_vars[var]
436 for var
in (
'X509_USER_CERT',
'X509_USER_KEY'):
437 if var
in os.environ:
438 save_vars[var] = os.environ[var]
443 cmd = [
'ifdh',
'rm', path]
444 jobinfo = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
447 thread = threading.Thread(target=wait_for_subprocess, args=[jobinfo, q])
449 thread.join(timeout=60)
450 if thread.is_alive():
451 print(
'Terminating subprocess.')
458 for var
in list(save_vars.keys()):
459 os.environ[var] = save_vars[var]
460 raise IFDHError(cmd, rc, jobout, joberr)
464 for var
in list(save_vars.keys()):
465 os.environ[var] = save_vars[var]
476 cmd = [
'cp', source, destination]
480 buffer_pid = os.fork()
486 jobinfo = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
489 thread = threading.Thread(target=wait_for_subprocess, args=[jobinfo, q])
491 thread.join(timeout=600)
492 if thread.is_alive():
498 print(
'Terminating subprocess.')
516 buffer_result = os.waitpid(buffer_pid, 0)
517 rc = buffer_result[1]/256
519 raise IFDHError(cmd, rc,
'',
'')
539 jobout, joberr = jobinfo.communicate(input)
552 ok = subprocess.call([
'klist',
'-s'], stdout=-1, stderr=-1)
554 raise RuntimeError(
'Please get a kerberos ticket.')
575 subprocess.check_call([
'kx509'], stdout=-1, stderr=-1)
601 if 'X509_USER_CERT' in os.environ
and 'X509_USER_KEY' in os.environ:
602 cmd=[
'voms-proxy-init',
604 '-cert', os.environ[
'X509_USER_CERT'],
605 '-key', os.environ[
'X509_USER_KEY'],
608 subprocess.check_call(cmd, stdout=-1, stderr=-1)
614 cmd=[
'voms-proxy-init',
620 subprocess.check_call(cmd, stdout=-1, stderr=-1)
636 if 'X509_USER_PROXY' in os.environ:
637 subprocess.check_call([
'voms-proxy-info',
638 '-file', os.environ[
'X509_USER_PROXY'],
639 '-exists'], stdout=-1, stderr=-1)
640 elif 'X509_USER_CERT' in os.environ
and 'X509_USER_KEY' in os.environ:
641 subprocess.check_call([
'voms-proxy-info',
642 '-file', os.environ[
'X509_USER_CERT'],
643 '-exists'], stdout=-1, stderr=-1)
645 subprocess.check_call([
'voms-proxy-info',
'-exists'], stdout=-1, stderr=-1)
650 x509_path =
convert_str(subprocess.check_output([
'voms-proxy-info',
'-path'], stderr=-1))
651 os.environ[
'X509_USER_PROXY'] = x509_path.strip()
666 if 'X509_USER_PROXY' in os.environ:
667 subprocess.check_call([
'voms-proxy-info',
668 '-file', os.environ[
'X509_USER_PROXY'],
669 '-exists'], stdout=-1, stderr=-1)
670 elif 'X509_USER_CERT' in os.environ
and 'X509_USER_KEY' in os.environ:
671 subprocess.check_call([
'voms-proxy-info',
672 '-file', os.environ[
'X509_USER_CERT'],
673 '-exists'], stdout=-1, stderr=-1)
675 subprocess.check_call([
'voms-proxy-info',
'-exists'], stdout=-1, stderr=-1)
678 raise RuntimeError(
'Please get a kca certificate.')
688 subprocess.check_call([
'voms-proxy-info',
'-exists'], stdout=-1, stderr=-1)
689 subprocess.check_call([
'voms-proxy-info',
'-exists',
'-acissuer'], stdout=-1, stderr=-1)
703 subprocess.check_call([
'voms-proxy-info',
'-exists'], stdout=-1, stderr=-1)
704 subprocess.check_call([
'voms-proxy-info',
'-exists',
'-acissuer'], stdout=-1, stderr=-1)
707 raise RuntimeError(
'Please get a grid proxy.')
719 jobinfo = subprocess.Popen([
'which',
'jobsub_submit'],
720 stdout=subprocess.PIPE,
721 stderr=subprocess.PIPE)
722 jobout, joberr = jobinfo.communicate()
725 jobsub_path = jobout.splitlines()[0].strip()
726 if jobsub_path !=
'':
732 print(
'Please set up jobsub_client')
740 return "fndca1.fnal.gov" 747 if path.startswith(
'/pnfs/')
and not path.startswith(
'/pnfs/fnal.gov/usr/'):
748 return '/pnfs/fnal.gov/usr/' + path[6:]
761 if path.startswith(
'/pnfs/'):
771 if path.startswith(
'/pnfs/'):
781 if path.startswith(
'/pnfs/'):
782 return 'srm://fndca1.fnal.gov:8443/srm/managerv2?SFN=/pnfs/fnal.gov/usr/' + path[6:]
792 return '%sgpvm01.fnal.gov' % os.environ[
'EXPERIMENT']
804 if mode_str[0] ==
'b':
806 elif mode_str[0] ==
'c':
808 elif mode_str[0] ==
'd':
810 elif mode_str[0] ==
'l':
812 elif mode_str[0] ==
'p':
814 elif mode_str[0] ==
's':
815 mode += stat.S_IFSOCK
816 elif mode_str[0] ==
'-':
823 if mode_str[1] ==
'r': 825 if mode_str[2] ==
'w':
827 if mode_str[3] ==
'x':
829 elif mode_str[3] ==
's':
832 elif mode_str[3] ==
'S':
837 if mode_str[4] ==
'r': 839 if mode_str[5] ==
'w':
841 if mode_str[6] ==
'x':
843 elif mode_str[6] ==
's':
846 elif mode_str[6] ==
'S':
851 if mode_str[7] ==
'r': 853 if mode_str[8] ==
'w':
855 if mode_str[9] ==
'x':
857 elif mode_str[9] ==
't':
860 elif mode_str[9] ==
'T':
881 for ev
in (
'EXPERIMENT',
'SAM_EXPERIMENT'):
887 hostname = socket.gethostname()
888 n = hostname.find(
'gpvm')
893 raise RuntimeError(
'Unable to determine experiment.')
909 if 'ROLE' in os.environ:
910 result = os.environ[
'ROLE']
916 user = getpass.getuser()
918 result =
'Production' 934 raise RuntimeError(
'Function get_setup_script_path not implemented.')
941 raise RuntimeError(
'Function dimensions not implemented.')
955 if stage.ana_data_stream !=
None and len(stage.ana_data_stream) > 0:
956 dim1 =
'( data_stream %s and %s )' % (stage.ana_data_stream[index], dim)
959 if stage.data_stream !=
None and len(stage.data_stream) > 0:
960 dim1 =
'( data_stream %s and %s )' % (stage.data_stream[index], dim)
985 return 'fnal-dcache:' 993 raise RuntimeError(
'Function get_dropbox not implemented.')
1029 if 'X509_USER_PROXY' in os.environ:
1030 subject =
convert_str(subprocess.check_output([
'voms-proxy-info',
1031 '-file', os.environ[
'X509_USER_PROXY'],
1032 '-subject'], stderr=-1))
1033 elif 'X509_USER_CERT' in os.environ
and 'X509_USER_KEY' in os.environ:
1034 subject =
convert_str(subprocess.check_output([
'voms-proxy-info',
1035 '-file', os.environ[
'X509_USER_CERT'],
1036 '-subject'], stderr=-1))
1038 subject =
convert_str(subprocess.check_output([
'voms-proxy-info',
'-subject'],
1045 n = subject.rfind(
'/CN=')
1048 if cn.strip().isdigit():
1050 subject = subject[:n]
1079 raise RuntimeError(
'Unable to determine authenticated user.')
1104 for pid
in os.listdir(
'/proc'):
1105 if pid.isdigit()
and int(pid) != os.getpid():
1106 procfile = os.path.join(
'/proc', pid)
1108 pstat = os.stat(procfile)
1112 if pstat.st_uid == os.getuid():
1116 cmdfile = os.path.join(
'/proc', pid,
'cmdline')
1118 words = cmd.split(
'\0')
1134 if word.endswith(
'project.py'):
1139 if xml == 1
and word == xmlname:
1141 elif stage == 1
and word == stagename:
1151 elif word ==
'--stage':
1153 elif word ==
'--submit':
1155 elif word ==
'--makeup':
1158 if project != 0
and submit+makeup != 0
and xmlmatch != 0
and stagematch != 0:
1239 from experiment_utilities
import *
def get_setup_script_path()
def get_sam_metadata(project, stage)
def dimensions(project, stage, ana=False)
def check_running(xmlname, stagename)
int open(const char *, int)
Opens a file descriptor.
def ifdh_cp(source, destination)
def dimensions_datastream(project, stage, ana=False, index=0)
def posix_cp(source, destination)
def ifdh_chmod(path, mode)
def wait_for_subprocess(jobinfo, q, input=None)
def get_dropbox(filename)
int read(int, char *, size_t)
Read bytes from a file descriptor.