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