CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
popcon2dropbox Namespace Reference

Functions

def run
 
def upload
 

Variables

string confFileName = 'popcon2dropbox.json'
 
string dateformatForFolder = "%y-%m-%d-%H-%M-%S"
 
string dateformatForLabel = "%y-%m-%d %H:%M:%S"
 
string dbFileForDropBox = '%s.db'
 
string dbLogFile = '%s_log.db'
 
string errorInUploadFileFolder = 'upload_errors'
 
string fileNameForDropBox = 'input_for_dropbox'
 

Function Documentation

def popcon2dropbox.run (   args)

Definition at line 159 of file popcon2dropbox.py.

References upload().

160 def run( args ):
161  if os.path.exists( '%s.db' %fileNameForDropBox ):
162  print "Removing files with name %s" %fileNameForDropBox
163  os.remove( '%s.db' %fileNameForDropBox )
164  if os.path.exists( '%s.txt' %fileNameForDropBox ):
165  os.remove( '%s.txt' %fileNameForDropBox )
166  command = 'cmsRun %s ' %args.job_file
167  command += ' destinationDatabase=%s' %args.destDb
168  command += ' destinationTag=%s' %args.destTag
169  command += ' 2>&1'
170  pipe = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
171  stdout = pipe.communicate()[0]
172  retCode = pipe.returncode
173  print stdout
174  print 'Return code is: %s' %retCode
175  if retCode!=0:
176  print 'O2O job failed. Skipping upload.'
177  return retCode
178  return upload( args.destDb, args.destTag, args.comment, args.auth )
def popcon2dropbox.upload (   destDb,
  destTag,
  comment,
  authPath 
)

Definition at line 83 of file popcon2dropbox.py.

Referenced by run().

83 
84 def upload( destDb, destTag, comment, authPath ):
85  #md = CondMetaData(cfileName)
86  datef = datetime.now()
87 
88  # check if the expected input file is there...
89  if not os.path.exists( dbFileForDropBox ):
90  print 'The input sqlite file has not been produced.'
91  return -1
92 
93  empty = True
94  try:
95  dbcon = sqlite3.connect( dbFileForDropBox )
96  dbcur = dbcon.cursor()
97  dbcur.execute('SELECT * FROM IOV')
98  rows = dbcur.fetchall()
99  for r in rows:
100  empty = False
101  dbcon.close()
102  if empty:
103  print 'The input sqlite file produced contains no data. The upload will be skipped.'
104  return 0
105  except Exception as e:
106  print 'Check on input data failed: %s' %str(e)
107  return -2
108 
109  # first remove any existing metadata file...
110  if os.path.exists( '%s.txt' %fileNameForDropBox ):
111  os.remove( '%s.txt' %fileNameForDropBox )
112 
113  ret = 0
114  # dump Metadata for the Upload
115  uploadMd = {}
116  uploadMd['destinationDatabase'] = destDb
117  tags = {}
118  tagInfo = {}
119  tags[ destTag ] = tagInfo
120  uploadMd['destinationTags'] = tags
121  uploadMd['inputTag'] = destTag
122  uploadMd['since'] = None
123  datelabel = datef.strftime(dateformatForLabel)
124  commentStr = ''
125  if not comment is None:
126  commentStr = comment
127  uploadMd['userText'] = '%s : %s' %(datelabel,commentStr)
128  with open( '%s.txt' %fileNameForDropBox, 'wb') as jf:
129  jf.write( json.dumps( uploadMd, sort_keys=True, indent = 2 ) )
130  jf.write('\n')
131 
132  # run the upload
133  uploadCommand = 'uploadConditions.py %s' %fileNameForDropBox
134  if not authPath is None:
135  uploadCommand += ' -a %s' %authPath
136  try:
137  pipe = subprocess.Popen( uploadCommand, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
138  stdout = pipe.communicate()[0]
139  print stdout
140  retCode = pipe.returncode
141  if retCode != 0:
142  # save a copy of the files in case of upload failure...
143  leafFolderName = datef.strftime(dateformatForFolder)
144  fileFolder = os.path.join( errorInUploadFileFolder, leafFolderName)
145  if not os.path.exists(fileFolder):
146  os.makedirs(fileFolder)
147  df= '%s.db' %fileNameForDropBox
148  mf= '%s.txt' %fileNameForDropBox
149  dataDestFile = os.path.join( fileFolder, df)
150  if not os.path.exists(dataDestFile):
151  shutil.copy2(df, dataDestFile)
152  shutil.copy2(mf,os.path.join(fileFolder,mf))
153  print "Upload failed. Data file and metadata saved in folder '%s'" %os.path.abspath(fileFolder)
154  ret |= retCode
155  except Exception as e:
156  ret |= 1
157  print e
158  return ret

Variable Documentation

string popcon2dropbox.confFileName = 'popcon2dropbox.json'

Definition at line 9 of file popcon2dropbox.py.

string popcon2dropbox.dateformatForFolder = "%y-%m-%d-%H-%M-%S"

Definition at line 14 of file popcon2dropbox.py.

string popcon2dropbox.dateformatForLabel = "%y-%m-%d %H:%M:%S"

Definition at line 15 of file popcon2dropbox.py.

string popcon2dropbox.dbFileForDropBox = '%s.db'

Definition at line 11 of file popcon2dropbox.py.

string popcon2dropbox.dbLogFile = '%s_log.db'

Definition at line 12 of file popcon2dropbox.py.

string popcon2dropbox.errorInUploadFileFolder = 'upload_errors'

Definition at line 13 of file popcon2dropbox.py.

string popcon2dropbox.fileNameForDropBox = 'input_for_dropbox'

Definition at line 10 of file popcon2dropbox.py.