git: rework work_tree / git_dir initialization
[git-cola.git] / setup.py
blob1087f481045641817e1bfc3cd6c579a7f1aa41b6
1 #!/usr/bin/env python
2 import re
3 import os
4 import sys
5 import stat
6 from glob import glob
8 from distutils.core import setup
9 from distutils.command import build_scripts
10 build_scripts.first_line_re = re.compile('^should not match$')
12 from cola import version
13 from cola import utils
15 def main():
16 # ensure readable files
17 old_mask = os.umask(0022)
18 if sys.argv[1] in ['install', 'build']:
19 __check_python_version()
20 __check_git_version()
21 __check_pyqt_version()
22 __build_views() # pyuic4: .ui -> .py
23 __build_translations() # msgfmt: .po -> .qm
24 try:
25 version.write_builtin_version()
26 __run_setup()
27 finally:
28 version.delete_builtin_version()
29 # restore the old mask
30 os.umask(old_mask)
32 def __run_setup():
33 setup(name = 'cola',
34 version = version.version,
35 license = 'GPLv2',
36 author = 'David Aguilar',
37 author_email = 'davvid@gmail.com',
38 url = 'http://cola.tuxfamily.org/',
39 description = 'GIT Cola',
40 long_description = 'A highly caffeinated GIT GUI',
41 scripts = ['bin/git-cola', 'bin/git-difftool'],
42 packages = ['cola', 'cola.gui', 'cola.views', 'cola.controllers'],
43 data_files = [
44 __app_path('share/cola/qm', '*.qm'),
45 __app_path('share/cola/icons', '*.png'),
46 __app_path('share/cola/styles', '*.qss'),
47 __app_path('share/cola/styles/images', '*.png'),
48 __app_path('share/applications', '*.desktop'),
49 __app_path('share/doc/cola', '*.txt'),
52 def __app_path(dirname, entry):
53 if '/' in entry:
54 return (dirname, glob(entry))
55 else:
56 return (dirname, glob(os.path.join(dirname, entry)))
58 def __version_to_list(version):
59 """Convert a version string to a list of numbers or strings
60 """
61 ver_list = []
62 for p in version.split('.'):
63 try:
64 n = int(p)
65 except ValueError:
66 n = p
67 ver_list.append(n)
68 return ver_list
70 def __check_min_version(min_ver, ver):
71 """Check whether ver is greater or equal to min_ver
72 """
73 min_ver_list = __version_to_list(min_ver)
74 ver_list = __version_to_list(ver)
75 return min_ver_list <= ver_list
77 def __check_python_version():
78 """Check the minimum Python version
79 """
80 pyver = '.'.join(map(lambda x: str(x), sys.version_info))
81 if not __check_min_version(version.python_min_ver, pyver):
82 print >> sys.stderr, 'Python version %s or newer required. Found %s' \
83 % (version.python_min_ver, pyver)
84 sys.exit(1)
86 def __check_git_version():
87 """Check the minimum GIT version
88 """
89 gitver = utils.run_cmd('git', '--version').split()[2]
90 if not __check_min_version(version.git_min_ver, gitver):
91 print >> sys.stderr, 'GIT version %s or newer required. Found %s' \
92 % (version.git_min_ver, gitver)
93 sys.exit(1)
95 def __check_pyqt_version():
96 """Check the minimum PYQT version
97 """
98 pyqtver = utils.run_cmd('pyuic4', '--version').split()[-1]
99 if not __check_min_version(version.pyqt_min_ver, pyqtver):
100 print >> sys.stderr, 'PYQT version %s or newer required. Found %s' \
101 % (version.pyqt_min_ver, pyqtver)
102 sys.exit(1)
104 def __dirty(src, dst):
105 if not os.path.exists(dst):
106 return True
107 srcstat = os.stat(src)
108 dststat = os.stat(dst)
109 return srcstat[stat.ST_MTIME] > dststat[stat.ST_MTIME]
111 def __build_views():
112 print 'running build_views'
113 views = os.path.join('cola', 'gui')
114 sources = glob('ui/*.ui')
115 for src in sources:
116 dst = os.path.join(views, os.path.basename(src)[:-3] + '.py')
117 if __dirty(src, dst):
118 print '\tpyuic4 -x %s -o %s' % (src, dst)
119 utils.run_cmd('pyuic4', '-x', src, '-o', dst)
121 def __build_translations():
122 print 'running build_translations'
123 sources = glob('share/cola/po/*.po')
124 for src in sources:
125 dst = os.path.join('share', 'cola', 'qm',
126 os.path.basename(src)[:-3] + '.qm')
127 if __dirty(src, dst):
128 print '\tmsgfmt --qt %s -o %s' % (src, dst)
129 utils.run_cmd('msgfmt', '--qt', src, '-o', dst)
131 main()