CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
popcon2dropbox.py
Go to the documentation of this file.
1 import subprocess
2 import json
3 import netrc
4 from os import rename
5 from os import remove
6 from os import path
7 
8 confFileName ='popcon2dropbox.json'
9 fileNameForDropBox = 'input_for_dropbox'
10 dbFileForDropBox = '%s.db' %fileNameForDropBox
11 dbLogFile = '%s_log.db' %fileNameForDropBox
12 
13 import upload_popcon
14 
16  def __init__( self ):
17  self.md = {}
18  with open(confFileName) as jf:
19  self.md = json.load(jf)
20 
21  def authPath( self ):
22  return self.md.get('authenticationPath')
23 
24  def authSys( self ):
25  return self.md.get('authenticationSystem')
26 
27  def destinationDatabase( self ):
28  return self.md.get('destinationDatabase')
29 
30  def logDbFileName( self ):
31  return self.md.get('logDbFileName')
32 
33  def records( self ):
34  return self.md.get('records')
35 
36  def dumpMetadataForUpload( self, inputtag, desttag, comment ):
37  uploadMd = {}
38  uploadMd['destinationDatabase'] = self.destinationDatabase()
39  tags = {}
40  tagInfo = {}
41  tagInfo['dependencies'] = {}
42  tagInfo['synchronizeTo'] = 'offline'
43  tags[ desttag ] = tagInfo
44  print tags
45  uploadMd['destinationTags'] = tags
46  uploadMd['inputTag'] = inputtag
47  uploadMd['since'] = None
48  uploadMd['userText'] = comment
49  with open( '%s.txt' %fileNameForDropBox, 'wb') as jf:
50  jf.write( json.dumps( uploadMd, sort_keys=True, indent = 2 ) )
51  jf.write('\n')
52 
53 def runO2O( cmsswdir, releasepath, release, arch, jobfilename, logfilename, *p ):
54  # first remove any existing metadata file...
55  if path.exists( '%s.db' %fileNameForDropBox ):
56  print "Removing files with name %s" %fileNameForDropBox
57  remove( '%s.db' %fileNameForDropBox )
58  if path.exists( '%s.txt' %fileNameForDropBox ):
59  remove( '%s.txt' %fileNameForDropBox )
60  command = 'export SCRAM_ARCH=%s;' %arch
61  command += 'CMSSWDIR=%s;' %cmsswdir
62  command += 'source ${CMSSWDIR}/cmsset_default.sh;'
63  command += 'cd %s/%s/src;' %(releasepath,release)
64  command += 'eval `scramv1 runtime -sh`;'
65  command += 'cd -;'
66  command += 'pwd;'
67  command += 'cmsRun %s ' %jobfilename
68  command += ' '.join(p)
69  command += ' 2>&1'
70  pipe = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
71  stdout_val = pipe.communicate()[0]
72  return stdout_val
73 
74 def upload_to_dropbox( backend ):
75  md = CondMetaData()
76  # first remove any existing metadata file...
77  if path.exists( '%s.txt' %fileNameForDropBox ):
78  remove( '%s.txt' %fileNameForDropBox )
79  try:
80  dropBox = upload_popcon.DropBox(upload_popcon.defaultHostname, upload_popcon.defaultUrlTemplate)
81  # Try to find the netrc entry
82  try:
83  (username, account, password) = netrc.netrc().authenticators(upload_popcon.defaultNetrcHost)
84  except Exception:
85  print 'Netrc entry "DropBox" not found.'
86  return
87  dropBox.signIn(username, password)
88  for k,v in md.records().items():
89  destTag = v.get("destinationTag")
90  inputTag = v.get("sqliteTag")
91  if inputTag == None:
92  inputTag = destTag
93  comment = v.get("comment")
94  md.dumpMetadataForUpload( inputTag, destTag, comment )
95  dropBox.uploadFile(dbFileForDropBox, backend, upload_popcon.defaultTemporaryFile)
96  dropBox.signOut()
97  except HTTPError as e:
98  print e
99 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
list object
Definition: dbtoconf.py:77