Here's the first part of an attempt at adding automatic translation support to dogtail. Attached is a patch to distro.py which adds getFiles() and getDependencies() methods to PackageDb, implementing them for the RPM backend [1] If anything needs these methods they'd need to get implemented for the other backends (Apt, Portage, etc), of course. Also attached is a test file which uses these methods to obtain a list of requirement packages for a given package (evolution) [2], and then uses this to obtain all of the French translation files for all of those packages. Here's the output when run on my FC3 box: Detecting distribution: Red Hat/Fedora/derived distribution ['libbonoboui', 'libxml2', 'popt', 'spamassassin', 'scrollkeeper', 'gtkhtml3', 'libart_lgpl', 'libgnomeprintui22', 'gnome-vfs2', 'GConf2', 'redhat-menus', 'glibc', 'ORBit2', 'libgpg-error', 'libglade2', 'xorg- x11-libs', 'libgnome', 'libgnomeprint22', 'libsoup', 'mozilla-nss', 'mozilla-nspr', 'gtk2', 'perl', 'openldap', 'gnutls', 'pango', 'libgcrypt', 'libgal2', 'gnome-icon-theme', 'evolution-data-server', 'libbonobo', 'zlib', 'atk', 'e2fsprogs', 'libgnomeui', 'krb5-libs', 'libgnomecanvas', 'pilot-link', 'gnome-pilot', 'glib2', 'gnome-spell'] ['/usr/share/locale/fr/LC_MESSAGES/evolution-2.0.mo', '/usr/share/locale/fr/LC_MESSAGES/libbonoboui-2.0.mo', '/usr/share/locale/fr/LC_MESSAGES/popt.mo', '/usr/share/locale/fr/LC_MESSAGES/scrollkeeper.mo', '/usr/share/locale/fr/LC_MESSAGES/gtkhtml-3.1.mo', '/usr/share/locale/fr/LC_MESSAGES/libgnomeprintui-2.2.mo', '/usr/share/locale/fr/LC_MESSAGES/gnome-vfs-2.0.mo', '/usr/share/locale/fr/LC_MESSAGES/GConf2.mo', '/usr/share/locale/fr/LC_MESSAGES/redhat-menus.mo', '/usr/share/locale/fr/LC_MESSAGES/libgnome-2.0.mo', '/usr/share/locale/fr/LC_MESSAGES/libgnomeprint-2.2.mo', '/usr/share/locale/fr/LC_MESSAGES/gtk20-properties.mo', '/usr/share/locale/fr/LC_MESSAGES/gtk20.mo', '/usr/share/locale/fr/LC_MESSAGES/gal-2.2.mo', '/usr/share/locale/fr/LC_MESSAGES/evolution-data-server-1.0.mo', '/usr/share/locale/fr/LC_MESSAGES/libbonobo-2.0.mo', '/usr/share/locale/fr/LC_MESSAGES/atk10.mo', '/usr/share/locale/fr/LC_MESSAGES/e2fsprogs.mo', '/usr/share/locale/fr/LC_MESSAGES/libgnomeui-2.0.mo', '/usr/share/locale/fr/LC_MESSAGES/libgnomecanvas-2.0.mo', '/usr/share/locale/fr/LC_MESSAGES/gnome-pilot.mo', '/usr/share/locale/fr/LC_MESSAGES/glib20.mo', '/usr/share/locale/fr/LC_MESSAGES/gnome-spell-1.0.5.mo'] So hopefully this gives us a start from which, given a package, we can easily locate all of the translation files that might affect its UI. Dave [1] together with some minor layout fixes to wrap comments at 80 columns, assuming an 8-space tab width, and usage of the correct exception class [2] this list doesn't include the package itself; maybe it should?
Index: dogtail/distro.py =================================================================== RCS file: /cvs/gnome/dogtail/dogtail/distro.py,v retrieving revision 1.4 diff -u -p -r1.4 distro.py --- dogtail/distro.py 7 Oct 2005 23:41:09 -0000 1.4 +++ dogtail/distro.py 20 Oct 2005 05:30:05 -0000 @@ -18,7 +18,22 @@ class PackageDb: Method to get the version of an installed package as a Version instance (or raise an exception if not found) Note: does not know about distributions' internal revision numbers. """ - raise NotImplemented + raise NotImplementedError + + def getFiles(self, packageName): + """ + Method to get a list of filenames owned by the package, or + raise an exception if not found. + """ + raise NotImplementedError + + def getDependencies(self, packageName): + """ + Method to get a list of unique package names that this package + is dependent on, or raise an exception if the package is not + found. + """ + raise NotImplementedError class Distro: """ @@ -56,7 +71,9 @@ class Conary(Distro): def __makeRpmPackageDb(): """ - Manufacture a PackageDb for an RPM system. We hide this inside a factory method so that we only import the RPM Python bindings if we're on a platform likely to have them + Manufacture a PackageDb for an RPM system. We hide this inside a + factory method so that we only import the RPM Python bindings if we're + on a platform likely to have them """ class RpmPackageDb(PackageDb): def getVersion(self, packageName): @@ -65,9 +82,40 @@ def __makeRpmPackageDb(): for header in ts.dbMatch("name", packageName): return Version.fromString(header["version"]) raise "Package not found: %s"%packageName + + def getFiles(self, packageName): + import rpm + ts = rpm.TransactionSet() + for header in ts.dbMatch("name", packageName): + return header["filenames"] + raise "Package not found: %s"%packageName + + def getDependencies(self, packageName): + import rpm + ts = rpm.TransactionSet() + for header in ts.dbMatch("name", packageName): + # Simulate a set using a hash (to a dummy value); + # sets were only added in Python 2.4 + result = {} + + # Get the list of requirements; these are + # sometimes package names, but can also be + # so-names of libraries, and invented virtual + # ids + for requirement in header[rpm.RPMTAG_REQUIRES]: + # Get the name of the package providing + # this requirement: + for depPackageHeader in ts.dbMatch("provides", requirement): + depName = depPackageHeader['name'] + if depName!=packageName: + # Add to the Hash with a dummy value + result[depName]=None + return result.keys() + raise "Package not found: %s"%packageName + return RpmPackageDb() -PATCH_MESSAGE = "Please send patches to the mailing list." # FIXME: add mailing list address +PATCH_MESSAGE = "Please send patches to dogtail-devel-list gnome org" def __makeAptPackageDb(): """
Attachment:
i18n-test.py
Description: application/python