CMS 3D CMS Logo

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