1
|
#! /usr/bin/env python
|
2
|
# -*- coding: utf-8 -*-
|
3
|
|
4
|
import glob
|
5
|
import os
|
6
|
import re
|
7
|
import subprocess
|
8
|
import sys
|
9
|
|
10
|
from setuptools.command.install_lib import install_lib as _install_lib
|
11
|
from distutils.command.build import build as _build
|
12
|
from distutils.command.sdist import sdist
|
13
|
from distutils.cmd import Command
|
14
|
from setuptools import setup, find_packages
|
15
|
|
16
|
class eo_sdist(sdist):
|
17
|
def run(self):
|
18
|
if os.path.exists('VERSION'):
|
19
|
os.remove('VERSION')
|
20
|
version = get_version()
|
21
|
version_file = open('VERSION', 'w')
|
22
|
version_file.write(version)
|
23
|
version_file.close()
|
24
|
sdist.run(self)
|
25
|
if os.path.exists('VERSION'):
|
26
|
os.remove('VERSION')
|
27
|
|
28
|
def get_version():
|
29
|
if os.path.exists('VERSION'):
|
30
|
version_file = open('VERSION', 'r')
|
31
|
version = version_file.read()
|
32
|
version_file.close()
|
33
|
return version
|
34
|
if os.path.exists('.git'):
|
35
|
p = subprocess.Popen(['git', 'describe', '--dirty',
|
36
|
'--match=v*'], stdout=subprocess.PIPE,
|
37
|
stderr=subprocess.PIPE)
|
38
|
result = p.communicate()[0]
|
39
|
if p.returncode == 0:
|
40
|
result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v
|
41
|
if '-' in result: # not a tagged version
|
42
|
real_number, commit_count, commit_hash = result.split('-', 2)
|
43
|
version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
|
44
|
else:
|
45
|
version = result
|
46
|
return version
|
47
|
else:
|
48
|
return '0.0.post%s' % len(
|
49
|
subprocess.check_output(
|
50
|
['git', 'rev-list', 'HEAD']).splitlines())
|
51
|
return '0'
|
52
|
|
53
|
def data_tree(destdir, sourcedir):
|
54
|
extensions = ['.css', '.png', '.jpeg', '.jpg', '.gif', '.xml', '.html', '.js']
|
55
|
r = []
|
56
|
for root, dirs, files in os.walk(sourcedir):
|
57
|
l = [os.path.join(root, x) for x in files if os.path.splitext(x)[1] in extensions]
|
58
|
r.append((root.replace(sourcedir, destdir, 1), l))
|
59
|
return r
|
60
|
|
61
|
class compile_translations(Command):
|
62
|
description = 'compile message catalogs to MO files via django compilemessages'
|
63
|
user_options = []
|
64
|
|
65
|
def initialize_options(self):
|
66
|
pass
|
67
|
|
68
|
def finalize_options(self):
|
69
|
pass
|
70
|
|
71
|
def run(self):
|
72
|
try:
|
73
|
from django.core.management import call_command
|
74
|
for path, dirs, files in os.walk('mandayejs'):
|
75
|
if 'locale' not in dirs:
|
76
|
continue
|
77
|
curdir = os.getcwd()
|
78
|
os.chdir(os.path.realpath(path))
|
79
|
try:
|
80
|
call_command('compilemessages')
|
81
|
finally:
|
82
|
os.chdir(curdir)
|
83
|
except ImportError:
|
84
|
sys.stderr.write('!!! Please install Django >= 1.4 to build translations\n')
|
85
|
|
86
|
|
87
|
class build(_build):
|
88
|
sub_commands = [('compile_translations', None)] + _build.sub_commands
|
89
|
|
90
|
|
91
|
class install_lib(_install_lib):
|
92
|
def run(self):
|
93
|
self.run_command('compile_translations')
|
94
|
_install_lib.run(self)
|
95
|
|
96
|
|
97
|
setup(
|
98
|
name='mandayejs',
|
99
|
version=get_version(),
|
100
|
description='Content Manager',
|
101
|
author='Frederic Peters',
|
102
|
author_email='fpeters@entrouvert.com',
|
103
|
packages=find_packages(),
|
104
|
include_package_data=True,
|
105
|
scripts=('manage.py',),
|
106
|
data_files=data_tree('share/mandayejs/themes/', 'data/themes/'),
|
107
|
url='https://dev.entrouvert.org/projects/mandayejs/',
|
108
|
classifiers=[
|
109
|
'Development Status :: 2 - Pre-Alpha',
|
110
|
'Environment :: Web Environment',
|
111
|
'Framework :: Django',
|
112
|
'Intended Audience :: Developers',
|
113
|
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
|
114
|
'Operating System :: OS Independent',
|
115
|
'Programming Language :: Python',
|
116
|
'Programming Language :: Python :: 2',
|
117
|
],
|
118
|
install_requires=['django>=1.8, <2.3',
|
119
|
'gadjo',
|
120
|
'django-jsonfield<1.3',
|
121
|
'python-ldap',
|
122
|
'pycrypto',
|
123
|
'requests',
|
124
|
'djangorestframework',
|
125
|
'django-mellon'
|
126
|
],
|
127
|
zip_safe=False,
|
128
|
cmdclass={
|
129
|
'build': build,
|
130
|
'compile_translations': compile_translations,
|
131
|
'install_lib': install_lib,
|
132
|
'sdist': eo_sdist,
|
133
|
},
|
134
|
)
|