Revision 1b45f4e5 lib/constants.py

b/lib/constants.py
29 29
OS_API_VERSION = 5
30 30
EXPORT_VERSION = 0
31 31

  
32

  
32 33
# Format for CONFIG_VERSION:
33 34
#   01 03 0123 = 01030123
34 35
#   ^^ ^^ ^^^^
......
37 38
#   + Major version
38 39
#
39 40
# It stored as an integer. Make sure not to write an octal number.
40
#
41

  
42
# BuildVersion and SplitVersion must be in here because we can't import other
43
# modules. The cfgupgrade tool must be able to read and write version numbers
44
# and thus requires these functions. To avoid code duplication, they're kept in
45
# here.
46

  
47
def BuildVersion(major, minor, revision):
48
  """Calculates int version number from major, minor and revision numbers.
49

  
50
  Returns: int representing version number
51

  
52
  """
53
  assert isinstance(major, int)
54
  assert isinstance(minor, int)
55
  assert isinstance(revision, int)
56
  return (1000000 * major +
57
            10000 * minor +
58
                1 * revision)
59

  
60

  
61
def SplitVersion(version):
62
  """Splits version number stored in an int.
63

  
64
  Returns: tuple; (major, minor, revision)
65

  
66
  """
67
  assert isinstance(version, int)
68

  
69
  (major, remainder) = divmod(version, 1000000)
70
  (minor, revision) = divmod(remainder, 10000)
71

  
72
  return (major, minor, revision)
73

  
74

  
41 75
CONFIG_MAJOR = int(_autoconf.VERSION_MAJOR)
42 76
CONFIG_MINOR = int(_autoconf.VERSION_MINOR)
43 77
CONFIG_REVISION = 0
44
CONFIG_VERSION = (
45
  1000000 * CONFIG_MAJOR +
46
    10000 * CONFIG_MINOR +
47
        1 * CONFIG_REVISION)
78
CONFIG_VERSION = BuildVersion(CONFIG_MAJOR, CONFIG_MINOR, CONFIG_REVISION)
48 79

  
49 80
# file paths
50 81
DATA_DIR = _autoconf.LOCALSTATEDIR + "/lib/ganeti"

Also available in: Unified diff