forked from git-cola/git-cola
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
executable file
·188 lines (157 loc) · 5.81 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python
import re
import os
import sys
import stat
from glob import glob
from distutils.core import setup
from distutils.command import build_scripts
build_scripts.first_line_re = re.compile('^should not match$')
from cola import version
from cola import utils
from cola import resources
from cola import core
def main():
# ensure readable files
old_mask = os.umask(0022)
if sys.argv[1] in ('install', 'build'):
_setup_environment()
_check_python_version()
_check_git_version()
_check_pyqt_version()
_check_jsonpickle_version()
_build_translations() # msgfmt: .po -> .qm
# First see if there is a version file (included in release tarballs),
# then try git-describe, then default.
builtin_version = os.path.join('cola', 'builtin_version.py')
if os.path.exists('version') and not os.path.exists(builtin_version):
shutils.copy('version', builtin_version)
elif os.path.exists('.git'):
version.write_builtin_version()
_run_setup()
# restore the old mask
os.umask(old_mask)
def _setup_environment():
"""Adds win32/ to our path for windows only"""
if sys.platform != 'win32':
return
path = os.environ['PATH']
win32 = os.path.join(os.path.dirname(__file__), 'win32')
os.environ['PATH'] = win32 + os.pathsep + path
def _run_setup():
"""Runs distutils.setup()"""
scripts = ['bin/git-cola']
# git-difftool first moved out of git.git's contrib area in git 1.6.3
if (os.environ.get('INSTALL_GIT_DIFFTOOL', '') or
not version.check('difftool-builtin', version.git_version())):
scripts.append('bin/difftool/git-difftool')
scripts.append('bin/difftool/git-difftool--helper')
if sys.platform == 'win32':
scripts.append('win32/cola')
scripts.append('win32/dirname')
scripts.append('win32/py2exe-setup.py')
scripts.append('win32/py2exe-setup.cmd')
setup(name = 'git-cola',
version = version.version(),
license = 'GPLv2',
author = 'David Aguilar and contributors',
author_email = 'davvid@gmail.com',
url = 'http://cola.tuxfamily.org/',
description = 'git-cola',
long_description = 'A highly caffeinated Git GUI',
scripts = scripts,
packages = [],
data_files = cola_data_files())
def cola_data_files():
data = [_app_path('share/git-cola/qm', '*.qm'),
_app_path('share/git-cola/icons', '*.png'),
_app_path('share/git-cola/icons', '*.svg'),
_app_path('share/git-cola/styles', '*.qss'),
_app_path('share/git-cola/styles/images', '*.png'),
_app_path('share/applications', '*.desktop'),
_app_path('share/doc/git-cola', '*.txt'),
_lib_path('cola/*.py'),
_lib_path('cola/models/*.py'),
_lib_path('cola/controllers/*.py'),
_lib_path('cola/views/*.py'),
_lib_path('simplejson/*.py')]
if sys.platform == 'darwin':
data.append(_app_path('share/git-cola/bin', 'ssh-askpass-darwin'))
else:
data.append(_app_path('share/git-cola/bin', 'ssh-askpass'))
return data
def _lib_path(entry):
dirname = os.path.dirname(entry)
app_dir = os.path.join('share/git-cola/lib', dirname)
return (app_dir, glob(entry))
def _app_path(dirname, entry):
return (dirname, glob(os.path.join(dirname, entry)))
def _check_python_version():
"""Check the minimum Python version
"""
pyver = '.'.join(map(lambda x: str(x), sys.version_info))
if not version.check('python', pyver):
print >> sys.stderr, ('Python version %s or newer required. '
'Found %s' % (version.get('python'), pyver))
sys.exit(1)
def _check_git_version():
"""Check the minimum GIT version
"""
if not version.check('git', version.git_version()):
print >> sys.stderr, ('GIT version %s or newer required. '
'Found %s' % (version.get('git'),
version.git_version()))
sys.exit(1)
def _check_pyqt_version():
"""Check the minimum PyQt version
"""
has_pyqt = False
pyqtver = 'None'
try:
from PyQt4 import QtCore
pyqtver = QtCore.PYQT_VERSION_STR
if version.check('pyqt', pyqtver):
return
except ImportError:
pass
print >> sys.stderr, ('PyQt4 version %s or newer required. '
'Found %s' % (version.get('pyqt'), pyqtver))
sys.exit(1)
def _check_jsonpickle_version():
"""Check the minimum jsonpickle version
"""
jsonpicklever = 'None'
try:
import jsonpickle
jsonpicklever = jsonpickle.__version__
if version.check('jsonpickle', jsonpicklever):
return
except ImportError:
pass
print >> sys.stderr, ('jsonpickle version %s or newer required. '
'Found %s' % (version.get('jsonpickle'),
jsonpicklever))
sys.exit(1)
def _dirty(src, dst):
if not os.path.exists(dst):
return True
srcstat = os.stat(src)
dststat = os.stat(dst)
return srcstat[stat.ST_MTIME] > dststat[stat.ST_MTIME]
def _build_translations():
print 'running build_translations'
sources = glob(resources.share('po', '*.po'))
sources = glob('share/git-cola/po/*.po')
for src in sources:
dst = resources.qm(os.path.basename(src)[:-3])
if _dirty(src, dst):
print '\tmsgfmt --qt %s -o %s' % (src, dst)
utils.run_cmd(['msgfmt', '--qt', src, '-o', dst])
def _run_cmd(cmd):
"""Runs a command and returns its output."""
pipe = os.popen(cmd)
contents = core.read_nointr(pipe).strip()
pipe.close()
return contents
if __name__ == '__main__':
main()