Package bmrblib :: Module version
[hide private]
[frames] | no frames]

Source Code for Module bmrblib.version

 1  ############################################################################# 
 2  #                                                                           # 
 3  # The BMRB library.                                                         # 
 4  #                                                                           # 
 5  # Copyright (C) 2008-2011 Edward d'Auvergne                                 # 
 6  #                                                                           # 
 7  # This program is free software: you can redistribute it and/or modify      # 
 8  # it under the terms of the GNU General Public License as published by      # 
 9  # the Free Software Foundation, either version 3 of the License, or         # 
10  # (at your option) any later version.                                       # 
11  #                                                                           # 
12  # This program is distributed in the hope that it will be useful,           # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of            # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             # 
15  # GNU General Public License for more details.                              # 
16  #                                                                           # 
17  # You should have received a copy of the GNU General Public License         # 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.     # 
19  #                                                                           # 
20  ############################################################################# 
21   
22  # Module docstring. 
23  """The NMR-STAR version singleton object.""" 
24   
25  # Python module imports. 
26  from re import search 
27   
28   
29 -class Star_version(object):
30 """A singleton for storing the NMR-STAR version information.""" 31 32 # Class variable for storing the class instance. 33 instance = None 34
35 - def __new__(self, *args, **kargs):
36 """Replacement function for implementing the singleton design pattern.""" 37 38 # First initialisation. 39 if self.instance is None: 40 self.instance = object.__new__(self, *args, **kargs) 41 42 # Already initialised, so return the instance. 43 return self.instance
44 45
46 - def set_version(self, version):
47 """Set the version number and extract the major, minor and revision numbers. 48 49 @param version: The NMR-STAR version number. 50 @type version: str 51 """ 52 53 # Store the number. 54 self.version = version 55 56 # Determine the major, minor, and revision numbers. 57 self.parse_version()
58 59
60 - def parse_version(self):
61 """Convert the version number string into the major, minor, and revision numbers.""" 62 63 # Initialise. 64 self.major = None 65 self.minor = None 66 self.revision = None 67 self.sub_revision = None 68 69 # Split up the number. 70 nums = self.version.split('.') 71 72 # Catch development versions. 73 if search('^Dev', self.version) or search('^dev', self.version): 74 # Assume a version 2.1 file. 75 self.major = 2 76 self.minor = 1 77 78 # Quit. 79 return 80 81 # A production tag is in the version string. 82 if nums[0] == 'production': 83 nums.pop(0) 84 85 # The major and minor numbers. 86 self.major = int(nums[0]) 87 self.minor = int(nums[1]) 88 89 # The revision number. 90 if len(nums) > 2: 91 self.revision = int(nums[2]) 92 93 # The sub-revision number. 94 if len(nums) > 3: 95 self.sub_revision = int(nums[3])
96