root/setup.py

Revision 1469, 8.1 kB (checked in by Alexandre Rossi <alexandre.rossi@…>, 3 months ago)

[doc] rename protocol doc file to be consistent with new protocol

Line 
1#!/usr/bin/env python
2
3# Deejayd, a media player daemon
4# Copyright (C) 2007-2009 Mickael Royer <mickael.royer@gmail.com>
5#                         Alexandre Rossi <alexandre.rossi@gmail.com>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21import glob,os
22from distutils.command.build import build as distutils_build
23from distutils.command.clean import clean as distutils_clean
24from distutils.core import setup,Command
25from distutils.errors import DistutilsFileError
26from distutils.dep_util import newer
27from distutils.dir_util import remove_tree
28from distutils.spawn import find_executable
29from zipfile import ZipFile
30
31import deejayd
32
33
34def force_unlink(path):
35    try:
36        os.unlink(path)
37    except OSError:
38        pass
39
40def force_rmdir(path):
41    try:
42        os.rmdir(path)
43    except OSError:
44        pass
45
46
47class build_extension(Command):
48    ext_directory = None
49    extension = None
50
51    def initialize_options(self):
52        pass
53
54    def finalize_options(self):
55        self.ext_directory = "extensions"
56        self.extension = "deejayd-webui"
57        self.ext_dir = os.path.join(self.ext_directory, self.extension)
58        self.ext_path = "%s.xpi" % self.ext_dir
59
60    def run(self):
61        data_files = self.distribution.data_files
62
63        # first remove old zip file
64        self.clean()
65        ext_file = ZipFile(self.ext_path, 'w')
66        for root, dirs, files in os.walk(self.ext_dir):
67            for f in files:
68                path = os.path.join(root, f)
69                ext_file.write(path, path[len(self.ext_dir):])
70        ext_file.close()
71
72        target_path = os.path.join('share', 'deejayd', 'htdocs')
73        data_files.append((target_path, (self.ext_path, ), ))
74
75    def clean(self):
76        force_unlink(self.ext_path)
77
78
79class build_manpages(Command):
80    manpages = None
81    db2mans = [
82        # debian
83        "/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl",
84        # gentoo
85        "/usr/share/sgml/docbook/xsl-stylesheets/manpages/docbook.xsl",
86        ]
87    mandir = "man/"
88    executable = find_executable('xsltproc')
89
90    def initialize_options(self):
91        pass
92
93    def finalize_options(self):
94        self.manpages = glob.glob(os.path.join(self.mandir, "*.xml"))
95
96    def __get_manpage(self, xmlmanpage):
97        return xmlmanpage[:-4] # remove '.xml' at the end
98
99    def run(self):
100        data_files = self.distribution.data_files
101        db2man = None
102        for path in self.__class__.db2mans:
103            if os.path.exists(path):
104                db2man = path
105                continue
106
107        for xmlmanpage in self.manpages:
108            manpage = self.__get_manpage(xmlmanpage)
109            if newer(xmlmanpage, manpage):
110                cmd = (self.executable, "--nonet", "-o", self.mandir, db2man,
111                       xmlmanpage)
112                self.spawn(cmd)
113
114            targetpath = os.path.join("share", "man","man%s" % manpage[-1])
115            data_files.append((targetpath, (manpage, ), ))
116
117    def clean(self):
118        for xmlmanpage in self.manpages:
119            force_unlink(self.__get_manpage(xmlmanpage))
120
121
122class build_i18n(Command):
123    user_options = []
124    po_package = None
125    po_directory = None
126    po_files = None
127    executable = find_executable('msgfmt')
128
129    def initialize_options(self):
130        pass
131
132    def finalize_options(self):
133        self.po_directory = "po"
134        self.po_package = "deejayd"
135        self.po_files = glob.glob(os.path.join(self.po_directory, "*.po"))
136        self.mo_dir = os.path.join('build', 'mo')
137
138    def run(self):
139        data_files = self.distribution.data_files
140
141        for po_file in self.po_files:
142            lang = os.path.basename(po_file[:-3])
143            mo_dir =  os.path.join(self.mo_dir, lang, "LC_MESSAGES")
144            mo_file = os.path.join(mo_dir, "%s.mo" % self.po_package)
145            if not os.path.exists(mo_dir):
146                os.makedirs(mo_dir)
147
148            cmd = (self.executable, po_file, "-o", mo_file)
149            self.spawn(cmd)
150
151            targetpath = os.path.join("share/locale", lang, "LC_MESSAGES")
152            data_files.append((targetpath, (mo_file,)))
153
154    def clean(self):
155        if os.path.isdir(self.mo_dir):
156            remove_tree(self.mo_dir)
157
158
159class deejayd_build(distutils_build):
160
161    def __has_manpages(self, command):
162        has_db2man = False
163        for path in build_manpages.db2mans:
164            if os.path.exists(path): has_db2man = True
165        return self.distribution.cmdclass.has_key("build_manpages")\
166            and has_db2man and build_manpages.executable != None
167
168    def __has_i18n(self, command):
169        return self.distribution.cmdclass.has_key("build_i18n")\
170            and build_i18n.executable != None
171
172    def __has_extension(self, command):
173        return self.distribution.cmdclass.has_key("build_extension")
174
175    def finalize_options(self):
176        distutils_build.finalize_options(self)
177        self.sub_commands.append(("build_i18n", self.__has_i18n))
178        self.sub_commands.append(("build_manpages", self.__has_manpages))
179        self.sub_commands.append(("build_extension", self.__has_extension))
180
181    def clean(self):
182        for subcommand_name in self.get_sub_commands():
183            subcommand = self.get_finalized_command(subcommand_name)
184            if hasattr(subcommand, 'clean'):
185                subcommand.clean()
186
187
188class deejayd_clean(distutils_clean):
189
190    def run(self):
191        distutils_clean.run(self)
192
193        for cmd in self.distribution.command_obj.values():
194            if hasattr(cmd, 'clean'):
195                cmd.clean()
196
197        force_unlink('MANIFEST')
198        force_rmdir('build')
199
200
201#
202# data files
203#
204def get_data_files(walking_root, dest_dir):
205    data_files = []
206    for root, dirs, files in os.walk(walking_root):
207        paths = [os.path.join(root, f) for f in files]
208        root = root.replace(walking_root, '').strip('/')
209        dest_path = os.path.join(dest_dir, root)
210        data_files.append((dest_path, paths))
211    return data_files
212
213def build_data_files_list():
214    data = [
215        ('share/doc/deejayd', ("doc/deejayd_rpc_protocol", )),
216        ('share/doc/deejayd', ("README", "NEWS", )),
217        ('share/doc/deejayd', ["scripts/deejayd_rgscan"]),
218        ]
219
220    # htdocs
221    data.extend(get_data_files('data/htdocs', 'share/deejayd/htdocs'))
222
223    return data
224
225if __name__ == "__main__":
226    setup( name="deejayd", version=deejayd.__version__,
227           url="http://mroy31.dyndns.org/~roy/projects/deejayd",
228           description="Network controllable media player daemon",
229           author="Mikael Royer, Alexandre Rossi",
230           author_email="mickael.royer@gmail.com",
231           license="GNU GPL v2",
232           scripts=["scripts/deejayd","scripts/djc"],
233           packages=["deejayd","deejayd.net","deejayd.mediadb",\
234                     "deejayd.mediadb.formats",
235                     "deejayd.mediadb.formats.audio",\
236                     "deejayd.mediadb.formats.video","deejayd.player",\
237                     "deejayd.sources","deejayd.ui","deejayd.rpc",\
238                     "deejayd.database","deejayd.database.upgrade",\
239                     "deejayd.database.backends",\
240                     "deejayd.webui","pytyxi"],
241           package_data={'deejayd.ui': ['defaults.conf'],},
242           data_files= build_data_files_list(),
243           cmdclass={"build": deejayd_build,
244                     "build_i18n": build_i18n,
245                     "build_extension": build_extension,
246                     "build_manpages": build_manpages,
247                     "clean"          : deejayd_clean,
248                    }
249        )
250
251# vim: ts=4 sw=4 expandtab
Note: See TracBrowser for help on using the browser.