summaryrefslogtreecommitdiff
path: root/setup.py
blob: b6e94449573ba6822875c4c8b674c82487976506 (plain)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/python

from distutils import log
from distutils.core import setup, Command
from distutils.log import info, error
from distutils.command.build import build
from distutils.command.install import install
from distutils.dep_util import newer
from distutils.errors import DistutilsFileError
from sys import exec_prefix
import os.path
import subprocess
import shutil
from glob import glob


class BuildThemes(Command):
    description = 'Compile all the themes found in data/themes using edje_cc'
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        theme_dir = os.path.abspath(os.path.join('data', 'theme'))
        name = 'default'
        if not self.dry_run:
            self.compile_theme(theme_dir, name)

    def compile_theme(self, theme_dir, name):
        edc_path = os.path.join(theme_dir, name + '.edc')
        edj_path = os.path.join(theme_dir, name + '.edj')
        if os.path.exists(edc_path):
            if newer(edc_path, edj_path):
                info('Compiling theme "%s" from %s' % (name, edc_path))
                ret = subprocess.call([
                    'edje_cc', edc_path,
                    '-id', os.path.join(theme_dir, 'images'),
                    ])
                if ret != 0:
                    error('Error compiling theme "%s"' % name)
                else:
                    shutil.copymode(edc_path, edj_path)
        else:
            if not os.path.exists(edj_path):
                raise DistutilsFileError("Cannot build without theme files")


def get_l10n_files():
    po_dirs = []
    for po_dir in glob('locale/*'):
        if po_dir.endswith('.pot'):
            continue
        lang = os.path.basename(po_dir)
        mo_path = "%s/polkit-efl.mo" % (po_dir)
        po_path = "%s/polkit-efl.po" % (po_dir)
        po_dirs.append((po_dir, lang, mo_path, po_path))
    return po_dirs


class BuildL10N(Command):
    description = 'Compile all l10n files'
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        for po_dir, lang, mo_path, po_path in get_l10n_files():
            if os.path.exists(po_path):
                if newer(po_path, mo_path):
                    info('Compiling l10n for "%s" from %s' % (lang, po_path))
                    ret = subprocess.call([
                        "msgfmt",
                        "-o%s" % (mo_path),
                        "-c",
                        po_path,
                        ])
                    if ret != 0:
                        error('Error compiling l10n for "%s"' % (lang))
                    else:
                        shutil.copymode(po_path, mo_path)

data_files = [
    (
        '/etc/xdg/autostart',
        ['data/polkit-efl-authentication-agent-1.desktop']
        ),
    (
        '%s/share/polkit-efl/theme' % (exec_prefix),
        ['data/theme/default.edj']
        )
    ]

scripts = ['polkit-efl-authentication-agent-1']

for po_dir, lang, mo_path, po_path in get_l10n_files():
    data_files.append(
        (
            '%s/share/locale/%s/LC_MESSAGES' % (
                exec_prefix, lang
                ),
            [mo_path]
            )
        )


class Build(build):
    def run(self):
        self.run_command("build_themes")
        self.run_command("build_l10n")
        build.run(self)


class Install(install):
    def handle_extra_path(self):
        exec_path = os.path.join(
            self.install_scripts, "polkit-efl-authentication-agent-1"
            )
        in_path = 'data/polkit-efl-authentication-agent-1.desktop.in'
        out_path = 'data/polkit-efl-authentication-agent-1.desktop'
        if os.path.exists(in_path):
            log.info("modifying .desktop file's Exec to %s" % exec_path)
            if not self.dry_run:
                with open(
                    in_path, 'r'
                        ) as src:
                    tmp = src.read()

                with open(
                    out_path, 'w'
                        ) as dest:
                    dest.write(tmp)
                    dest.write(
                        "Exec=%s\n" % (
                            exec_path
                            )
                        )
        install.handle_extra_path(self)


setup(
    name='polkit-efl',
    version='0.1.0',
    author='Kai Huuhko',
    author_email='kai.huuhko@gmail.com',
    maintainer='Kai Huuhko',
    maintainer_email='kai.huuhko@gmail.com',
    description='EFL polkit authentication agent',
    url='http://www.enlightenment.org/',
    download_url='http://download.enlightenment.org/',
    license='GNU GPL',
    platforms='linux',
    requires=[
        'dbus',
        'python_efl',
        ],
    data_files=data_files,
    scripts=scripts,
    cmdclass={
        'build_themes': BuildThemes,
        'build_l10n': BuildL10N,
        'build': Build,
        'install': Install,
        },
    )