forked from rabbitvcs/rabbitvcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
168 lines (142 loc) · 5.6 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
#!/usr/bin/env python
# If you didn't know already, this is a Python distutils setup script. It borrows
# heavily from Phatch's (see: http://photobatch.stani.be/).
#
# There's a lot of comments here (on purpose) so people can actually learn from
# this and don't have to figure out everything on their own.
#
# This setup script is used to build distribution specific packages.
#
# For more information see: http://docs.python.org/dist/dist.html
#
# TODO: this all feels just a little too shell scripty, refactoring it later
# might be a good idea.
# NOTES:
# System-wide directories:
# Scalable emblems go in: /usr/share/icons/hicolor/scalable/emblems
#
# User-specific directories:
# Scalable emblems go in: ~/.icons/hicolor/scalable
#
# Common directories
# See: http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
# Configuration information goes in: ~/.config/rabbitvcs/
# Data goes in: ~/.local/share/rabbitvcs
import sys
import os
import os.path
import subprocess
from distutils.core import setup
import distutils.sysconfig
PREFIX = sys.prefix
# If the user passed --prefix=... then use the new prefix
for c in sys.argv:
if c.startswith("--prefix"):
PREFIX = c.split("=")[1].lstrip().rstrip()
#==============================================================================
# Variables
#==============================================================================
# Some descriptive variables
# This will eventually be passed to the setup function, but we already need them
# for doing some other stuff so we have to declare them here.
name = "rabbitvcs"
version = "0.16.0"
description = "Easy version control"
long_description = """RabbitVCS is a set of graphical tools written to provide simple and straightforward access to the version control systems you use."""
author = "Bruce van der Kooij"
author_email = "[email protected]"
url = "http://www.rabbitvcs.org"
license = "GNU General Public License version 2 or later"
#==============================================================================
# Paths
#==============================================================================
icon_theme_directory = "share/icons/hicolor"
locale_directory = "share/locale"
#==============================================================================
# Helper functions
#==============================================================================
def include_by_pattern(directory, directory_to_install, pattern):
files_to_include = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(pattern):
files_to_include.append((
root.replace(directory, directory_to_install),
[os.path.join(root, file)]
))
return files_to_include
#==============================================================================
# Gather all the files that need to be included
#==============================================================================
# Packages
packages = []
for root, dirs, files in os.walk("rabbitvcs"):
if "__init__.py" in files:
packages.append(root.replace(os.path.sep, "."))
# Translation
translations = include_by_pattern("locale", locale_directory, ".mo")
# Icons
icons = include_by_pattern("data/icons/hicolor", icon_theme_directory, ".svg")
icons += include_by_pattern("data/icons/hicolor", icon_theme_directory, ".png")
# Config parsing specification
config_spec = [(
"share/rabbitvcs",
["rabbitvcs/util/configspec/configspec.ini"]
)]
# Documentation
documentation = [("share/doc/rabbitvcs", [
"AUTHORS",
"MAINTAINERS"
])]
# Save build information so we can access the prefix later
path = "rabbitvcs/buildinfo.py"
buildinfo = '''rabbitvcs_prefix = "%s"
icon_path = "%s/%s"
''' % (PREFIX, PREFIX, icon_theme_directory)
fh = open(path, "w")
fh.write(buildinfo)
fh.close()
#==============================================================================
# Ready to install
#==============================================================================
# Calling the setup function will actually install RabbitVCS and also creates
# an .egg-info file in /usr/lib/python<version>/site-packages/ or
# /usr/share/python-support/rabbitvcs when generating a Debian package.
dist = setup(
# The following arguments will be included in the .egg.info file,
# for a list of available arguments and their descriptions see:
# - http://docs.python.org/dist/module-distutils.core.html
name=name,
version=version,
description=description,
long_description=long_description,
author=author,
author_email=author_email,
url=url,
license=license,
# There are actually several arguments that are used to install files:
# - py_modules: installs specific modules to site-packages
# - packages: install complete packages (directories with an __init__.py
# file) into site-packages
# - data_files: any file you want, anywhere you want it
packages=packages,
package_data={
"rabbitvcs": [
# Include our GtkBuilder UI files right into the package
"ui/xml/*.xml",
"ui/xml/dialogs/*.xml"
]
},
data_files=translations + icons + documentation + config_spec
)
#
# Post installation
#
# Make sure the icon cache is deleted and recreated
if sys.argv[1] == "install":
if os.uname()[0] != 'Darwin':
print "Running gtk-update-icon-cache-3.0"
subprocess.Popen(
["gtk-update-icon-cache-3.0", icon_theme_directory],
stdout=subprocess.PIPE
).communicate()[0]