CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
fileTransfer.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os, time, sys, shutil, glob, smtplib, re, commands
4 import getopt as gop
5 import zipfile as zp
6 from datetime import datetime
7 from email.MIMEText import MIMEText
8 
9 SOURCEDIR = "/dqmdata/dqm/merged" #Directory where the original files are located.
10 INJECTIONDIR = "/dqmdata/dqm/Tier0Shipping/inject" #Directory where files get placed once they have been sent.
11 TRASHCAN = "/dqmdata/dqm/trashcan"
12 HOSTNAME = "srv-C2D05-19"
13 CONFIGFILE = "/nfshome0/dqm/.transfer/myconfig.txt"
14 INJECTIONSCRIPT = "/nfshome0/tier0/scripts/injectFileIntoTransferSystem.pl"
15 
16 EMPTY_TRASHCAN = False
17 WAIT_TIME = 600
18 ################################################################################
20  newfiles={}
21  trashfiles=[]
22  filelist=[]
23  for dir1, subdirs, files in os.walk(SOURCEDIR):
24  for f in files:
25  try:
26  version=int(f.split("_V")[-1][:4])
27  vlfn=f.split("_V")[0]+f.split("_V")[1][4:]
28  except:
29  version=1
30  vlfn=f
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))
35  else:
36  trashfiles.append("%s/%s" % (dir1,f))
37 
38  return (newfiles,trashfiles)
39 #=====================================================================================
40 def injectFile(f,renotify=False):
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)
45  shutil.move(f,iname)
46  parameters=["--filename %s" % fname,
47  "--type dqm",
48  "--path %s" % INJECTIONDIR,
49  "--destination dqm",
50  "--hostname %s" % HOSTNAME,
51  "--config %s" % CONFIGFILE,
52  "--runnumber %s" % run,
53  "--lumisection 95",
54  "--numevents 834474816",
55  "--appname dqmArchive",
56  "--appversion dqmArchive_1_0"]
57  cmd="%s %s" % (INJECTIONSCRIPT," ".join(parameters))
58  result = commands.getstatusoutput(cmd)
59  if result[0] >= 1:
60  output = result[1]
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)
65  if result[0]==1:
66  if "File not found in database" in result[1]:
67  print "Error: file %s not found in transfer database, check configuration" % f
68  return 0
69  else:
70  print "Warning: file %s already exists in transfer database" % f
71  return 2
72  else:
73  print "Error: problem checking database entry for file %s\n Error:%s" % (f,result[1])
74  return 0
75  else:
76  print "File %s injected successfully" % f
77  return 1
78 #=====================================================================================
80  while True:
81  #look for NEW files in SOURCEDIR and files that need to be cleared.
82  newfiles,trashfiles=getFileLists()
83 
84  #Making sure destination directories exist
85  if not os.path.exists(TRASHCAN):
86  os.makedirs(TRASHCAN)
87  if not os.path.exists(INJECTIONDIR):
88  os.makedirs(INJECTIONDIR)
89 
90  #Dealing with trash can
91  for tf in trashfiles:
92  if EMPTY_TRASHCAN:
93  os.remove(tf)
94  else:
95  tfname="%s/%s" % (TRASHCAN,tf.rsplit("/",1)[-1])
96  shutil.move(tf,tfname)
97 
98  #Down to bussines
99  for ver,f in newfiles.values():
100  ifr=injectFile(f)
101  time.sleep(WAIT_TIMEt )
102 #=====================================================================================
103 if __name__ == "__main__":
104  transferFiles()
static std::string join(char **cmd)
Definition: RemoteFile.cc:18