git-cola 1.7.3
[git-cola.git] / cola / version.py
blobdf496cf11de1c243795230775364c4ea8cb03528
1 # Copyright (c) 2012 David Aguilar
2 """Provide cola's version number"""
4 # The current git-cola version
5 _default_version = '1.7.3'
8 import os
9 import sys
11 if __name__ == '__main__':
12 srcdir = os.path.dirname(os.path.dirname(__file__))
13 sys.path.insert(1, srcdir)
15 from cola.git import git
16 from cola.decorators import memoize
18 # minimum version requirements
19 _versions = {
20 # git-diff learned --patience in 1.6.2
21 # git-mergetool learned --no-prompt in 1.6.2
22 # git-difftool moved out of contrib in git 1.6.3
23 'git': '1.6.3',
24 'python': '2.4',
25 'pyqt': '4.4',
26 'pyqt_qrunnable': '4.4',
27 'diff-submodule': '1.6.6',
31 def get(key):
32 """Returns an entry from the known versions table"""
33 return _versions.get(key)
36 def version():
37 """Returns the current version"""
38 return _default_version
41 @memoize
42 def check_version(min_ver, ver):
43 """Check whether ver is greater or equal to min_ver
44 """
45 min_ver_list = version_to_list(min_ver)
46 ver_list = version_to_list(ver)
47 return min_ver_list <= ver_list
50 @memoize
51 def check(key, ver):
52 """Checks if a version is greater than the known version for <what>"""
53 return check_version(get(key), ver)
56 def version_to_list(version):
57 """Convert a version string to a list of numbers or strings
58 """
59 ver_list = []
60 for p in version.split('.'):
61 try:
62 n = int(p)
63 except ValueError:
64 n = p
65 ver_list.append(n)
66 return ver_list
69 @memoize
70 def git_version_str():
71 """Returns the current GIT version"""
72 return git.version()
74 @memoize
75 def git_version():
76 """Returns the current GIT version"""
77 return git_version_str().split()[-1]
80 if __name__ == '__main__':
81 print(version())