~ubuntu-branches/ubuntu/oneiric/checkbox/oneiric-proposed

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Manrique, Marc Tardif, Chad A. Davis, Barry Warsaw
  • Date: 2011-07-01 11:37:27 UTC
  • Revision ID: james.westby@ubuntu.com-20110701113727-k4pekmtyr7v2i6le
Tags: 0.12.3
[ Marc Tardif ]
* Only reading CHECKBOX_* environment variables in config (LP: #802458)
* Imported scripts and jobs from Platform Services.

[Chad A. Davis]
* Switch to dh_python2 and debhelper7 (LP: #788514)

[Barry Warsaw]
* Fix checkbox_clean.run() to ignore missing executables, as is the case
  in a fresh checkout.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import os
4
4
import re
 
5
import errno
5
6
import posixpath
6
7
from glob import glob
7
8
 
8
9
from distutils.core import setup
9
10
from distutils.util import change_root, convert_path
10
11
 
 
12
from distutils.ccompiler import new_compiler
 
13
from distutils.command.build import build
 
14
from distutils.command.clean import clean
11
15
from distutils.command.install import install
12
16
from distutils.command.install_data import install_data
13
17
from distutils.command.install_scripts import install_scripts
26
30
 
27
31
    return version
28
32
 
 
33
def expand_data_files(data_files):
 
34
    for f in data_files:
 
35
        if type(f) != str:
 
36
            files = f[1]
 
37
            i = 0
 
38
            while i < len(files):
 
39
                if files[i].find("*") > -1:
 
40
                    for e in glob(files[i]):
 
41
                        files.append(e)
 
42
                    files.pop(i)
 
43
                    i -= 1
 
44
                i += 1
 
45
 
 
46
    return data_files
 
47
 
 
48
def extract_sources_from_data_files(data_files):
 
49
    all_sources = []
 
50
    data_files = expand_data_files(data_files)
 
51
    for destination, sources in data_files:
 
52
        all_sources.extend([s for s in sources if s.endswith(".c")])
 
53
 
 
54
    return all_sources
 
55
 
 
56
def extract_executables_from_data_files(data_files):
 
57
    sources = extract_sources_from_data_files(data_files)
 
58
    return [os.path.splitext(s)[0] for s in sources]
 
59
 
29
60
def substitute_variables(infile, outfile, variables={}):
30
61
    file_in = open(infile, "r")
31
62
    file_out = open(outfile, "w")
35
66
        file_out.write(line)
36
67
 
37
68
 
 
69
class checkbox_build(build_extra, object):
 
70
 
 
71
    def initialize_options(self):
 
72
        super(checkbox_build, self).initialize_options()
 
73
 
 
74
        self.sources = []
 
75
 
 
76
    def finalize_options(self):
 
77
        super(checkbox_build, self).finalize_options()
 
78
 
 
79
        # Initialize sources
 
80
        data_files = self.distribution.data_files
 
81
        self.sources = extract_sources_from_data_files(data_files)
 
82
 
 
83
    def run(self):
 
84
        super(checkbox_build, self).run()
 
85
 
 
86
        cc = new_compiler()
 
87
        for source in self.sources:
 
88
            executable = os.path.splitext(source)[0]
 
89
            cc.link_executable([source], executable, libraries=["rt", "pthread"])
 
90
 
 
91
 
 
92
class checkbox_clean(clean, object):
 
93
 
 
94
    def initialize_options(self):
 
95
        super(checkbox_clean, self).initialize_options()
 
96
 
 
97
        self.executables = None
 
98
 
 
99
    def finalize_options(self):
 
100
        super(checkbox_clean, self).finalize_options()
 
101
 
 
102
        # Initialize sources
 
103
        data_files = self.distribution.data_files
 
104
        self.executables = extract_executables_from_data_files(data_files)
 
105
 
 
106
    def run(self):
 
107
        super(checkbox_clean, self).run()
 
108
 
 
109
        for executable in self.executables:
 
110
            try:
 
111
                os.unlink(executable)
 
112
            except OSError, error:
 
113
                if error.errno != errno.ENOENT:
 
114
                    raise
 
115
 
 
116
 
38
117
# Hack to workaround unsupported option in Python << 2.5
39
118
class checkbox_install(install, object):
40
119
 
109
188
        for outfile in self.outfiles:
110
189
            infile = posixpath.join("bin", posixpath.basename(outfile))
111
190
            substitute_variables(infile, outfile, {
 
191
                "CHECKBOX_OPTIONS:-": "CHECKBOX_OPTIONS:---whitelist-file=$CHECKBOX_SHARE/data/whitelists/default.whitelist",
112
192
                "CHECKBOX_SHARE:-.": "CHECKBOX_SHARE:-/usr/share/checkbox",
113
193
                "CHECKBOX_DATA:-.": "CHECKBOX_DATA:-$XDG_CACHE_HOME/checkbox"})
114
194
 
138
218
        ("share/checkbox/data/images/", ["data/images/*"]), 
139
219
        ("share/checkbox/data/video/", ["data/video/*"]), 
140
220
        ("share/checkbox/data/websites/", ["data/websites/*"]), 
 
221
        ("share/checkbox/data/whitelists/", ["data/whitelists/*"]), 
141
222
        ("share/checkbox/examples/", ["examples/*"]),
142
223
        ("share/checkbox/install/", ["install/*"]),
143
224
        ("share/checkbox/patches/", ["patches/*"]),
152
233
    packages = ["checkbox", "checkbox.contrib", "checkbox.lib", "checkbox.parsers",
153
234
        "checkbox.reports", "checkbox_cli", "checkbox_gtk", "checkbox_urwid"],
154
235
    cmdclass = {
 
236
        "build": checkbox_build,
 
237
        "build_i18n":  build_i18n,
 
238
        "build_icons":  checkbox_build_icons,
 
239
        "clean": checkbox_clean,
155
240
        "install": checkbox_install,
156
241
        "install_data": checkbox_install_data,
157
 
        "install_scripts": checkbox_install_scripts,
158
 
        "build": build_extra,
159
 
        "build_i18n":  build_i18n,
160
 
        "build_icons":  checkbox_build_icons }
 
242
        "install_scripts": checkbox_install_scripts}
161
243
)