qtutils: avoid None in add_items()
[git-cola.git] / cola / version.py
blob75e6e81be152d60498420e9e69eb22439a52099d
1 # Copyright (c) David Aguilar
2 """Provide git-cola's version number"""
3 from __future__ import division, absolute_import, unicode_literals
5 import os
6 import sys
8 if __name__ == '__main__':
9 srcdir = os.path.dirname(os.path.dirname(__file__))
10 sys.path.insert(1, srcdir)
12 from cola.git import git
13 from cola.git import STDOUT
14 from cola.decorators import memoize
15 from cola._version import VERSION
17 # minimum version requirements
18 _versions = {
19 # git-diff learned --patience in 1.6.2
20 # git-mergetool learned --no-prompt in 1.6.2
21 # git-difftool moved out of contrib in git 1.6.3
22 'git': '1.6.3',
23 'python': '2.6',
24 'pyqt': '4.4',
25 'pyqt_qrunnable': '4.4',
26 'diff-submodule': '1.6.6',
30 def get(key):
31 """Returns an entry from the known versions table"""
32 return _versions.get(key)
35 def version():
36 """Returns the current version"""
37 return VERSION
40 @memoize
41 def check_version(min_ver, ver):
42 """Check whether ver is greater or equal to min_ver
43 """
44 min_ver_list = version_to_list(min_ver)
45 ver_list = version_to_list(ver)
46 return min_ver_list <= ver_list
49 @memoize
50 def check(key, ver):
51 """Checks if a version is greater than the known version for <what>"""
52 return check_version(get(key), ver)
55 def version_to_list(version):
56 """Convert a version string to a list of numbers or strings
57 """
58 ver_list = []
59 for p in version.split('.'):
60 try:
61 n = int(p)
62 except ValueError:
63 n = p
64 ver_list.append(n)
65 return ver_list
68 @memoize
69 def git_version_str():
70 """Returns the current GIT version"""
71 return git.version()[STDOUT].strip()
73 @memoize
74 def git_version():
75 """Returns the current GIT version"""
76 parts = git_version_str().split()
77 if parts and len(parts) >= 3:
78 return parts[2]
79 else:
80 # minimum supported version
81 return '1.6.3'
84 def print_version(brief=False):
85 if brief:
86 print('%s' % version())
87 else:
88 print('cola version %s' % version())
91 if __name__ == '__main__':
92 print(version())