Hello all,
I've recently undertaken adding localization support to virtinst. Since
currently build and install from source is done using a typical setup.py
script, I've encountered several issues involving how to handle
installing the locale files, and making virtinst aware of where they are.
The attached patch handles the first issue: I added custom functionality
to to the build and install_data commands as invoked in the setup
script. The build command searchs po/ for any .po files and invokes
msgfmt to compile them. The install_data additions have to do some silly
things to name the files correctly as distutils cannot rename extra
install files on the fly (ex. moves po/es.mo to build/es/virtinst.mo).
The second problem is a bit more perplexing. The path to the locale
files has to be placed into a virtinst header so that the library knows
where to look for them. Possible solutions I see:
1) Extracting the install root from setup.py mid run. This has to happen
after build but before actual install. The locale path could then be
formed and sed'd or some equivalent into a virtinst header file, which
would than have to be (re)compiled and moved to the build directory.
Ugly way to do it, but the user can still use setup.py as normal and all
should work.
2) Force the user to use the autobuild.sh script and pass an environment
variable to that if they want to specify a different install root. That
way the sed'ing can be done prior to calling setup.py. Would be pretty
simple and non-intrusive, but no good for a user who wants to pass other
arguments to setup.py.
3) Use traditional autotools. Probably the 'right' solution, but a tad
overkill :) The only real way at multiplatforming the install as well,
since all other solutions would involve hardcoding share/locale/...
among other things, which might not be the directory structure used by
other platforms.
Thoughts? I'm not too familiar with this stuff so I may be overlooking a
simpler solution, or oversimplifying a complex one!
Thanks,
Cole
--
Cole Robinson
crobinso@xxxxxxxxxx
diff -r 65ea24a40b29 setup.py
--- a/setup.py Fri Jun 22 13:03:53 2007 -0400
+++ b/setup.py Mon Jun 25 14:12:35 2007 -0400
@@ -1,12 +1,15 @@ from distutils.core import setup, Comman
from distutils.core import setup, Command
+from distutils.command.build import build as _build
+from distutils.command.install_data import install_data as _install_data
from unittest import TextTestRunner, TestLoader
from glob import glob
from os.path import splitext, basename, join as pjoin, walk
import os
import tests.coverage as coverage
-
pkgs = ['virtinst']
+datafiles = [('share/man/man1', ['man/en/virt-install.1', \
+ 'man/en/virt-clone.1'])]
class TestCommand(Command):
user_options = [ ]
@@ -34,6 +37,50 @@ class TestCommand(Command):
t.run(tests)
coverage.stop()
+class build(_build):
+ """ custom build command to compile i18n files"""
+
+ def run(self):
+ dirlist = os.listdir("po")
+ for filename in dirlist:
+ if filename.endswith(".po"):
+ newname = filename.rpartition('.')[0] + ".mo"
+ print "Building %s from %s." % (newname, filename)
+ os.system("msgfmt po/%s -o po/%s" % (filename, newname))
+
+ _build.run(self)
+
+class install_data(_install_data):
+ """ custom install_data command to prepare i18n files for install"""
+
+ def run(self):
+ dirlist = os.listdir("po")
+ for filename in dirlist:
+
+ if filename.endswith(".mo"):
+ part = filename.rpartition('.')
+ install_path = "share/locale/%s/LC_MESSAGES/" % (part[0],)
+
+ # make a temp path ./build/po-rename/LANG/virtinst.mo, since we
+ # cannot rename files on install with the distutils
+ orig_path = "po/" + filename
+ new_path = "build/po-rename/%s/" % part[0]
+
+ if not os.path.exists(new_path):
+ os.makedirs(new_path)
+ new_path = new_path + filename
+
+ if os.path.isfile(new_path):
+ os.remove(new_path)
+ print "Linking %s to %s." % (orig_path, new_path)
+ os.link(orig_path, new_path)
+
+ toadd = (install_path, [new_path])
+
+ # Add these to the datafiles list
+ datafiles.append(toadd)
+ _install_data.run(self)
+
setup(name='virtinst',
version='0.103.0',
description='Virtual machine installation',
@@ -43,7 +90,8 @@ setup(name='virtinst',
package_dir={'virtinst': 'virtinst'},
scripts = ["virt-install","virt-clone"],
packages=pkgs,
- data_files = [('share/man/man1', ['man/en/virt-install.1', 'man/en/virt-clone.1'])],
- cmdclass = { 'test': TestCommand }
+ data_files = datafiles,
+ cmdclass = { 'test': TestCommand, 'build': build, \
+ 'install_data' : install_data}
)
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools