]> git.0d.be Git - panikweb.git/blob - setup.py
limit embed view to podcastable sounds
[panikweb.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 distutils.spawn import find_executable
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('panikweb'):
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 >= 1.4 to build translations\n')
72
73
74 class compile_scss(Command):
75     description = 'compile scss files into css files'
76     user_options = []
77
78     def initialize_options(self):
79         pass
80
81     def finalize_options(self):
82         pass
83
84     def run(self):
85         sass_bin = None
86         for program in ('sassc', 'sass'):
87             sass_bin = find_executable(program)
88             if sass_bin:
89                 break
90         if not sass_bin:
91             raise CompileError(
92                 'A sass compiler is required but none was found.  See sass-lang.com for choices.'
93             )
94
95         for path, dirnames, filenames in os.walk('panikweb'):
96             for filename in filenames:
97                 if not filename.endswith('.scss'):
98                     continue
99                 if filename.startswith('_'):
100                     continue
101                 subprocess.check_call(
102                     [
103                         sass_bin,
104                         '%s/%s' % (path, filename),
105                         '%s/%s' % (path, filename.replace('.scss', '.css')),
106                     ]
107                 )
108
109
110 class build(_build):
111     sub_commands = [('compile_translations', None), ('compile_scss', None)] + _build.sub_commands
112
113
114 class install_lib(_install_lib):
115     def run(self):
116         self.run_command('compile_translations')
117         _install_lib.run(self)
118
119
120 setup(
121     name='panikweb',
122     version=get_version(),
123     description='Radio Panik Website',
124     author='Frederic Peters',
125     author_email='fred@radiopanik.org',
126     packages=find_packages(),
127     url='https://www.radiopanik.org',
128     include_package_data=True,
129     scripts=('manage.py',),
130     classifiers=[
131         'Development Status :: 4 - Beta',
132         'Environment :: Web Environment',
133         'Framework :: Django',
134         'Intended Audience :: Developers',
135         'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
136         'Operating System :: OS Independent',
137         'Programming Language :: Python',
138         'Programming Language :: Python :: 3',
139         'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
140         'Topic :: Multimedia :: Sound/Audio',
141     ],
142     zip_safe=False,
143     cmdclass={
144         'build': build,
145         'compile_scss': compile_scss,
146         'compile_translations': compile_translations,
147         'install_lib': install_lib,
148         'sdist': sdist,
149     }
150 )