~cr3/ubuntu/lucid/checkbox/0.9.2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python

import os
import re
import posixpath
from glob import glob

from distutils.core import setup
from distutils.util import change_root, convert_path

from distutils.command.install import install
from distutils.command.install_data import install_data
from distutils.command.install_scripts import install_scripts
from DistUtilsExtra.command.build_extra import build_extra
from DistUtilsExtra.command.build_i18n import build_i18n
from DistUtilsExtra.command.build_icons import build_icons


def changelog_version(changelog="debian/changelog"):
    version = "dev"
    if posixpath.exists(changelog):
        head=open(changelog).readline()
        match = re.compile(".*\((.*)\).*").match(head)
        if match:
            version = match.group(1)

    return version

def substitute_variables(infile, outfile, variables={}):
    file_in = open(infile, "r")
    file_out = open(outfile, "w")
    for line in file_in.readlines():
        for key, value in variables.items():
            line = line.replace(key, value)
        file_out.write(line)


# Hack to workaround unsupported option in Python << 2.5
class checkbox_install(install, object):

    user_options = install.user_options + [
        ('install-layout=', None,
         "installation layout to choose (known values: deb)")]

    def initialize_options(self):
        super(checkbox_install, self).initialize_options()

        self.install_layout = None


class checkbox_install_data(install_data, object):

    def finalize_options(self):
        """Add wildcard support for filenames."""
        super(checkbox_install_data, self).finalize_options()

        for f in self.data_files:
            if type(f) != str:
                files = f[1]
                i = 0
                while i < len(files):
                    if "*" in files[i]:
                        for e in glob(files[i]):
                            files.append(e)
                        files.pop(i)
                        i -= 1
                    i += 1

    def run(self):
        """Run substitutions on files."""
        super(checkbox_install_data, self).run()

        examplesfiles = [o for o in self.outfiles if "examples" in o]
        if not examplesfiles:
            return

        # Create etc directory
        etcdir = convert_path("/etc/checkbox.d")
        if not posixpath.isabs(etcdir):
            etcdir = posixpath.join(self.install_dir, etcdir)
        elif self.root:
            etcdir = change_root(self.root, etcdir)
        self.mkpath(etcdir)

        # Create configs symbolic link
        dstdir = posixpath.dirname(examplesfiles[0]).replace("examples",
            "configs")
        os.symlink(etcdir, dstdir)

        # Substitute version in examplesfiles and etcfiles
        version = changelog_version()
        for examplesfile in examplesfiles:
            etcfile = posixpath.join(etcdir,
                posixpath.basename(examplesfile))
            infile = posixpath.join("examples",
                posixpath.basename(examplesfile))
            for outfile in examplesfile, etcfile:
                substitute_variables(infile, outfile, {
                    "version = dev": "version = %s" % version})


class checkbox_install_scripts(install_scripts, object):

    def run(self):
        """Run substitutions on files."""
        super(checkbox_install_scripts, self).run()

        # Substitute directory in defaults.py
        for outfile in self.outfiles:
            infile = posixpath.join("bin", posixpath.basename(outfile))
            substitute_variables(infile, outfile, {
                "CHECKBOX_SHARE:-.": "CHECKBOX_SHARE:-/usr/share/checkbox",
                "CHECKBOX_DATA:-.": "CHECKBOX_DATA:-$XDG_CACHE_HOME/checkbox"})


setup(
    name = "checkbox",
    version = changelog_version(),
    author = "Marc Tardif",
    author_email = "marc.tardif@canonical.com",
    license = "GPL",
    description = "Checkbox System Testing",
    long_description = """
This project provides an extensible interface for system testing.
""",
    data_files = [
        ("share/checkbox/", ["backend", "run"]),
        ("share/checkbox/data/", ["data/*.txt"]),
        ("share/checkbox/examples/", ["examples/*"]),
        ("share/checkbox/install/", ["install/*"]),
        ("share/checkbox/patches/", ["patches/*"]),
        ("share/checkbox/plugins/", ["plugins/*.py"]),
        ("share/checkbox/report/", ["report/*"]),
        ("share/checkbox/scripts/", ["scripts/*"]),
        ("share/checkbox/gtk/", ["gtk/checkbox-gtk.glade", "gtk/*.png"]),
        ("share/apport/package-hooks/", ["apport/source_checkbox.py"]),
        ("share/apport/general-hooks/", ["apport/checkbox.py"])],
    scripts = ["bin/checkbox-cli", "bin/checkbox-gtk"],
    packages = ["checkbox", "checkbox.contrib", "checkbox.lib", "checkbox.reports",
        "checkbox_cli", "checkbox_gtk"],
    cmdclass = {
        "install": checkbox_install,
        "install_data": checkbox_install_data,
        "install_scripts": checkbox_install_scripts,
        "build": build_extra,
        "build_i18n":  build_i18n,
        "build_icons":  build_icons }
)