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 synchronizeTo( self ):
34  return self.md.get('synchronizeTo')
35 
36  def records( self ):
37  return self.md.get('records')
38 
39  def dumpMetadataForUpload( self, inputtag, desttag, comment ):
40  uploadMd = {}
41  uploadMd['destinationDatabase'] = self.destinationDatabase()
42  tags = {}
43  tagInfo = {}
44  tagInfo['dependencies'] = {}
45  tagInfo['synchronizeTo'] = self.synchronizeTo()
46  tags[ desttag ] = tagInfo
47  print tags
48  uploadMd['destinationTags'] = tags
49  uploadMd['inputTag'] = inputtag
50  uploadMd['since'] = None
51  uploadMd['userText'] = comment
52  with open( '%s.txt' %fileNameForDropBox, 'wb') as jf:
53  jf.write( json.dumps( uploadMd, sort_keys=True, indent = 2 ) )
54  jf.write('\n')
55 
56 def runO2O( cmsswdir, releasepath, release, arch, jobfilename, logfilename, *p ):
57  # first remove any existing metadata file...
58  if path.exists( '%s.db' %fileNameForDropBox ):
59  print "Removing files with name %s" %fileNameForDropBox
60  remove( '%s.db' %fileNameForDropBox )
61  if path.exists( '%s.txt' %fileNameForDropBox ):
62  remove( '%s.txt' %fileNameForDropBox )
63  command = 'export SCRAM_ARCH=%s;' %arch
64  command += 'CMSSWDIR=%s;' %cmsswdir
65  command += 'source ${CMSSWDIR}/cmsset_default.sh;'
66  command += 'cd %s/%s/src;' %(releasepath,release)
67  command += 'eval `scramv1 runtime -sh`;'
68  command += 'cd -;'
69  command += 'pwd;'
70  command += 'cmsRun %s ' %jobfilename
71  command += ' '.join(p)
72  command += ' 2>&1'
73  pipe = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
74  stdout_val = pipe.communicate()[0]
75  return stdout_val
76 
77 def upload_to_dropbox( backend ):
78  md = CondMetaData()
79  # first remove any existing metadata file...
80  if path.exists( '%s.txt' %fileNameForDropBox ):
81  remove( '%s.txt' %fileNameForDropBox )
82  try:
83  dropBox = upload_popcon.DropBox(upload_popcon.defaultHostname, upload_popcon.defaultUrlTemplate)
84  # Try to find the netrc entry
85  try:
86  (username, account, password) = netrc.netrc().authenticators(upload_popcon.defaultNetrcHost)
87  except Exception:
88  print 'Netrc entry "DropBox" not found.'
89  return
90  print 'signing in...'
91  dropBox.signIn(username, password)
92  print 'signed in'
93  for k,v in md.records().items():
94  destTag = v.get("destinationTag")
95  inputTag = v.get("sqliteTag")
96  if inputTag == None:
97  inputTag = destTag
98  comment = v.get("comment")
99  md.dumpMetadataForUpload( inputTag, destTag, comment )
100  dropBox.uploadFile(dbFileForDropBox, backend, upload_popcon.defaultTemporaryFile)
101  dropBox.signOut()
102  except upload_popcon.HTTPError as e:
103  print e
104 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
list object
Definition: dbtoconf.py:77