3 import os, time, sys, shutil, glob, smtplib, re, commands
6 from datetime
import datetime
7 from email.MIMEText
import MIMEText
9 SOURCEDIR =
"/dqmdata/dqm/merged"
10 INJECTIONDIR =
"/dqmdata/dqm/Tier0Shipping/inject"
11 TRASHCAN =
"/dqmdata/dqm/trashcan"
12 HOSTNAME =
"srv-C2D05-19"
13 CONFIGFILE =
"/nfshome0/dqm/.transfer/myconfig.txt"
14 INJECTIONSCRIPT =
"/nfshome0/tier0/scripts/injectFileIntoTransferSystem.pl"
16 EMPTY_TRASHCAN =
False
23 for dir1, subdirs, files
in os.walk(SOURCEDIR):
26 version=int(f.split(
"_V")[-1][:4])
27 vlfn=f.split(
"_V")[0]+f.split(
"_V")[1][4:]
31 if vlfn
in newfiles.keys()
and version >= newfiles[vlfn][0]:
32 newfiles[vlfn]=(version,
"%s/%s" % (dir1,f))
33 elif vlfn
not in newfiles.keys():
34 newfiles[vlfn]=(version,
"%s/%s" % (dir1,f))
36 trashfiles.append(
"%s/%s" % (dir1,f))
38 return (newfiles,trashfiles)
41 fname=f.rsplit(
"/",1)[-1]
42 dname=f.rsplit(
"/",1)[0]
43 run=f.split(
"_R")[-1][:9]
44 iname=
"%s/%s" % (INJECTIONDIR,fname)
46 parameters=[
"--filename %s" % fname,
48 "--path %s" % INJECTIONDIR,
50 "--hostname %s" % HOSTNAME,
51 "--config %s" % CONFIGFILE,
52 "--runnumber %s" % run,
54 "--numevents 834474816",
55 "--appname dqmArchive",
56 "--appversion dqmArchive_1_0"]
57 cmd=
"%s %s" % (INJECTIONSCRIPT,
" ".
join(parameters))
58 result = commands.getstatusoutput(cmd)
61 print "Error injecting file %s to transfer system checking if it exists" % f
62 chkparameters=[
"--check",
"--filename %s" % fname,
"--config %s" % CONFIGFILE]
63 cmd=
"%s %s" % (INJECTIONSCRIPT,
" ".
join(chkparameters))
64 result = commands.getstatusoutput(cmd)
66 if "File not found in database" in result[1]:
67 print "Error: file %s not found in transfer database, check configuration" % f
70 print "Warning: file %s already exists in transfer database" % f
73 print "Error: problem checking database entry for file %s\n Error:%s" % (f,result[1])
76 print "File %s injected successfully" % f
85 if not os.path.exists(TRASHCAN):
87 if not os.path.exists(INJECTIONDIR):
88 os.makedirs(INJECTIONDIR)
95 tfname=
"%s/%s" % (TRASHCAN,tf.rsplit(
"/",1)[-1])
96 shutil.move(tf,tfname)
99 for ver,f
in newfiles.values():
101 time.sleep(WAIT_TIMEt )
103 if __name__ ==
"__main__":
static std::string join(char **cmd)