CMS 3D CMS Logo

Classes | Functions | Variables

alcaDQMUpload Namespace Reference

Classes

class  HTTPSCertAuth
class  HTTPSCertAuthenticate

Functions

def checkFileName
def checkSSL
def encode
def filetype
def getURL
def main
def marshall
def print_help
def registerFileAtLogServer
def startUpload
def upload

Variables

 HTTPS = httplib.HTTPS
 ssl_cert_file = None
 ssl_key_file = None

Function Documentation

def alcaDQMUpload::checkFileName (   fileName)

Definition at line 162 of file alcaDQMUpload.py.

00163                            :
00164     regWhitespace = re.compile('.*\s.*')
00165     if regWhitespace.match(fileName):
00166         sys.stderr.write("whitespace detected!\n")
00167         return False
00168             
00169     regRelval=re.compile('.*relval.*')
00170     regCMSSW=re.compile('.*CMSSW_[0-9]+_[0-9]+_[0-9]+_.*')
00171     regCMSSWpre=re.compile('.*CMSSW_[0-9]+_[0-9]+_[0-9]+_pre[0-9]+_.*')
00172     if regRelval.match(fileName):
00173         # TODO check for pre-versions
00174         if not regCMSSW.match(fileName):
00175             print "no CMSSW"
00176     return True
00177     # DQM stuff

def alcaDQMUpload::checkSSL (   opts)

Definition at line 116 of file alcaDQMUpload.py.

00117                   :
00118     global ssl_key_file
00119     global ssl_cert_file
00120     
00121     if opts.ssl_key_file and os.path.exists(opts.ssl_key_file):
00122         ssl_key_file = opts.ssl_key_file
00123     if opts.ssl_cert_file and os.path.exists(opts.ssl_cert_file):
00124         ssl_cert_file = opts.ssl_cert_file
00125 
00126     if not ssl_key_file:
00127         x509_path = os.getenv("X509_USER_PROXY", None)
00128         if x509_path and os.path.exists(x509_path):
00129             ssl_key_file = ssl_cert_file = x509_path
00130 
00131     if not ssl_key_file:
00132         x509_path = os.getenv("X509_USER_KEY", None)
00133         if x509_path and os.path.exists(x509_path):
00134             ssl_key_file = x509_path
00135 
00136     if not ssl_cert_file:
00137         x509_path = os.getenv("X509_USER_CERT", None)
00138         if x509_path and os.path.exists(x509_path):
00139             ssl_cert_file = x509_path
00140     
00141     if not ssl_key_file:
00142         x509_path = os.getenv("HOME") + "/.globus/userkey.pem"
00143         if os.path.exists(x509_path):
00144             ssl_key_file = x509_path
00145 
00146     if not ssl_cert_file:
00147         x509_path = os.getenv("HOME") + "/.globus/usercert.pem"
00148         if os.path.exists(x509_path):
00149             ssl_cert_file = x509_path
00150     
00151     if not ssl_key_file or not os.path.exists(ssl_key_file):
00152         sys.stderr.write("no certificate private key file found, please specify one via $X509_USER_PROXY, $X509_USER_KEY or --ssl-key-file\n")
00153         sys.exit(2)
00154                   
00155     if not ssl_cert_file or not os.path.exists(ssl_cert_file):
00156         sys.stderr.write("no certificate public key file found, please specify one via $X509_USER_CERT or --ssl-cert-file\n")
00157         sys.exit(3)
00158 
00159     print "Using SSL private key", ssl_key_file
00160     print "Using SSL public key", ssl_cert_file
00161 
                                                                                  
def alcaDQMUpload::encode (   args,
  files 
)
  Encode form (name, value) and (name, filename, type) elements into
  multi-part/form-data. We don't actually need to know what we are
  uploading here, so just claim it's all text/plain.

Definition at line 31 of file alcaDQMUpload.py.

Referenced by trigger::TriggerEvent::addCollections(), cond::DecodingKey::createFile(), EmDQM::fillHistos(), egHLT::trigTools::getFiltersPassed(), HLTMuonIsoFilter::HLTMuonIsoFilter(), and egHLT::trigTools::setFiltersObjPasses().

00032                        :
00033   """
00034     Encode form (name, value) and (name, filename, type) elements into
00035     multi-part/form-data. We don't actually need to know what we are
00036     uploading here, so just claim it's all text/plain.
00037   """
00038   boundary = '----------=_DQM_FILE_BOUNDARY_=-----------'
00039   (body, crlf) = ('', '\r\n')
00040   for (key, value) in args.items():
00041     body += '--' + boundary + crlf
00042     body += ('Content-disposition: form-data; name="%s"' % key) + crlf
00043     body += crlf + str(value) + crlf
00044   for (key, filename) in files.items():
00045     body += '--' + boundary + crlf
00046     body += ('Content-Disposition: form-data; name="%s"; filename="%s"'
00047              % (key, os.path.basename(filename))) + crlf
00048     body += ('Content-Type: %s' % filetype(filename)) + crlf
00049     body += crlf + open(filename, "r").read() + crlf
00050   body += '--' + boundary + '--' + crlf + crlf
00051   return ('multipart/form-data; boundary=' + boundary, body)

def alcaDQMUpload::filetype (   filename)

Definition at line 28 of file alcaDQMUpload.py.

Referenced by SiStripQualityStatistics::analyze(), TrackerMap::save(), TrackerMap::save_as_fectrackermap(), TrackerMap::save_as_fedtrackermap(), TrackerMap::save_as_HVtrackermap(), and TrackerMap::save_as_psutrackermap().

00029                       :
00030   return mimetypes.guess_type(filename)[0] or 'application/octet-stream'

def alcaDQMUpload::getURL (   filename,
  destination 
)

Definition at line 200 of file alcaDQMUpload.py.

00201                                  :
00202         filename = filename.split("/")[-1]
00203         regMC=re.compile('.*_R([0-9]*)__*')
00204         if regMC.match(filename):
00205                 m = re.search('.*_R([0-9]*)(__.*).root',filename)
00206                 runNr = m.group(1)
00207                 dataset = m.group(2).replace("__","/")
00208         else:
00209                 m = re.search('.*_R([0-9]*)(_?.*).root',filename)
00210                 runNr = m.group(1)
00211                 dataset = m.group(2).replace("__","/")
00212                 if dataset=="":
00213                         dataset="/Global/Online/ALL"
00214         if not runNr:
00215                 runNr="1"
00216         if (int(runNr)==1):
00217                 return destination+"start?workspace=summary;dataset="+dataset+";sampletype=offline_data"
00218         else:
00219                 return destination+"start?workspace=summary;runnr="+runNr+";dataset="+dataset+";sampletype=online_data"
        
def alcaDQMUpload::main (   args)

Definition at line 237 of file alcaDQMUpload.py.

00238               :
00239     global opts
00240     parser = optparse.OptionParser(add_help_option=False)
00241     parser.add_option("-h", "--help",          action="callback", callback=print_help),
00242     parser.add_option("",   "--no-filename-check", dest="no_filename_check",  default=False, action="store_true")
00243     parser.add_option("-d", "--destination", dest="destination", default="",  action="store")
00244     parser.add_option("-t", "--tags", dest="tags", default="",  action="store")
00245     parser.add_option("-s", "--no-submission", dest="submission", default=True,  action="store_false")
00246     parser.add_option("-r", "--no-registration", dest="registration", default=True,  action="store_false")
00247     parser.add_option("","--ssl-key-file", dest="ssl_key_file", default="", action="store")
00248     parser.add_option("","--ssl-cert-file", dest="ssl_cert_file", default="", action="store")
00249     (opts, args) = parser.parse_args()
00250     opts.abort = False
00251 
00252     if not opts.destination:
00253         sys.stderr.write("no destination specified\n")
00254         sys.exit(4)
00255     checkSSL(opts)
00256 
00257     if len(args)==0:
00258         sys.stderr.write("no input files specified\n")
00259         sys.exit(1)
00260     for fileName in args:
00261         fileName=fileName.strip()
00262         if not os.path.exists(fileName):
00263             sys.stderr.write("file '%s' doesn't exist!\n" % fileName)
00264             continue
00265         if not opts.no_filename_check and not checkFileName(fileName):
00266             continue
00267         sys.stderr.write("file '%s' passed name check, upload will follow!\n" % fileName)
00268         if opts.submission:
00269           startUpload(opts.destination, fileName)
00270         else:
00271           sys.stdout.write("file '%s' would be uploaded to '%s'\n" % (fileName, opts.destination))
00272         if opts.registration:
00273           registerFileAtLogServer(fileName, opts.destination, opts.tags)       
00274         print "You should see the plots here: "+getURL(fileName, opts.destination)

def alcaDQMUpload::marshall (   args,
  files,
  request 
)
  Marshalls the arguments to the CGI script as multi-part/form-data,
  not the default application/x-www-form-url-encoded.  This improves
  the transfer of the large inputs and eases command line invocation
  of the CGI script.

Definition at line 52 of file alcaDQMUpload.py.

00053                                   :
00054   """
00055     Marshalls the arguments to the CGI script as multi-part/form-data,
00056     not the default application/x-www-form-url-encoded.  This improves
00057     the transfer of the large inputs and eases command line invocation
00058     of the CGI script.
00059   """
00060   (type, body) = encode(args, files)
00061   request.add_header('Content-type', type)
00062   request.add_header('Content-length', str(len(body)))
00063   request.add_data(body)

def alcaDQMUpload::print_help (   args)

Definition at line 91 of file alcaDQMUpload.py.

00092                      :
00093     sys.stdout.write("\n")
00094     sys.stdout.write("This scripts intends to do the upload of files to the DQM server. It\n")
00095     sys.stdout.write("runs some basic checks on the file name as it is crucial to follow\n")
00096     sys.stdout.write("the naming convention.\n")
00097     sys.stdout.write("\n")
00098     sys.stdout.write("Mandatory Option\n")
00099     sys.stdout.write("    -d, --destination parameter to specify the DQM server\n")
00100     sys.stdout.write("\n")
00101     sys.stdout.write("  Proxy Options\n")
00102     sys.stdout.write("  The script will try to find your grid proxy automatically. To\n")
00103     sys.stdout.write("  do so, it checks $X509_* environment variables and your globus\n")
00104     sys.stdout.write("  directory (~/.globus). To override this automatism, you can use\n")
00105     sys.stdout.write("  the following two options:\n")
00106     sys.stdout.write("    --ssl-key-file          location of your private key\n")
00107     sys.stdout.write("    --ssl-cert-file         location of your public key\n")
00108     sys.stdout.write("\n")
00109     sys.stdout.write("Other Options\n")
00110     sys.stdout.write("    -h, --help                show this help message\n")
00111     sys.stdout.write("    -s, --no-submission       suppress the submission\n")
00112     sys.stdout.write("    -r, --no-registration     suppress the submission\n")
00113     sys.stdout.write("    --no-filename-check       omit the file name check\n")
00114     sys.stdout.write("\n")
00115     sys.exit(0)

def alcaDQMUpload::registerFileAtLogServer (   filename,
  destination,
  tags 
)

Definition at line 220 of file alcaDQMUpload.py.

00221                                                         :
00222         filename = filename.split("/")[-1]
00223         regMC=re.compile('.*_R([0-9]*)__*')
00224         if regMC.match(filename):
00225                 m = re.search('.*_R([0-9]*)(__.*).root',filename)
00226                 runNr = m.group(1)
00227                 dataset = m.group(2).replace("__","/")
00228         else:
00229                 m = re.search('.*_R([0-9]*)(_?.*).root',filename)
00230                 runNr = m.group(1)
00231                 dataset = m.group(2).replace("__","/")
00232                 if dataset=="":
00233                         dataset="/Global/Online/ALL"
00234         tempurl = "https://www-ekp.physik.uni-karlsruhe.de/~zeise/cgi-bin/register.py?run="+runNr+"&dataset="+dataset+"&filename="+filename+"&tags="+tags+"&instance="+destination
00235         print "Link that is used to register: ", tempurl
00236         urllib.urlopen(tempurl)

def alcaDQMUpload::startUpload (   url,
  filename 
)

Definition at line 178 of file alcaDQMUpload.py.

00179                               :
00180     global ssl_key_file
00181     global ssl_cert_file
00182 
00183     print url, filename
00184     try:
00185         (headers, data) = \
00186                   upload(url,
00187                      { 'size': os.stat(filename).st_size,
00188                        'checksum': "md5:%s" % md5.new(file(filename).read()).hexdigest() },
00189                      { 'file': filename })
00190         print 'Status code: ', headers.get("Dqm-Status-Code", "None")
00191         print 'Message:     ', headers.get("Dqm-Status-Message", "None")
00192         print 'Detail:      ', headers.get("Dqm-Status-Detail", "None")
00193         print data
00194     except urllib2.HTTPError, e:
00195         print "ERROR", e
00196         print 'Status code: ', e.hdrs.get("Dqm-Status-Code", "None")
00197         print 'Message:     ', e.hdrs.get("Dqm-Status-Message", "None")
00198         print 'Detail:      ', e.hdrs.get("Dqm-Status-Detail", "None")
00199         sys.exit(1)

def alcaDQMUpload::upload (   url,
  args,
  files 
)

Definition at line 64 of file alcaDQMUpload.py.

Referenced by CommissioningHistosUsingDb::doUploadAnal(), CommissioningHistosUsingDb::doUploadConf(), ApvTimingHistosUsingDb::uploadConfigurations(), LatencyHistosUsingDb::uploadConfigurations(), and FineDelayHistosUsingDb::uploadConfigurations().

00065                             :
00066   ident = "visDQMUpload DQMGUI/%s CMSSW/%s python/%s" % \
00067     (os.getenv('DQMGUI_VERSION', '?'),
00068      os.getenv('DQM_CMSSW_VERSION', os.getenv('CMSSW_VERSION', '?')),
00069      "%d.%d.%d" % sys.version_info[:3])
00070   cookie = None
00071   if url.startswith("https:"):
00072     authreq = urllib2.Request(url + '/authenticate')
00073     authreq.add_header('User-agent', ident)
00074     result = urllib2.build_opener(HTTPSCertAuthenticate()).open(authreq)
00075     cookie = result.headers.get('Set-Cookie')
00076     if not cookie:
00077       raise RuntimeError("Did not receive authentication cookie")
00078     cookie = cookie.split(";")[0]
00079 
00080   datareq = urllib2.Request(url + '/data/put')
00081   datareq.add_header('Accept-encoding', 'gzip')
00082   datareq.add_header('User-agent', ident)
00083   if cookie:
00084     datareq.add_header('Cookie', cookie)
00085   marshall(args, files, datareq)
00086   result = urllib2.build_opener().open(datareq)
00087   data = result.read()
00088   if result.headers.get ('Content-encoding', '') == 'gzip':
00089     data = gzip.GzipFile (fileobj=StringIO(data)).read ()
00090   return (result.headers, data)


Variable Documentation

alcaDQMUpload::HTTPS = httplib.HTTPS

Definition at line 13 of file alcaDQMUpload.py.

Definition at line 18 of file alcaDQMUpload.py.

Definition at line 17 of file alcaDQMUpload.py.