aboutsummaryrefslogtreecommitdiff
blob: 16b65dcee49ad48307dab369c574ebb46f574147 (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
from distutils.core import setup
from distutils import log
from distutils.cmd import Command
from distutils.file_util import copy_file
from distutils.dir_util import remove_tree
from distutils.command.build import build as _build
from distutils.command.install import install as _install
from distutils.command.clean import clean as _clean


import os
from glob import glob

## Snippet of code found on 
## http://developer.berlios.de/snippet/detail.php?type=snippet&id=100019
## Useful to handle *.po files under distutils

class messages(Command):

    description = 'Extract messages from source files'

    user_options = [('merge', 'm', 'Merge message catalogs after '
                     'extracting template')]

    boolean_options = ['merge']

    def initialize_options(self):
        self.merge = False

    def finalize_options(self):
        pass

    def run(self):
        wd = os.getcwd()
        name = self.distribution.get_name()
        log.info('Extracting messages from %s' % name)
        os.chdir('po')
        os.system('pygettext -k i18n -o %s.pot ../%s' % (name, name))
        os.chdir(wd)
        if self.merge:
            self.run_command('merge')

class merge(Command):
    description = 'Merge message catalogs with template'

    user_options = [('lang=', 'l', 'Only merge specified language')]

    def initialize_options(self):
        self.lang = None

    def finalize_options(self):
        pass

    def run(self):
        wd = os.getcwd()
        os.chdir('po')
        if self.lang is not None:
            filename = '%s.po' % self.lang
            if os.path.exists(filename):
                self.merge(filename)
            else:
                log.error('No catalog found for language %s' % self.lang)
        else:
            files = glob('*.po')
            for f in files:
                self.merge(f)
        os.chdir(wd)

    def merge(self, f):
        name = self.distribution.get_name()
        log.info('Merging catalog %s' % f)
        os.system('msgmerge %s %s.pot -o %s' % (f, name, f))


class build_messages(Command):

    description = 'Compile message catalogs'
    user_options = [('build-dir=', 'd', 'directory to build message catalogs in')]

    def initialize_options(self):
        self.build_dir = None

    def finalize_options(self):
        self.set_undefined_options('build',
                                  ('build_messages', 'build_dir'))

    def run(self):
        self.mkpath(self.build_dir)
        po_files = os.path.join('po', '*.po')
        po_files = glob(po_files)
        for f in po_files:
            base = os.path.basename(f)
            base = os.path.splitext(base)[0]
            out_file = os.path.join(self.build_dir, '%s.gmo' % base)
            log.info('Building catalog %s > %s' % (f, out_file))
            cmd = 'msgfmt -o "%s" %s' % (out_file, f)
            os.system(cmd)

class build(_build):
    # integrate build_message
    def has_messages(self):
        return True

    def initialize_options(self):
        _build.initialize_options(self)
        self.build_messages = None

    def finalize_options(self):
        _build.finalize_options(self)
        if self.build_messages is None:
            self.build_messages = os.path.join(self.build_base,
                                               'po')

    _build.user_options.append(('build-messages=', None,
         "build directory for messages"))
    _build.sub_commands.append(('build_messages', has_messages))

class install_messages(Command):

    description = 'Installs message catalogs'

    user_options = [
        ('install-dir=', 'd', "directory to install scripts to"),
        ('build-dir=','b', "build directory (where to install from)"),
        ('skip-build', None, "skip the build steps"),
    ]

    boolean_options = ['skip-build']

    def initialize_options(self):
        self.install_dir = None
        self.build_dir = None
        self.skip_build = None

    def finalize_options(self):
        self.set_undefined_options('build', ('build_messages', 'build_dir'))
        self.set_undefined_options('install',
                                   ('install_data', 'install_dir'),
                                   ('force', 'force'),
                                   ('skip_build', 'skip_build'),
                                  )
        self.install_dir = os.path.join(self.install_dir, 'share', 'locale')

    def run(self):
        if not self.skip_build:
            self.run_command('build_messages')
        catalogs = glob(os.path.join(self.build_dir, '*.gmo'))
        for c in catalogs:
            base = os.path.basename(c)
            base = os.path.splitext(base)[0]
            out_dir = os.path.join(self.install_dir, base, 'LC_MESSAGES')
            self.mkpath(out_dir)
            out_file = os.path.join(out_dir, '%s.mo' % self.distribution.get_name())
            copy_file(c, out_file)

class clean(_clean):
    _clean.user_options.append(('build-messages=', None,
                                "build directory for messages (default: 'build.build-messages')"))

    def initialize_options(self):
        _clean.initialize_options(self)
        self.build_messages = None

    def finalize_options(self):
        self.set_undefined_options('build',
                                   ('build_base', 'build_base'),
                                   ('build_lib', 'build_lib'),
                                   ('build_scripts', 'build_scripts'),
                                   ('build_temp', 'build_temp'),
                                   ('build_messages', 'build_messages'))
        self.set_undefined_options('bdist',
                                   ('bdist_base', 'bdist_base'))
    def run(self):
        # remove the build/temp.<plat> directory (unless it's already
        # gone)
        if os.path.exists(self.build_temp):
            remove_tree(self.build_temp, dry_run=self.dry_run)
        else:
            log.debug("'%s' does not exist -- can't clean it",
                      self.build_temp)

        if self.all:
            # remove build directories
            for directory in (self.build_lib,
                              self.bdist_base,
                              self.build_scripts,
                              self.build_messages):
                if os.path.exists(directory):
                    remove_tree(directory, dry_run=self.dry_run)
                else:
                    log.warn("'%s' does not exist -- can't clean it",
                             directory)

        # just for the heck of it, try to remove the base build directory:
        # we might have emptied it right now, but if not we don't care
        if not self.dry_run:
            try:
                os.rmdir(self.build_base)
                log.info("removing '%s'", self.build_base)
            except OSError:
                pass

## Class modified to add manpages command
class install(_install):
    def has_messages(self):
        return True

    def has_manpages(self):
        return True
        
    _install.sub_commands.append(('install_messages', has_messages))
    _install.sub_commands.append(('install_manpages', has_manpages))  

### End of snippet ###

class install_manpages(Command):

    description = "Install man pages"
    
    user_options = []
    
    def initialize_options(self):
        self.man_pages = man_pages
        self.install_dir = None
        self.root = None
    
    def finalize_options(self):
        self.set_undefined_options('install',
                                   ('install_data', 'install_dir'),
                                   ('root', 'root'),
                                  )
    def run(self):
        for f in self.man_pages:
            attrs = f.split(".")
            dest = os.path.join(self.install_dir,"share","man")
            try:
                dest = os.path.join(dest,attrs[2])
            except IndexError:
                pass
            dest = os.path.join(dest,"man" + attrs[1])
            self.mkpath(dest)
            self.copy_file(f, dest)

man_pages=glob("man/*")
      
setup(name="elogv",
      version="0.7.6.5",
      author="Luca Marturana",
      author_email="lucamarturana@gmail.com",
      license="GPL-2",
      description="Curses based utility to view elogs created by Portage",
      url="https://github.com/gentoo/elogv",
      scripts=['elogv'],
      cmdclass={'extract_messages': messages,
                'merge': merge,
                'build_messages': build_messages,
                'build': build,
                'install_messages': install_messages,
                'install_manpages': install_manpages,
                'install': install,
                'clean': clean}
)