-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
executable file
·247 lines (198 loc) · 7.95 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
241
242
243
244
245
246
247
#!/usr/bin/env python3
# Deejayd, a media player daemon
# Copyright (C) 2007-2017 Mickael Royer <[email protected]>
# Alexandre Rossi <[email protected]>
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import glob
import os
import shutil
import subprocess
from distutils.errors import DistutilsExecError
from distutils.command.build import build as distutils_build
from distutils.command.clean import clean as distutils_clean
from distutils.core import setup, Command
from distutils.dep_util import newer
from distutils.spawn import find_executable
from babel.messages import frontend as babel
import deejayd
def force_unlink(path):
try:
os.unlink(path)
except OSError:
pass
def force_rmdir(path):
try:
shutil.rmtree(path)
except OSError:
pass
def spawn(cmdargs, cwd=None):
try:
subprocess.check_call(cmdargs, cwd=cwd)
except subprocess.CalledProcessError as e:
raise DistutilsExecError(e)
class build_manpages(Command):
description = "Build deejayd man pages"
user_options = []
manpages = None
db2mans = [
# debian
"/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl",
# gentoo
"/usr/share/sgml/docbook/xsl-stylesheets/manpages/docbook.xsl",
]
mandir = "man/"
executable = find_executable('xsltproc')
def initialize_options(self):
pass
def finalize_options(self):
self.manpages = glob.glob(os.path.join(self.mandir, "*.xml"))
def __get_manpage(self, xmlmanpage):
return xmlmanpage[:-4] # remove '.xml' at the end
def run(self):
data_files = self.distribution.data_files
db2man = None
for path in self.__class__.db2mans:
if os.path.exists(path):
db2man = path
continue
for xmlmanpage in self.manpages:
manpage = self.__get_manpage(xmlmanpage)
if newer(xmlmanpage, manpage):
cmd = (self.executable, "--nonet", "-o", self.mandir, db2man,
xmlmanpage)
self.spawn(cmd)
targetpath = os.path.join("share", "man", "man%s" % manpage[-1])
data_files.append((targetpath, (manpage, ), ))
def clean(self):
for xmlmanpage in self.manpages:
force_unlink(self.__get_manpage(xmlmanpage))
class build_i18n(Command):
description = "Compile deejayd .po files"
user_options = []
po_filename = None
po_directory = None
def initialize_options(self):
pass
def finalize_options(self):
self.po_directory = "locale"
self.po_filename = "deejayd.mo"
def run(self):
data_files = self.distribution.data_files
self.run_command("compile_catalog")
for root, dirs, files in os.walk(self.po_directory):
if self.po_filename in files:
path = os.path.join(root, self.po_filename)
t_path = os.path.join("share", root)
data_files.append((t_path, (path,)))
print(data_files)
def clean(self):
for root, dirs, files in os.walk(self.po_directory):
if self.po_filename in files:
f_path = os.path.join(root, self.po_filename)
force_unlink(f_path)
class build_webui(Command):
description = "Install deejayd webui"
webui_directory = "webui"
def initialize_options(self):
self.webuidir = os.path.join(os.path.dirname(__file__),
self.webui_directory)
def finalize_options(self):
pass
def run(self):
data_files = self.distribution.data_files
for d in ('dist', 'ressources'):
dist = os.path.join('share/deejayd/htdocs/', d)
data_files.extend(get_data_files(os.path.join(self.webuidir, d),
dist))
class deejayd_build(distutils_build):
def finalize_options(self):
distutils_build.finalize_options(self)
self.sub_commands.append(("build_i18n", None))
self.sub_commands.append(("build_webui", None))
self.sub_commands.append(("build_manpages", self.__has_manpages))
def __has_manpages(self, command):
has_db2man = False
for path in build_manpages.db2mans:
if os.path.exists(path):
has_db2man = True
return "build_manpages"in self.distribution.cmdclass\
and has_db2man and build_manpages.executable is not None
def clean(self):
for subcommand_name in self.get_sub_commands():
subcommand = self.get_finalized_command(subcommand_name)
if hasattr(subcommand, 'clean'):
subcommand.clean()
class deejayd_clean(distutils_clean):
def run(self):
distutils_clean.run(self)
commands = list(self.distribution.command_obj.values())
for cmd in commands:
if hasattr(cmd, 'clean'):
cmd.clean()
force_unlink('MANIFEST')
force_rmdir('build')
#
# data files
#
def get_data_files(walking_root, dest_dir):
data_files = []
for root, dirs, files in os.walk(walking_root):
paths = [os.path.join(root, f) for f in files]
root = root.replace(walking_root, '').strip('/')
dest_path = os.path.join(dest_dir, root)
data_files.append((dest_path, paths))
return data_files
def build_data_files_list():
data = [
('share/doc/deejayd', ("doc/deejayd_rpc_protocol", )),
('share/doc/deejayd', ("README.md", "NEWS.md", )),
('share/doc/deejayd', ["scripts/deejayd_rgscan"]),
]
return data
if __name__ == "__main__":
setup( name="deejayd", version=deejayd.__version__,
url="http://mroy31.domring.net/~roy/projects/deejayd",
description="Network controllable media player daemon",
author="Mikael Royer, Alexandre Rossi",
author_email="[email protected]",
license="GNU GPL v2",
scripts=["scripts/deejayd", "scripts/djc"],
packages=["deejayd", "deejayd.common", "deejayd.library",
"deejayd.server",
"deejayd.dispatch",
"deejayd.library.parsers",
"deejayd.library.parsers.audio",
"deejayd.library.parsers.video", "deejayd.player",
"deejayd.sources", "deejayd.ui", "deejayd.jsonrpc",
"deejayd.db", "deejayd.db.dbmigrate",
"deejayd.db.dbmigrate.versions", "deejayd.webradio",
"deejayd.webui", "deejayd.playlist", "pytyx11"],
package_data={'deejayd.ui': ['defaults.conf'],
'deejayd.webui': ['webui.thtml', 'manifest.tjson'],
'deejayd.db.dbmigrate': ['migrate.cfg', 'README']},
data_files=build_data_files_list(),
cmdclass={
"build": deejayd_build,
"build_i18n": build_i18n,
"compile_catalog": babel.compile_catalog,
"extract_messages": babel.extract_messages,
"init_catalog": babel.init_catalog,
"update_catalog": babel.update_catalog,
"build_manpages": build_manpages,
"build_webui": build_webui,
"clean": deejayd_clean,
}
)