CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Member Functions
upload_popcon.DropBox Class Reference
Inheritance diagram for upload_popcon.DropBox:

Public Member Functions

def __init__
 
def signIn
 
def signInSSO
 
def signOut
 
def uploadFile
 

Public Attributes

 hostname
 
 http
 

Private Member Functions

def _checkForUpdates
 

Detailed Description

A dropBox API class.

Definition at line 411 of file upload_popcon.py.

Constructor & Destructor Documentation

def upload_popcon.DropBox.__init__ (   self,
  hostname = defaultHostname,
  urlTemplate = defaultUrlTemplate 
)

Definition at line 415 of file upload_popcon.py.

416  def __init__(self, hostname = defaultHostname, urlTemplate = defaultUrlTemplate):
417  self.hostname = hostname
418  self.http = HTTP()
419  self.http.setBaseUrl(urlTemplate % hostname)
420  os.environ['http_proxy'] = 'http://cmsproxy.cms:3128/'
421  os.environ['https_proxy'] = 'https://cmsproxy.cms:3128/'

Member Function Documentation

def upload_popcon.DropBox._checkForUpdates (   self)
private
Updates this script, if a new version is found.

Definition at line 472 of file upload_popcon.py.

References upload_popcon.DropBox.hostname, and upload_popcon.DropBox.signOut().

473  def _checkForUpdates(self):
474  '''Updates this script, if a new version is found.
475  '''
476 
477  logging.info('%s: Checking for updates...', self.hostname)
478  version = int(self.http.query('getUploadScriptVersion'))
479 
480  if version <= __version__:
481  logging.info('%s: Up to date.', self.hostname)
482  return
483 
484  logging.info('%s: There is a newer version (%s) than the current one (%s): Updating...', self.hostname, version, __version__)
485 
486  logging.info('%s: Downloading new version...', self.hostname)
487  uploadScript = self.http.query('getUploadScript')
488 
489  self.signOut()
490 
491  logging.info('%s: Saving new version...', self.hostname)
492  with open(sys.argv[0], 'wb') as f:
493  f.write(uploadScript)
494 
495  logging.info('%s: Executing new version...', self.hostname)
496  os.execl(sys.executable, *([sys.executable] + sys.argv))
497 
def upload_popcon.DropBox.signIn (   self,
  username,
  password 
)
Signs in the server.

Definition at line 453 of file upload_popcon.py.

References upload_popcon.DropBox.hostname.

Referenced by uploadConditions.ConditionsUploader.signInAgain(), and cmstc.TagCollector.signInInteractive().

454  def signIn(self, username, password):
455  '''Signs in the server.
456  '''
457 
458  logging.info('%s: Signing in...', self.hostname)
459  self.http.query('signIn', {
460  'username': username,
461  'password': password,
462  })
463 
def upload_popcon.DropBox.signInSSO (   self,
  secure = True 
)
Signs in the server via CERN SSO.

Definition at line 422 of file upload_popcon.py.

References upload_popcon.DropBox.hostname.

423  def signInSSO(self, secure = True):
424  '''Signs in the server via CERN SSO.
425  '''
426 
427  if secure:
428  logging.info('%s: Signing in via CERN SSO...', self.hostname)
429  else:
430  logging.info('%s: Signing in via CERN SSO (insecure)...', self.hostname)
431 
432  # FIXME: Insecure connection to -prod until the certificates are fixed.
433  # The connection to the CERN SSO is still secure by default.
434  # On -dev and -int the certificates are installed properly.
435  secureTarget = True
436  if 'cms-conddb-prod' in self.hostname:
437  secureTarget = False
438 
439  # We also use the CERN CA certificate to verify the targets,
440  # so if we are not connecting securely to CERN SSO is because
441  # we do not have the CERN-CA-certs package, so we need to skip
442  # this as well.
443  #
444  # i.e. right now we have these options:
445  # secure == True, secureTarget == True with CERN CA cert, -dev and -int
446  # secure == True, secureTarget == False with CERN CA cert, -prod
447  # secure == False, secureTarget == False without CERN CA cert
448  if not secure:
449  secureTarget = False
450 
451  self.http.addCERNSSOCookies('signInSSO', secureTarget, secure)
452 
def upload_popcon.DropBox.signOut (   self)
Signs out the server.

Definition at line 464 of file upload_popcon.py.

References upload_popcon.DropBox.hostname.

Referenced by uploadConditions.ConditionsUploader._checkForUpdates(), and upload_popcon.DropBox._checkForUpdates().

465  def signOut(self):
466  '''Signs out the server.
467  '''
468 
469  logging.info('%s: Signing out...', self.hostname)
470  self.http.query('signOut')
471 
def upload_popcon.DropBox.uploadFile (   self,
  filename,
  backend = defaultBackend,
  temporaryFile = defaultTemporaryFile 
)
Uploads a file to the dropBox.

The filename can be without extension, with .db or with .txt extension.
It will be stripped and then both .db and .txt files are used.

Definition at line 498 of file upload_popcon.py.

References upload_popcon.addToTarFile(), and upload_popcon.DropBox.hostname.

499  def uploadFile(self, filename, backend = defaultBackend, temporaryFile = defaultTemporaryFile):
500  '''Uploads a file to the dropBox.
501 
502  The filename can be without extension, with .db or with .txt extension.
503  It will be stripped and then both .db and .txt files are used.
504  '''
505 
506  basepath = filename.rsplit('.db', 1)[0].rsplit('.txt', 1)[0]
507  basename = os.path.basename(basepath)
508 
509  logging.info('%s: %s: Creating tar file...', self.hostname, basename)
510 
511  tarFile = tarfile.open(temporaryFile, 'w:bz2')
512 
513  with open('%s.db' % basepath, 'rb') as data:
514  addToTarFile(tarFile, data, 'data.db')
515 
516  with tempfile.NamedTemporaryFile() as metadata:
517  with open('%s.txt' % basepath, 'rb') as originalMetadata:
518  json.dump(json.load(originalMetadata), metadata, sort_keys = True, indent = 4)
519 
520  metadata.seek(0)
521  addToTarFile(tarFile, metadata, 'metadata.txt')
522 
523  tarFile.close()
524 
525  logging.info('%s: %s: Calculating hash...', self.hostname, basename)
526 
527  fileHash = hashlib.sha1()
528  with open(temporaryFile, 'rb') as f:
529  while True:
530  data = f.read(4 * 1024 * 1024)
531 
532  if not data:
533  break
534 
535  fileHash.update(data)
536 
537  fileHash = fileHash.hexdigest()
538 
539  logging.info('%s: %s: Hash: %s', self.hostname, basename, fileHash)
540 
541  logging.info('%s: %s: Uploading file for the %s backend...', self.hostname, basename, backend)
542  os.rename(temporaryFile, fileHash)
543  self.http.query('uploadPopcon', {
544  'backend': backend,
545  'fileName': basename,
546  }, files = {
547  'uploadedFile': fileHash,
548  })
549  os.unlink(fileHash)
550 

Member Data Documentation

upload_popcon.DropBox.hostname

Definition at line 416 of file upload_popcon.py.

Referenced by uploadConditions.ConditionsUploader._checkForUpdates(), upload_popcon.DropBox._checkForUpdates(), uploadConditions.ConditionsUploader.setHost(), uploadConditions.ConditionsUploader.signIn(), upload_popcon.DropBox.signIn(), upload_popcon.DropBox.signInSSO(), uploadConditions.ConditionsUploader.signOut(), upload_popcon.DropBox.signOut(), uploadConditions.ConditionsUploader.uploadFile(), and upload_popcon.DropBox.uploadFile().

upload_popcon.DropBox.http

Definition at line 417 of file upload_popcon.py.

Referenced by uploadConditions.ConditionsUploader.signIn().