Projet

Général

Profil

Télécharger (4,03 ko) Statistiques
| Branche: | Tag: | Révision:

root / setup.py @ 2ebf524c

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, stderr=subprocess.PIPE
25
        )
26
        result = p.communicate()[0]
27
        if p.returncode == 0:
28
            result = result.decode('ascii').strip()[1:]  # strip spaces/newlines and initial v
29
            if '-' in result:  # not a tagged version
30
                real_number, commit_count, commit_hash = result.split('-', 2)
31
                version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
32
            else:
33
                version = result
34
            return version
35
        else:
36
            return '0.0.post%s' % len(
37
                    subprocess.check_output(
38
                            ['git', 'rev-list', 'HEAD']).splitlines())
39
    return '0.0'
40

    
41

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

    
54

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

    
59
    def initialize_options(self):
60
        pass
61

    
62
    def finalize_options(self):
63
        pass
64

    
65
    def run(self):
66
        try:
67
            from django.core.management import call_command
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

    
91
    def run(self):
92
        print("creating VERSION file")
93
        if os.path.exists('VERSION'):
94
            os.remove('VERSION')
95
        version = get_version()
96
        version_file = open('VERSION', 'w')
97
        version_file.write(version)
98
        version_file.close()
99
        sdist.run(self)
100
        print("removing VERSION file")
101
        if os.path.exists('VERSION'):
102
            os.remove('VERSION')
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={'build': build,
112
                  'compile_translations': compile_translations,
113
                  'install_lib': install_lib,
114
                  'sdist': eo_sdist},
115
        include_package_data=True,
116
        data_files = data_tree('share/wcs/texts', 'texts') +\
117
            data_tree('share/wcs/themes/auquotidien', 'theme') +\
118
            data_tree('share/wcs/themes/', 'data/themes/') + \
119
            data_tree('share/auquotidien/apache-errors', 'apache-errors') +\
120
            [('share/wcs/', ['au-quotidien-wcs-settings.xml',])]
121
    )
(7-7/7)