/
setup.py
180 lines (127 loc) · 4.52 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
from setuptools import setup, find_packages
from distutils.command.build import build
from setuptools.command.egg_info import egg_info
import glob
import os
import sys
SRC_PATH = os.path.relpath(os.path.join(os.path.dirname(__file__), "src"))
ABS_SRC_PATH = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "src"))
sys.path.append(SRC_PATH)
from mousetrap import __version__
PYTHON_VERSION = sys.version_info
LOCALE_PATH = "src/mousetrap/locale"
all_requirements = [
"pygobject",
"pyyaml",
]
python2_requirements = all_requirements + [
"python-xlib",
]
python3_requirements = all_requirements + [
"python3-xlib",
]
if PYTHON_VERSION[0] > 2:
requirements = python3_requirements
else:
requirements = python2_requirements
class EggInfoCommand(egg_info):
def run(self):
try:
import gi.repository
except ImportError:
sys.stderr.write(
"""
PyGObject does not appear to be installed. This cannot be installed
automatically and must be installed to the system using your package manager.
On apt-based systems:
sudo apt-get install python-gobject
On yum-based systems:
sudo yum install python-gobject
The installation not work as expected without this dependency.
""")
try:
import Xlib
except ImportError:
# Python3-xlib can be installed automatically
if PYTHON_VERSION[0] < 3:
sys.stderr.write(
"""
Python Xlib does not appear to be installed. This cannot be installed
automatically and must be installed to the system using your package manager.
On apt-based systems:
sudo apt-get install python-xlib
On yum-based systems:
sudo yum install python-xlib
The installation not work as expected without this dependency.
""")
try:
import cv2
except ImportError:
sys.stderr.write(
"""
OpenCV does not appear to be installed. This cannot be installed
automatically and must be installed to the system using your package manager.
On apt-based systems:
sudo apt-get install python-opencv
On yum-based systems:
sudo yum install python-opencv
The installation not work as expected without this dependency.
""")
if "build" in self.distribution.command_obj:
build_command = self.distribution.command_obj["build"]
self.egg_base = build_command.build_base
self.egg_info = os.path.join(self.egg_base, os.path.basename(self.egg_info))
egg_info.run(self)
class BuildCommand(build):
def run(self):
from subprocess import Popen
sys.stdout.write("Compiling locale files...\n")
program = "msgfmt"
LOCALE_PATH = "%s/mousetrap/locale" % SRC_PATH
DEST_PATH = "%s/mousetrap/locale" % self.build_lib
root, directories, files = os.walk(LOCALE_PATH).next()
language_codes = directories
for language_code in language_codes:
message_file = os.path.join(LOCALE_PATH, language_code, "LC_MESSAGES", "mousetrap.po")
compiled_file = os.path.join(DEST_PATH, language_code, "LC_MESSAGES", "mousetrap.mo")
if not os.path.exists(os.path.dirname(compiled_file)):
sys.stdout.write("Creating %s\n" % os.path.dirname(compiled_file))
os.makedirs(os.path.dirname(compiled_file))
arguments = [message_file, "--output-file", compiled_file]
sys.stdout.write("Compiling %s locale" % language_code)
command = [program] + arguments
process = Popen(command)
output, errors = process.communicate()
status_code = process.returncode
if status_code == 0:
sys.stdout.write(" [OK]\n")
else:
sys.stdout.write(" [FAIL]\n")
build.run(self)
setup(
name="mousetrap",
version=__version__,
url="https://wiki.gnome.org/Projects/MouseTrap",
license="GPL",
include_package_data=True,
install_requires=requirements,
packages=find_packages(SRC_PATH),
cmdclass={
"build": BuildCommand,
"egg_info": EggInfoCommand,
},
package_dir={
"": SRC_PATH,
},
entry_points={
"console_scripts": [
"mousetrap = mousetrap.main:main",
],
},
classifiers=[
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
],
)