chiark / gitweb /
stgit.el: Add "d" for a few diff commands, similar to git.el
[stgit] / setup.py
1 #!/usr/bin/env python
2
3 import sys, glob, os
4 from distutils.core import setup
5
6 from stgit import version
7
8 def __version_to_list(version):
9     """Convert a version string to a list of numbers or strings
10     """
11     ver_list = []
12     for p in version.split('.'):
13         try:
14             n = int(p)
15         except ValueError:
16             n = p
17         ver_list.append(n)
18     return ver_list
19
20 def __check_min_version(min_ver, ver):
21     """Check whether ver is greater or equal to min_ver
22     """
23     min_ver_list = __version_to_list(min_ver)
24     ver_list = __version_to_list(ver)
25     return min_ver_list <= ver_list
26
27 def __check_python_version():
28     """Check the minimum Python version
29     """
30     pyver = '.'.join(map(lambda x: str(x), sys.version_info))
31     if not __check_min_version(version.python_min_ver, pyver):
32         print >> sys.stderr, 'Python version %s or newer required. Found %s' \
33               % (version.python_min_ver, pyver)
34         sys.exit(1)
35
36 def __check_git_version():
37     """Check the minimum GIT version
38     """
39     from stgit.run import Run
40     gitver = Run('git', '--version').output_one_line().split()[2]
41     if not __check_min_version(version.git_min_ver, gitver):
42         print >> sys.stderr, 'GIT version %s or newer required. Found %s' \
43               % (version.git_min_ver, gitver)
44         sys.exit(1)
45
46 def __run_setup():
47     setup(name = 'stgit',
48           version = version.version,
49           license = 'GPLv2',
50           author = 'Catalin Marinas',
51           author_email = 'catalin.marinas@gmail.com',
52           url = 'http://www.procode.org/stgit/',
53           description = 'Stacked GIT',
54           long_description = 'Push/pop utility on top of GIT',
55           scripts = ['stg'],
56           packages = ['stgit', 'stgit.commands', 'stgit.lib'],
57           data_files = [
58             ('share/stgit/templates', glob.glob('templates/*.tmpl')),
59             ('share/stgit/examples', glob.glob('examples/*.tmpl')),
60             ('share/stgit/examples', ['examples/gitconfig']),
61             ('share/stgit/contrib', ['contrib/stgbashprompt.sh']),
62             ('share/stgit/completion', ['stgit-completion.bash'])
63             ])
64
65 # Check the minimum versions required
66 if sys.argv[1] in ['install', 'build']:
67     __check_python_version()
68     __check_git_version()
69
70 # ensure readable template files
71 old_mask = os.umask(0022)
72
73 try:
74     version.write_builtin_version()
75     __run_setup()
76 finally:
77     version.delete_builtin_version()
78
79 # restore the old mask
80 os.umask(old_mask)