Projet

Général

Profil

Télécharger (3,82 ko) Statistiques
| Branche: | Tag: | Révision:

root / setup.py @ main

1
#! /usr/bin/env python3
2

    
3
import os
4
import subprocess
5
import sys
6

    
7
from distutils.cmd import Command
8
from distutils.command.build import build as _build
9
from distutils.command.sdist import sdist
10
from setuptools.command.install_lib import install_lib as _install_lib
11
from setuptools import setup
12

    
13

    
14
def get_version():
15
    """Use the VERSION, if absent generates a version with git describe, if not
16
    tag exists, take 0.0- and add the length of the commit log.
17
    """
18
    if os.path.exists('VERSION'):
19
        with open('VERSION', 'r') as v:
20
            return v.read()
21
    if os.path.exists('.git'):
22
        p = subprocess.Popen(
23
            ['git', 'describe', '--dirty=.dirty', '--match=v*'],
24
            stdout=subprocess.PIPE,
25
            stderr=subprocess.PIPE,
26
        )
27
        result = p.communicate()[0]
28
        if p.returncode == 0:
29
            result = result.decode('ascii').strip()[1:]  # strip spaces/newlines and initial v
30
            if '-' in result:  # not a tagged version
31
                real_number, commit_count, commit_hash = result.split('-', 2)
32
                version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
33
            else:
34
                version = result
35
            return version
36
        else:
37
            return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines())
38
    return '0.0'
39

    
40

    
41
def data_tree(destdir, sourcedir):
42
    extensions = ['.css', '.png', '.jpeg', '.jpg', '.xml', '.html', '.js', '.ezt', '.gif', '.otf']
43
    r = []
44
    for root, dirs, files in os.walk(sourcedir):
45
        l = [os.path.join(root, x) for x in files if os.path.splitext(x)[1] in extensions]
46
        r.append((root.replace(sourcedir, destdir, 1), l))
47
        if 'CVS' in dirs:
48
            dirs.remove('CVS')
49
        if '.svn' in dirs:
50
            dirs.remove('.svn')
51
    return r
52

    
53

    
54
class compile_translations(Command):
55
    description = 'compile message catalogs to MO files via django compilemessages'
56
    user_options = []
57

    
58
    def initialize_options(self):
59
        pass
60

    
61
    def finalize_options(self):
62
        pass
63

    
64
    def run(self):
65
        try:
66
            from django.core.management import call_command
67

    
68
            for path, dirs, files in os.walk('auquotidien'):
69
                if 'locale' not in dirs:
70
                    continue
71
                curdir = os.getcwd()
72
                os.chdir(os.path.realpath(path))
73
                call_command('compilemessages')
74
                os.chdir(curdir)
75
        except ImportError:
76
            sys.stderr.write('!!! Please install Django >= 1.4 to build translations\n')
77

    
78

    
79
class build(_build):
80
    sub_commands = [('compile_translations', None)] + _build.sub_commands
81

    
82

    
83
class install_lib(_install_lib):
84
    def run(self):
85
        self.run_command('compile_translations')
86
        _install_lib.run(self)
87

    
88

    
89
class eo_sdist(sdist):
90
    def run(self):
91
        print("creating VERSION file")
92
        if os.path.exists('VERSION'):
93
            os.remove('VERSION')
94
        version = get_version()
95
        version_file = open('VERSION', 'w')
96
        version_file.write(version)
97
        version_file.close()
98
        sdist.run(self)
99
        print("removing VERSION file")
100
        if os.path.exists('VERSION'):
101
            os.remove('VERSION')
102

    
103

    
104
setup(
105
    name='wcs-au-quotidien',
106
    version=get_version(),
107
    maintainer='Frederic Peters',
108
    maintainer_email='fpeters@entrouvert.com',
109
    package_dir={'auquotidien': 'auquotidien'},
110
    packages=['auquotidien', 'auquotidien.modules'],
111
    cmdclass={
112
        'build': build,
113
        'compile_translations': compile_translations,
114
        'install_lib': install_lib,
115
        'sdist': eo_sdist,
116
    },
117
    include_package_data=True,
118
    data_files=data_tree('share/auquotidien/apache-errors', 'apache-errors')
119
    + [
120
        (
121
            'share/wcs/',
122
            [
123
                'au-quotidien-wcs-settings.xml',
124
            ],
125
        )
126
    ],
127
)
(9-9/9)