~ubuntu-branches/ubuntu/precise/checkbox/precise

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Tardif
  • Date: 2009-01-20 16:46:15 UTC
  • Revision ID: james.westby@ubuntu.com-20090120164615-7iz6nmlef41h4vx2
Tags: 0.4
* Setup bzr-builddeb in native mode.
* Removed LGPL notice from the copyright file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import os
 
4
import re
 
5
import posixpath
 
6
from glob import glob
 
7
 
 
8
from distutils.core import setup
 
9
from distutils.util import change_root, convert_path
 
10
 
 
11
from distutils.command.install_data import install_data
 
12
from distutils.command.install_scripts import install_scripts
 
13
from DistUtilsExtra.command.build_extra import build_extra
 
14
from DistUtilsExtra.command.build_i18n import build_i18n
 
15
 
 
16
 
 
17
def changelog_version(changelog="debian/changelog"):
 
18
    version = "dev"
 
19
    if posixpath.exists(changelog):
 
20
        head=open(changelog).readline()
 
21
        match = re.compile(".*\((.*)\).*").match(head)
 
22
        if match:
 
23
            version = match.group(1)
 
24
 
 
25
    return version
 
26
 
 
27
def substitute_variables(infile, outfile, variables={}):
 
28
    file_in = open(infile, "r")
 
29
    file_out = open(outfile, "w")
 
30
    for line in file_in.readlines():
 
31
        for key, value in variables.items():
 
32
            line = line.replace(key, value)
 
33
        file_out.write(line)
 
34
 
 
35
 
 
36
class checkbox_install_data(install_data, object):
 
37
 
 
38
    def finalize_options(self):
 
39
        """Add wildcard support for filenames."""
 
40
        super(checkbox_install_data, self).finalize_options()
 
41
 
 
42
        for f in self.data_files:
 
43
            if type(f) != str:
 
44
                files = f[1]
 
45
                i = 0
 
46
                while i < len(files):
 
47
                    if "*" in files[i]:
 
48
                        for e in glob(files[i]):
 
49
                            files.append(e)
 
50
                        files.pop(i)
 
51
                        i -= 1
 
52
                    i += 1
 
53
 
 
54
    def run(self):
 
55
        """Run substitutions on files."""
 
56
        super(checkbox_install_data, self).run()
 
57
 
 
58
        examplesfiles = [o for o in self.outfiles if "examples" in o]
 
59
        if not examplesfiles:
 
60
            return
 
61
 
 
62
        # Create etc directory
 
63
        etcdir = convert_path("/etc/checkbox.d")
 
64
        if not posixpath.isabs(etcdir):
 
65
            etcdir = posixpath.join(self.install_dir, etcdir)
 
66
        elif self.root:
 
67
            etcdir = change_root(self.root, etcdir)
 
68
        self.mkpath(etcdir)
 
69
 
 
70
        # Create configs symbolic link
 
71
        dstdir = posixpath.dirname(examplesfiles[0]).replace("examples",
 
72
            "configs")
 
73
        os.symlink(etcdir, dstdir)
 
74
 
 
75
        # Substitute version in examplesfiles and etcfiles
 
76
        version = changelog_version()
 
77
        for examplesfile in examplesfiles:
 
78
            etcfile = posixpath.join(etcdir,
 
79
                posixpath.basename(examplesfile))
 
80
            infile = posixpath.join("examples",
 
81
                posixpath.basename(examplesfile))
 
82
            for outfile in examplesfile, etcfile:
 
83
                substitute_variables(infile, outfile, {
 
84
                    "version = dev": "version = %s" % version})
 
85
 
 
86
 
 
87
class checkbox_install_scripts(install_scripts, object):
 
88
 
 
89
    def run(self):
 
90
        """Run substitutions on files."""
 
91
        super(checkbox_install_scripts, self).run()
 
92
 
 
93
        # Substitute directory in defaults.py
 
94
        for outfile in self.outfiles:
 
95
            infile = posixpath.join("bin", posixpath.basename(outfile))
 
96
            substitute_variables(infile, outfile, {
 
97
                "CHECKBOX_SHARE:-.": "CHECKBOX_SHARE:-/usr/share/checkbox",
 
98
                "CHECKBOX_DATA:-.": "CHECKBOX_DATA:-/var/lib/checkbox"})
 
99
 
 
100
 
 
101
setup(
 
102
    name = "checkbox",
 
103
    version = changelog_version(),
 
104
    author = "Marc Tardif",
 
105
    author_email = "marc.tardif@canonical.com",
 
106
    license = "GPL",
 
107
    description = "Checkbox System Testing",
 
108
    long_description = """
 
109
This project provides an extensible interface for system testing. The
 
110
results can then be sent to Launchpad.
 
111
""",
 
112
    data_files = [
 
113
        ("share/pixmaps/", ["gtk/checkbox-gtk.xpm"]),
 
114
        ("share/checkbox/", ["run"]),
 
115
        ("share/checkbox/data/", ["data/*"]),
 
116
        ("share/checkbox/examples/", ["examples/*"]),
 
117
        ("share/checkbox/install/", ["install/*"]),
 
118
        ("share/checkbox/patches/", ["patches/*"]),
 
119
        ("share/checkbox/plugins/", ["plugins/*.py"]),
 
120
        ("share/checkbox/registries/", ["registries/*.py"]),
 
121
        ("share/checkbox/scripts/", ["scripts/*"]),
 
122
        ("share/checkbox/gtk/", ["gtk/checkbox-gtk.glade", "gtk/*.png"])],
 
123
    scripts = ["bin/checkbox-gtk", "bin/checkbox-cli"],
 
124
    packages = ["checkbox", "checkbox.contrib", "checkbox.lib", "checkbox.reports",
 
125
        "checkbox.registries", "checkbox_cli", "checkbox_gtk"],
 
126
    cmdclass = {
 
127
        "install_data": checkbox_install_data,
 
128
        "install_scripts": checkbox_install_scripts,
 
129
        "build" : build_extra,
 
130
        "build_i18n" :  build_i18n }
 
131
)