Make --without-gettext work in more situations. Needs some tidying; if nothing else some metaprogramming to reduce duplication.

This commit is contained in:
Thomas Hurst 2008-07-06 18:03:05 +01:00
parent 6cb121a9f7
commit 71f9dc5ca1
1 changed files with 26 additions and 11 deletions

View File

@ -2,6 +2,7 @@
from distutils.core import setup from distutils.core import setup
from distutils.command.install_data import install_data from distutils.command.install_data import install_data
from distutils.command.install import install
from distutils.command.build import build from distutils.command.build import build
from distutils.dep_util import newer from distutils.dep_util import newer
from distutils.log import info from distutils.log import info
@ -15,7 +16,9 @@ from terminatorlib.version import *
PO_DIR = 'po' PO_DIR = 'po'
MO_DIR = os.path.join('build', 'mo') MO_DIR = os.path.join('build', 'mo')
WITHOUT_GETTEXT = False
# Someone with more distutils clue needs to sort out our --without-gettext nonsense
class BuildData(build): class BuildData(build):
user_options = build.user_options user_options = build.user_options
user_options.append(("without-gettext", None, "Don't build gettext .mo files")) user_options.append(("without-gettext", None, "Don't build gettext .mo files"))
@ -28,7 +31,7 @@ class BuildData(build):
def run (self): def run (self):
build.run (self) build.run (self)
if self.without_gettext: if self.without_gettext or WITHOUT_GETTEXT:
return return
for po in glob.glob (os.path.join (PO_DIR, '*.po')): for po in glob.glob (os.path.join (PO_DIR, '*.po')):
@ -52,15 +55,29 @@ class BuildData(build):
sys.exit(1) sys.exit(1)
class Install(install):
user_options = install.user_options
user_options.append(("without-gettext", None, "Don't install gettext .mo files"))
def initialize_options(self):
install.initialize_options(self)
self.without_gettext = False
def run(self):
global WITHOUT_GETTEXT
if self.without_gettext:
WITHOUT_GETTEXT = True
install.run(self)
class InstallData(install_data): class InstallData(install_data):
user_options = install_data.user_options user_options = install_data.user_options
user_options.append(("without-gettext", None, "Don't install gettext .mo files")) user_options.append(("without-gettext", None, "Don't build gettext .mo files"))
def initialize_options(self): def initialize_options(self):
install_data.initialize_options(self) install_data.initialize_options(self)
self.without_gettext = False self.without_gettext = False
def run (self): def run (self):
self.data_files.extend (self._find_mo_files ()) self.data_files.extend (self._find_mo_files ())
install_data.run (self) install_data.run (self)
@ -69,9 +86,7 @@ class InstallData(install_data):
def _find_mo_files (self): def _find_mo_files (self):
data_files = [] data_files = []
if self.without_gettext: if not (self.without_gettext or WITHOUT_GETTEXT):
return data_files
for mo in glob.glob (os.path.join (MO_DIR, '*', 'terminator.mo')): for mo in glob.glob (os.path.join (MO_DIR, '*', 'terminator.mo')):
lang = os.path.basename(os.path.dirname(mo)) lang = os.path.basename(os.path.dirname(mo))
dest = os.path.join('share', 'locale', lang, 'LC_MESSAGES') dest = os.path.join('share', 'locale', lang, 'LC_MESSAGES')
@ -106,6 +121,6 @@ setup(name='Terminator',
('share/icons/hicolor/16x16/actions', glob.glob('data/icons/16x16/actions/*.png')), ('share/icons/hicolor/16x16/actions', glob.glob('data/icons/16x16/actions/*.png')),
], ],
packages=['terminatorlib'], packages=['terminatorlib'],
cmdclass={'build': BuildData, 'install_data': InstallData} cmdclass={'build': BuildData, 'install_data': InstallData, 'install': Install}
) )