-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.py
executable file
·240 lines (201 loc) · 9.21 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#! /usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2009-2011 Frédéric Bertolus.
# Copyright (C) 2009-2011 Matthieu Bizien.
#
# This file is part of Perroquet.
#
# Perroquet is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Perroquet is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Perroquet. If not, see <http://www.gnu.org/licenses/>.
import glob
import os
import platform
import subprocess
import sys
from distutils.cmd import Command
from distutils.command.build import build
from distutils.command.install_data import install_data
from distutils.core import setup
from distutils.dep_util import newer
from distutils.dist import Distribution
from distutils.errors import DistutilsFileError
from distutils.log import error, info, warn
from perroquetlib.config import config
PO_DIR = 'po'
MO_DIR = os.path.join('build', 'mo')
class PerroquetDist(Distribution):
global_options = Distribution.global_options + [
("without-gettext", None, "Don't build/install gettext .mo files"),
("without-icon-cache", None, "Don't attempt to run gtk-update-icon-cache"),
("without-mime-database", None, "Don't attempt to run update-mime-database"),
("without-desktop-database", None, "Don't attempt to run update-desktop-database")]
def __init__ (self, * args):
self.without_gettext = False
self.without_icon_cache = False
self.without_mime_database = False
self.without_desktop_database = False
Distribution.__init__(self, * args)
class BuildData(build):
def run (self):
build.run (self)
if self.distribution.without_gettext:
return
for po in glob.glob (os.path.join (PO_DIR, '*.po')):
lang = os.path.basename(po[:-3])
mo = os.path.join(MO_DIR, lang, 'LC_MESSAGES/perroquet.mo')
directory = os.path.dirname(mo)
if not os.path.exists(directory):
info('creating %s' % directory)
os.makedirs(directory)
if newer(po, mo):
info('compiling %s -> %s' % (po, mo))
try:
rc = subprocess.call(['msgfmt', '-o', mo, po])
if rc != 0:
raise Warning, "msgfmt returned %d" % rc
except Exception, e:
error("Building gettext files failed. Try setup.py --without-gettext [build|install]")
error("Error: %s" % str(e))
sys.exit(1)
TOP_BUILDDIR = '.'
INTLTOOL_MERGE = 'intltool-merge'
desktop_in = 'data/perroquet.desktop.in'
desktop_data = 'data/perroquet.desktop'
os.system ("C_ALL=C " + INTLTOOL_MERGE + " -d -u -c " + TOP_BUILDDIR +
"/po/.intltool-merge-cache " + TOP_BUILDDIR + "/po " +
desktop_in + " " + desktop_data)
class Uninstall(Command):
description = "Attempt an uninstall from an install --record file"
user_options = [('manifest=', None, 'Installation record filename')]
def initialize_options(self):
self.manifest = None
def finalize_options(self):
pass
def get_command_name(self):
return 'uninstall'
def run(self):
self.ensure_filename('manifest')
try:
try:
f = open(self.manifest)
files = [file.strip() for file in f]
except IOError, e:
raise DistutilsFileError("unable to open install manifest: %s", str(e))
finally:
f.close()
for file in files:
if os.path.isfile(file) or os.path.islink(file):
info("removing %s" % repr(file))
if not self.dry_run:
try:
os.unlink(file)
except OSError, e:
warn("could not delete: %s" % repr(file))
elif not os.path.isdir(file):
info("skipping %s" % repr(file))
dirs = set()
for file in reversed(sorted(files)):
dir = os.path.dirname(file)
if dir not in dirs and os.path.isdir(dir) and len(os.listdir(dir)) == 0:
dirs.add(dir)
# Only nuke empty Python library directories, else we could destroy
# e.g. locale directories we're the only app with a .mo installed for.
if dir.find("site-packages/") > 0:
info("removing %s" % repr(dir))
if not self.dry_run:
try:
os.rmdir(dir)
except OSError, e:
warn("could not remove directory: %s" % str(e))
else:
info("skipping empty directory %s" % repr(dir))
class InstallData(install_data):
def run (self):
self.data_files.extend (self._find_mo_files ())
install_data.run (self)
if not self.distribution.without_icon_cache:
self._update_icon_cache ()
if not self.distribution.without_mime_database:
self._update_mime_database()
if not self.distribution.without_desktop_database:
self._update_desktop_database()
# We should do this on uninstall too
def _update_icon_cache(self):
info("running gtk-update-icon-cache")
try:
subprocess.call(["gtk-update-icon-cache", "-q", "-f", "-t", os.path.join(self.install_dir, "share/icons/hicolor")])
except Exception, e:
warn("updating the GTK icon cache failed: %s" % str(e))
def _update_mime_database(self):
info("running update-mime-database")
try:
subprocess.call(["update-mime-database", os.path.join(self.install_dir, "share/mime")])
except Exception, e:
warn("updating mime database failed: %s" % str(e))
def _update_desktop_database(self):
info("running update-desktop-database")
try:
subprocess.call(["update-desktop-database",])
except Exception, e:
warn("updating desktop database failed: %s" % str(e))
def _find_mo_files (self):
data_files = []
if not self.distribution.without_gettext:
for mo in glob.glob (os.path.join (MO_DIR, '*', 'LC_MESSAGES/perroquet.mo')):
lang = os.path.basename(os.path.dirname(os.path.dirname(mo)))
dest = os.path.join('share', 'locale', lang, 'LC_MESSAGES')
data_files.append((dest, [mo]))
return data_files
if platform.system() == 'FreeBSD':
man_dir = 'man'
else:
man_dir = 'share/man'
setup(name='perroquet',
version=config.get("version"),
description='Perroquet, listening comprehension tutor ',
author='Frédéric Bertolus',
author_email='[email protected]',
url='http://perroquet.niavok.com',
license='GNU GPL v3',
scripts=['perroquet'],
data_files=[
('share/applications', ['data/perroquet.desktop']),
('share/mime/packages', ['data/perroquet.xml']),
('share/pixmaps', ['data/icons/48x48/apps/perroquet.png']),
('share/icons/hicolor/scalable/apps', glob.glob('data/icons/scalable/apps/*.svg')),
('share/icons/hicolor/16x16/apps', glob.glob('data/icons/16x16/apps/*.png')),
('share/icons/hicolor/22x22/apps', glob.glob('data/icons/22x22/apps/*.png')),
('share/icons/hicolor/24x24/apps', glob.glob('data/icons/24x24/apps/*.png')),
('share/icons/hicolor/32x32/apps', glob.glob('data/icons/32x32/apps/*.png')),
('share/icons/hicolor/48x48/apps', glob.glob('data/icons/48x48/apps/*.png')),
('share/icons/hicolor/256x256/apps', glob.glob('data/icons/256x256/apps/*.png')),
('share/icons/hicolor/scalable/mimetypes', glob.glob('data/icons/scalable/mimetypes/*.svg')),
('share/perroquet/', ['data/gui_message_dialog.ui']),
('share/perroquet/', ['data/reset.ui']),
('share/perroquet/', ['data/perroquet.ui']),
('share/perroquet/', ['data/properties.ui']),
('share/perroquet/', ['data/settings.ui']),
('share/perroquet/', ['data/exercise_manager.ui']),
('share/perroquet/', ['data/gui_password_dialog.ui']),
('share/perroquet/', ['data/properties_advanced.ui']),
('share/perroquet/', ['data/audio_icon.png']),
('share/perroquet/', ['data/perroquet.png']),
('share/perroquet/', ['data/languages.list']),
('/etc/perroquet/', ['data/config.ini']),
('/etc/perroquet/', ['data/languages_aliases.ini']),
('/etc/perroquet/', ['data/sources.conf']),
],
packages=['perroquetlib', 'perroquetlib.config', 'perroquetlib.gui', 'perroquetlib.model', 'perroquetlib.model.exercise_parser', 'perroquetlib.model.sequence', 'perroquetlib.repository'],
cmdclass={'build': BuildData, 'install_data': InstallData, 'uninstall': Uninstall},
distclass=PerroquetDist
)