CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/RecoLuminosity/LumiDB/python/checkforupdate.py

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='https://cms-service-lumi.web.cern.ch/cms-service-lumi/publicplots/'+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=allfields[2]
00024         if workingversion=='(none)':
00025             workingversion='HEAD'
00026         if isverbose:
00027             print 'checking current version......'
00028             print '  project base : '+cmsswWorkingBase
00029             print '  script : '+scriptname
00030             print '  version : '+workingversion
00031         return allfields[2]
00032     def checkforupdate(self,workingtag,isverbose=True):
00033         newtags=self.fetchTagsHTTP()
00034         if workingtag=='(none)':#means HEAD
00035             if isverbose:
00036                 print 'checking update for HEAD'
00037                 print '  no update'
00038             return []
00039         w=workingtag.lstrip('V').split('-')
00040         if len(w)!=3:
00041             print workingtag+' is not a release tag, can not compare'
00042             return []
00043         w=[int(r) for r in w]
00044         updatetags=[]
00045         for [tagstr,ismajor,desc] in newtags:
00046             digits=[int(r) for r in tagstr.lstrip('V').split('-')]
00047             if digits[0]==w[0] and  digits[1]==w[1] and digits[2]==w[2]:
00048                 continue
00049             if digits[0]<w[0]: 
00050                 continue            
00051             elif digits[0]==w[0]:
00052                 if digits[1]<w[1]:
00053                     continue
00054                 elif digits[1]==w[1]:
00055                     if digits[2]<=w[2]:
00056                         continue
00057             updatetags.append([tagstr,ismajor,desc])
00058         if isverbose:
00059             print 'checking update for '+workingtag
00060             if not updatetags:
00061                 print '  no update'
00062                 return []
00063             for [tag,ismajor,description] in updatetags:
00064                 if ismajor=='1':
00065                     print '  major update, tag ',tag+' , '+description
00066                 else:
00067                     print '  minor update, tag ',tag+' , '+description
00068         return updatetags
00069         
00070 if __name__=='__main__':
00071     scriptname='lumiCalc2.py'
00072     cmsswWorkingBase=os.environ['CMSSW_BASE']    
00073     c=checkforupdate()
00074     workingversion=c.runningVersion(cmsswWorkingBase,scriptname)
00075     #c.checkforupdate('V03-03-07')
00076     c.checkforupdate(workingversion)
00077    
00078