CMS 3D CMS Logo

checkforupdate.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import os,commands,re,urllib2
4  def __init__(self,statusfilename='tagstatus.txt'):
5  self.lumiurl='http://cms-service-lumi.web.cern.ch/cms-service-lumi/'+statusfilename
6  def fetchTagsHTTP(self):
7  taglist=[]
8  openurl=urllib2.build_opener()
9  tagfile=openurl.open(self.lumiurl)
10  tagfileStr=tagfile.read()
11  for tag in tagfileStr.lstrip('\n').strip('\n').split('\n'):
12  fields=tag.split(',')
13  taglist.append([fields[0],fields[1],fields[2]])
14  return taglist
15  def runningVersion(self,cmsswWorkingBase,scriptname,isverbose=True):
16  currentdir=os.getcwd()
17  os.chdir(os.path.join(cmsswWorkingBase,'src','RecoLuminosity','LumiDB','scripts'))
18  cvscmmd='cvs status '+scriptname
19  (cmmdstatus,result)=commands.getstatusoutput(cvscmmd+'| grep "Sticky Tag:"')
20  os.chdir(currentdir)
21  cleanresult=result.lstrip().strip()
22  cleanresult=re.sub(r'\s+|\t+',' ',cleanresult)
23  allfields=cleanresult.split(' ')
24  workingversion = "n/a"
25  for line in [line for line in result.split('\n') if "Sticky Tag" in line]:
26  workingversion = line.split()[2]
27  if workingversion=='(none)':
28  workingversion='HEAD'
29  if isverbose:
30  print('checking current version......')
31  print(' project base : '+cmsswWorkingBase)
32  print(' script : '+scriptname)
33  print(' version : '+workingversion)
34  return workingversion
35  def checkforupdate(self,workingtag,isverbose=True):
36  newtags=self.fetchTagsHTTP()
37  if workingtag=='(none)':#means HEAD
38  if isverbose:
39  print('checking update for HEAD')
40  print(' no update')
41  return []
42  w=workingtag.lstrip('V').split('-')
43  if len(w)!=3:
44  #print workingtag+' is not a release tag, can not compare'
45  return []
46  w=[int(r) for r in w]
47  updatetags=[]
48  for [tagstr,ismajor,desc] in newtags:
49  digits=[int(r) for r in tagstr.lstrip('V').split('-')]
50  if digits[0]==w[0] and digits[1]==w[1] and digits[2]==w[2]:
51  continue
52  if digits[0]<w[0]:
53  continue
54  elif digits[0]==w[0]:
55  if digits[1]<w[1]:
56  continue
57  elif digits[1]==w[1]:
58  if digits[2]<=w[2]:
59  continue
60  updatetags.append([tagstr,ismajor,desc])
61  if isverbose:
62  print('checking update for '+workingtag)
63  if not updatetags:
64  print(' no update')
65  return []
66  for [tag,ismajor,description] in updatetags:
67  if ismajor=='1':
68  print(' major update, tag ',tag+' , '+description)
69  else:
70  print(' minor update, tag ',tag+' , '+description)
71  return updatetags
72 
73 if __name__=='__main__':
74  scriptname='lumiCalc2.py'
75  cmsswWorkingBase=os.environ['CMSSW_BASE']
77  workingversion=c.runningVersion(cmsswWorkingBase,scriptname)
78  #c.checkforupdate('V03-03-07')
79  c.checkforupdate(workingversion)
80 
81 
def checkforupdate(self, workingtag, isverbose=True)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def runningVersion(self, cmsswWorkingBase, scriptname, isverbose=True)
def __init__(self, statusfilename='tagstatus.txt')
double split
Definition: MVATrainer.cc:139