Revision effc1b86 lib/constants.py

b/lib/constants.py
44 44
EXPORT_VERSION = 0
45 45
RAPI_VERSION = 2
46 46

  
47

  
48
# Format for CONFIG_VERSION:
49
#   01 03 0123 = 01030123
50
#   ^^ ^^ ^^^^
51
#   |  |  + Configuration version/revision
52
#   |  + Minor version
53
#   + Major version
54
#
55
# It is stored as an integer. Make sure not to write an octal number.
56

  
57
# BuildVersion and SplitVersion must be in here because we can't import other
58
# modules. The cfgupgrade tool must be able to read and write version numbers
59
# and thus requires these functions. To avoid code duplication, they're kept in
60
# here.
61

  
62
def BuildVersion(major, minor, revision):
63
  """Calculates int version number from major, minor and revision numbers.
64

  
65
  Returns: int representing version number
66

  
67
  """
68
  assert isinstance(major, int)
69
  assert isinstance(minor, int)
70
  assert isinstance(revision, int)
71
  return (1000000 * major +
72
            10000 * minor +
73
                1 * revision)
74

  
75

  
76
def SplitVersion(version):
77
  """Splits version number stored in an int.
78

  
79
  Returns: tuple; (major, minor, revision)
80

  
81
  """
82
  assert isinstance(version, int)
83

  
84
  (major, remainder) = divmod(version, 1000000)
85
  (minor, revision) = divmod(remainder, 10000)
86

  
87
  return (major, minor, revision)
88

  
89

  
90 47
CONFIG_MAJOR = _constants.CONFIG_MAJOR
91 48
CONFIG_MINOR = _constants.CONFIG_MINOR
92 49
CONFIG_REVISION = _constants.CONFIG_REVISION

Also available in: Unified diff