Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:29

0001 import os
0002 import re
0003 
0004 def cmsswRelease():
0005     #return os.environ['CMSSW_BASE'].split('/')[-1]
0006     #this also works when the CMSSW directory is renamed
0007     return os.environ['CMSSW_VERSION']
0008 
0009 def cmsswIs44X():
0010     return cmsswRelease().find('CMSSW_4_4_') != -1
0011 
0012 def cmsswIs52X():
0013     if cmsswRelease().find('CMSSW_5_2_') != -1 or \
0014             cmsswRelease().find('CMSSW_5_3_') != -1:
0015         return True
0016     else:
0017         return False
0018 
0019 def releaseNumber(release = None):
0020     # first check if this is an integration build
0021     if release is None:
0022         release = cmsswRelease()
0023     ibrel = re.compile('^CMSSW_(\d+)_(\d+)_X.*$')
0024     m = ibrel.match(release)
0025     if m:
0026         big = int(m.group(1))
0027         medium = int(m.group(2))
0028         return big, medium
0029     rerel = re.compile('^CMSSW_(\d+)_(\d+)_(\d+)(_\S+)*$')
0030     m = rerel.match(release)
0031     if m is None:
0032         raise ValueError('malformed release string '+release)
0033     big = int(m.group(1))
0034     medium = int(m.group(2))
0035     small = int(m.group(3))
0036     if m.group(4): # that's either a patch or prerelease
0037         prel = re.compile('_pre(\d+)')
0038         patch = re.compile('_patch(\d+)')
0039         pm = prel.match(m.group(4))
0040         if pm: # prerelease
0041             pre = int(pm.group(1))
0042             return big, medium, small, pre
0043         else: # patch
0044             pm2 = patch.match(m.group(4))
0045             if pm2:
0046                 pat = int(pm2.group(1))
0047                 return big, medium, small, pat
0048             else:
0049                 raise ValueError('patch or prerelease string malformed '+m.group(4))
0050     else:
0051         return big, medium, small
0052 
0053 def isNewerThan(release1, release2=None):
0054     """Checks the orders of two releases. If release2 is not set, it is taken as the current release"""
0055     return releaseNumber(release2) >= releaseNumber(release1)
0056 
0057 
0058 if __name__ == '__main__':
0059 
0060     import unittest
0061     
0062     class CMSSWReleaseTest(unittest.TestCase):
0063         def test_cmsswRelease(self):
0064             rel = cmsswRelease()
0065             self.assertTrue(rel.startswith('CMSSW_'))
0066         def test_releaseNumber(self):
0067             out = releaseNumber('CMSSW_7_2_1')
0068             self.assertEqual(out, (7,2,1))
0069             out = releaseNumber('CMSSW_10_2_1_patch4')
0070             self.assertEqual(out, (10,2,1,4))
0071             out = releaseNumber('CMSSW_7_3_X_2014-10-30-0200')
0072             self.assertEqual(out, (7,3))
0073             out = releaseNumber('CMSSW_7_3_0_pre2')
0074             self.assertEqual(out, (7,3,0,2))
0075             self.assertRaises(ValueError, releaseNumber, 'foobar')
0076             self.assertRaises(ValueError, releaseNumber, 'CMSSW_1_2_3_xat3')
0077             self.assertRaises(ValueError, releaseNumber, 'CMSSW_1_2_a')
0078         def test_isNewerThan(self): 
0079             self.assertTrue( isNewerThan('CMSSW_5_3_1','CMSSW_7_1_0') )
0080             self.assertTrue( isNewerThan('CMSSW_5_3_1','CMSSW_5_3_1_patch1') )
0081             self.assertTrue( isNewerThan('CMSSW_5_3_1','CMSSW_5_3_1_pre1') )
0082             self.assertTrue( isNewerThan('CMSSW_5_3_1_pre1','CMSSW_5_3_1_pre2') )
0083 
0084             
0085 
0086     unittest.main()