1 # -*- coding: utf-8 -*-
3 # This file is part of Gnomolicious.
5 # Gnomolicious is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # Gnomolicious is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Gnomolicious; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # (C) 2003, 2005 Terje Røsten <terjeros@phys.ntnu.no>, Nicolas Évrard
30 from distutils
.core
import Command
31 from distutils
.command
.build
import build
32 from distutils
.command
.install
import install
33 from distutils
.command
.install_data
import install_data
34 from distutils
.dep_util
import newer
35 from distutils
.dist
import Distribution
36 from distutils
.core
import setup
39 from dsextras
import BuildExt
42 from gtk
.dsextras
import BuildExt
44 sys
.exit('Error: Can not find dsextras or gtk.dsextras')
47 class l10napp_build(build
):
49 def has_po_files(self
):
50 return self
.distribution
.has_po_files()
53 sub_commands
.append(('build_conf', None))
54 sub_commands
.extend(build
.sub_commands
)
55 sub_commands
.append(('build_mo', has_po_files
))
57 class l10napp_install(install
):
59 def has_po_files(self
):
60 return self
.distribution
.has_po_files()
63 sub_commands
.extend(install
.sub_commands
)
64 sub_commands
.append(('install_mo', has_po_files
))
66 class build_conf(Command
):
68 description
= 'update conf file'
72 def initialize_options(self
):
75 def finalize_options(self
):
76 self
.set_undefined_options('install', ('prefix', 'prefix'))
79 self
.announce('Building files from templates')
81 class build_mo(Command
):
83 description
= 'build binary message catalog'
86 ('build-base=', 'b', 'directory to build to')]
88 def initialize_options(self
):
89 self
.build_base
= None
90 self
.translations
= self
.distribution
.translations
92 def finalize_options(self
):
93 self
.set_undefined_options('build',
94 ('build_base', 'build_base'),
97 self
.announce('Building binary message catalog')
98 if self
.distribution
.has_po_files():
99 for mo
, po
in self
.translations
:
100 dest
= os
.path
.normpath(self
.build_base
+ '/' + mo
)
101 self
.mkpath(os
.path
.dirname(dest
))
102 if not self
.force
and not newer(po
, dest
):
103 self
.announce("not building %s (up-to-date)" % dest
)
105 msgfmt
.make(po
, dest
)
107 class install_mo(install_data
):
109 description
= 'install generated binary message catalog'
111 def initialize_options(self
):
112 install_data
.initialize_options(self
)
113 self
.translations
= self
.distribution
.translations
114 self
.has_po_files
= self
.distribution
.has_po_files
115 self
.install_dir
= None
116 self
.build_dir
= None
117 self
.skip_build
= None
120 def finalize_options(self
):
121 install_data
.finalize_options(self
)
122 self
.set_undefined_options('build_mo', ('build_base', 'build_dir'))
123 self
.set_undefined_options('install',
124 ('install_data', 'install_dir'),
125 ('skip_build', 'skip_build'))
127 if not self
.skip_build
:
128 self
.run_command('build_mo')
129 if self
.has_po_files():
130 for mo
, po
in self
.translations
:
131 src
= os
.path
.normpath(self
.build_dir
+ '/' + mo
)
132 if not os
.path
.isabs(mo
):
133 dest
= os
.path
.normpath(self
.install_dir
+ '/' + mo
)
135 dest
= self
.root
+ mo
138 self
.mkpath(os
.path
.dirname(dest
))
139 (out
, _
) = self
.copy_file(src
, dest
)
140 self
.outfiles
.append(out
)
142 def get_outputs (self
):
145 def get_inputs (self
):
146 return [ po
for mo
, po
in self
.translations
]
148 class L10nAppDistribution(Distribution
):
149 def __init__(self
, attrs
= None):
150 self
.modules_check
= 0
152 self
.msg_sources
= None
153 self
.translations
= []
154 self
.name
= attrs
.get('name')
155 Distribution
.__init
__(self
, attrs
)
157 'install' : l10napp_install
,
158 'install_mo' : install_mo
,
159 'build' : l10napp_build
,
160 'build_mo' : build_mo
,
161 'build_conf' : build_conf
,
162 'build_ext': BuildExt
,
165 def has_po_files(self
):
166 return len(self
.translations
) > 0
169 from distutils
.core
import setup
170 kwds
['distclass'] = L10nAppDistribution
173 # vim:expandtab:tw=80