Go to the documentation of this file.00001 import os,commands,re,urllib2
00002 class checkforupdate:
00003 def __init__(self,statusfilename='tagstatus.txt'):
00004 self.lumiurl='http://cms-service-lumi.web.cern.ch/cms-service-lumi/'+statusfilename
00005 def fetchTagsHTTP(self):
00006 taglist=[]
00007 openurl=urllib2.build_opener()
00008 tagfile=openurl.open(self.lumiurl)
00009 tagfileStr=tagfile.read()
00010 for tag in tagfileStr.lstrip('\n').strip('\n').split('\n'):
00011 fields=tag.split(',')
00012 taglist.append([fields[0],fields[1],fields[2]])
00013 return taglist
00014 def runningVersion(self,cmsswWorkingBase,scriptname,isverbose=True):
00015 currentdir=os.getcwd()
00016 os.chdir(os.path.join(cmsswWorkingBase,'src','RecoLuminosity','LumiDB','scripts'))
00017 cvscmmd='cvs status '+scriptname
00018 (cmmdstatus,result)=commands.getstatusoutput(cvscmmd+'| grep "Sticky Tag:"')
00019 os.chdir(currentdir)
00020 cleanresult=result.lstrip().strip()
00021 cleanresult=re.sub(r'\s+|\t+',' ',cleanresult)
00022 allfields=cleanresult.split(' ')
00023 workingversion = "n/a"
00024 for line in filter(lambda line: "Sticky Tag" in line, result.split('\n')):
00025 workingversion = line.split()[2]
00026 if workingversion=='(none)':
00027 workingversion='HEAD'
00028 if isverbose:
00029 print 'checking current version......'
00030 print ' project base : '+cmsswWorkingBase
00031 print ' script : '+scriptname
00032 print ' version : '+workingversion
00033 return workingversion
00034 def checkforupdate(self,workingtag,isverbose=True):
00035 newtags=self.fetchTagsHTTP()
00036 if workingtag=='(none)':
00037 if isverbose:
00038 print 'checking update for HEAD'
00039 print ' no update'
00040 return []
00041 w=workingtag.lstrip('V').split('-')
00042 if len(w)!=3:
00043
00044 return []
00045 w=[int(r) for r in w]
00046 updatetags=[]
00047 for [tagstr,ismajor,desc] in newtags:
00048 digits=[int(r) for r in tagstr.lstrip('V').split('-')]
00049 if digits[0]==w[0] and digits[1]==w[1] and digits[2]==w[2]:
00050 continue
00051 if digits[0]<w[0]:
00052 continue
00053 elif digits[0]==w[0]:
00054 if digits[1]<w[1]:
00055 continue
00056 elif digits[1]==w[1]:
00057 if digits[2]<=w[2]:
00058 continue
00059 updatetags.append([tagstr,ismajor,desc])
00060 if isverbose:
00061 print 'checking update for '+workingtag
00062 if not updatetags:
00063 print ' no update'
00064 return []
00065 for [tag,ismajor,description] in updatetags:
00066 if ismajor=='1':
00067 print ' major update, tag ',tag+' , '+description
00068 else:
00069 print ' minor update, tag ',tag+' , '+description
00070 return updatetags
00071
00072 if __name__=='__main__':
00073 scriptname='lumiCalc2.py'
00074 cmsswWorkingBase=os.environ['CMSSW_BASE']
00075 c=checkforupdate()
00076 workingversion=c.runningVersion(cmsswWorkingBase,scriptname)
00077
00078 c.checkforupdate(workingversion)
00079
00080