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