]> git.0d.be Git - django-panik-combo.git/blob - setup.py
build: fix path to translation files
[django-panik-combo.git] / setup.py
1 #! /usr/bin/env python3
2
3 import os
4 import subprocess
5 import sys
6
7 from setuptools.command.install_lib import install_lib as _install_lib
8 from distutils.command.build import build as _build
9 from distutils.command.sdist import sdist as _sdist
10 from distutils.cmd import Command
11 from setuptools import setup, find_packages
12
13
14 class sdist(_sdist):
15     def run(self):
16         if os.path.exists('VERSION'):
17             os.remove('VERSION')
18         version = get_version()
19         with open('VERSION', 'w') as fd:
20             fd.write(version)
21         _sdist.run(self)
22         if os.path.exists('VERSION'):
23             os.remove('VERSION')
24
25
26 def get_version():
27     if os.path.exists('VERSION'):
28         with open('VERSION', 'r') as v:
29             return v.read()
30     if os.path.exists('.git'):
31         p = subprocess.Popen(['git', 'describe', '--dirty=.dirty', '--match=v*'],
32                 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
33         result = p.communicate()[0]
34         if p.returncode == 0:
35             result = result.decode('ascii').strip()[1:]  # strip spaces/newlines and initial v
36             if '-' in result:  # not a tagged version
37                 real_number, commit_count, commit_hash = result.split('-', 2)
38                 version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
39             else:
40                 version = result
41             return version
42         else:
43             return '0.0.post%s' % len(
44                     subprocess.check_output(
45                             ['git', 'rev-list', 'HEAD']).splitlines())
46     return '0.0'
47
48
49 class compile_translations(Command):
50     description = 'compile message catalogs to MO files via django compilemessages'
51     user_options = []
52
53     def initialize_options(self):
54         pass
55
56     def finalize_options(self):
57         pass
58
59     def run(self):
60         try:
61             from django.core.management import call_command
62             for path, dirs, files in os.walk('panikombo'):
63                 if 'locale' not in dirs:
64                     continue
65                 curdir = os.getcwd()
66                 os.chdir(os.path.realpath(path))
67                 call_command('compilemessages')
68                 os.chdir(curdir)
69         except ImportError:
70             sys.stderr.write('!!! Please install Django to build translations\n')
71
72
73 class build(_build):
74     sub_commands = [('compile_translations', None)] + _build.sub_commands
75
76
77 class install_lib(_install_lib):
78     def run(self):
79         self.run_command('compile_translations')
80         _install_lib.run(self)
81
82
83 setup(
84     name='panikombo',
85     version=get_version(),
86     description='Combo extensions for Radio Panik',
87     author='Frederic Peters',
88     author_email='fred@radiopanik.org',
89     packages=find_packages(),
90     include_package_data=True,
91     classifiers=[
92         'Development Status :: 4 - Beta',
93         'Environment :: Web Environment',
94         'Framework :: Django',
95         'Intended Audience :: Developers',
96         'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
97         'Operating System :: OS Independent',
98         'Programming Language :: Python',
99         'Programming Language :: Python :: 2',
100         'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
101         'Topic :: Multimedia :: Sound/Audio',
102     ],
103     zip_safe=False,
104     cmdclass={
105         'build': build,
106         'compile_translations': compile_translations,
107         'install_lib': install_lib,
108         'sdist': sdist,
109     }
110 )