13 commits - liveusb-creator.spec liveusb/gui.py liveusb/__init__.py liveusb/linux_dialog.py liveusb/windows_dialog.py Makefile MANIFEST.in po/mki18n.py README.txt setup.py

Luke Macken lmacken at fedoraproject.org
Thu Sep 25 22:33:04 UTC 2008


 MANIFEST.in               |    2 
 Makefile                  |   17 +
 README.txt                |   43 +---
 liveusb-creator.spec      |   32 ++-
 liveusb/__init__.py       |   13 +
 liveusb/gui.py            |   14 -
 liveusb/linux_dialog.py   |    2 
 liveusb/windows_dialog.py |    2 
 po/mki18n.py              |  453 ++++++++++++++++++++++++++++++++++++++++++++++
 setup.py                  |   26 +-
 10 files changed, 546 insertions(+), 58 deletions(-)

New commits:
commit f969a99dc809978f8a20f87458ec37d774f6bd1f
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 18:32:59 2008 -0400

    Update our setup.py to include our locales

diff --git a/setup.py b/setup.py
index 80c9a37..dc56ec9 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,16 @@
 from distutils.core import setup
-import sys
+import sys, os
+
+LOCALE_DIR= '/usr/share/locale'
+
+locales = []
+if os.path.exists('po/locale'):
+    for lang in os.listdir('po/locale'):
+        locales.append(os.path.join(lang, 'LC_MESSAGES'))
+
 if sys.platform == 'win32':
     import py2exe
+    LOCALE_DIR = 'locale'
 
     setup(
         name = 'liveusb-creator',
@@ -37,13 +46,15 @@ if sys.platform == 'win32':
                 "tools/7z.dll",
                 "tools/7zCon.sfx",
                 "tools/7-Zip-License.txt",
-            ])
-        ]
+            ],)
+          ] + [(os.path.join(LOCALE_DIR, locale),
+                [os.path.join('po', 'locale', locale, 'liveusb-creator.mo')])
+                for locale in locales]
     )
 else:
     setup(
         name = 'liveusb-creator',
-        version = '2.7',
+        version = '3.0',
         packages = ['liveusb', 'liveusb/urlgrabber'],
         scripts = ['liveusb-creator'],
         license = 'GNU General Public License (GPL)',
@@ -54,8 +65,9 @@ else:
         maintainer = 'Luke Macken',
         maintainer_email = 'lmacken at redhat.com',
         data_files = [("/usr/share/applications",["data/liveusb-creator.desktop"]), 
-                      ('/usr/share/pixmaps',["data/fedorausb.png"])
-                      ]
-        
+                      ('/usr/share/pixmaps',["data/fedorausb.png"]),
+                      ] + [(os.path.join(LOCALE_DIR, locale),
+                            [os.path.join('po', 'locale', locale, 'liveusb-creator.mo')])
+                            for locale in locales]
         )
 


commit 1b0a5a474881ab6b01c0c96d2c91b12c4db1756d
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 18:31:03 2008 -0400

    Encode our translated GUI strings to UTF8 bytestrings before sending to PyQt4

diff --git a/liveusb/__init__.py b/liveusb/__init__.py
index e819b15..66ff9e8 100644
--- a/liveusb/__init__.py
+++ b/liveusb/__init__.py
@@ -28,6 +28,10 @@ else:
                                       fallback=True)
 _ = translation.ugettext
 
+def utf8_gettext(string):
+    " Translate string, converting it to a UTF-8 encoded bytestring "
+    return _(string).encode('utf8')
+
 from liveusb.creator import LiveUSBError
 
 if sys.platform == "win32":
@@ -40,4 +44,4 @@ else:
     from liveusb.creator import LinuxLiveUSBCreator as LiveUSBCreator
     from liveusb.linux_dialog import Ui_Dialog as LiveUSBInterface
 
-__all__ = ("LiveUSBCreator", "LiveUSBError", "LiveUSBDialog", "_")
+__all__ = ("LiveUSBCreator", "LiveUSBError", "LiveUSBDialog", "_", "utf8_gettext")
diff --git a/liveusb/linux_dialog.py b/liveusb/linux_dialog.py
index 04c454e..cf11adb 100644
--- a/liveusb/linux_dialog.py
+++ b/liveusb/linux_dialog.py
@@ -8,7 +8,7 @@
 # WARNING! All changes made in this file will be lost!
 
 from PyQt4 import QtCore, QtGui
-from liveusb import _
+from liveusb import utf8_gettext as _
 
 class Ui_Dialog(object):
     def setupUi(self, Dialog):
diff --git a/liveusb/windows_dialog.py b/liveusb/windows_dialog.py
index c74df2f..d9e28c8 100644
--- a/liveusb/windows_dialog.py
+++ b/liveusb/windows_dialog.py
@@ -8,7 +8,7 @@
 # WARNING! All changes made in this file will be lost!
 
 from PyQt4 import QtCore, QtGui
-from liveusb import _
+from liveusb import utf8_gettext as _
 
 class Ui_Dialog(object):
     def setupUi(self, Dialog):


commit 3332249b56509e0f610795c4c3adbdd2f8c84422
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 18:26:06 2008 -0400

    Ensure we're dealing with UTF8 bytestrings when displaying exception messages.

diff --git a/liveusb/gui.py b/liveusb/gui.py
index 00f4c82..e37f1fd 100755
--- a/liveusb/gui.py
+++ b/liveusb/gui.py
@@ -185,10 +185,10 @@ class LiveUSBThread(QtCore.QThread):
             duration = str(datetime.now() - now).split('.')[0]
             self.status(_("Complete! (%s)" % duration))
         except LiveUSBError, e:
-            self.status(str(e))
+            self.status(e.message)
             self.status(_("LiveUSB creation failed!"))
         except Exception, e:
-            self.status(str(e))
+            self.status(e.message)
             self.status(_("LiveUSB creation failed!"))
             import traceback
             traceback.print_exc()
@@ -237,7 +237,7 @@ class LiveUSBDialog(QtGui.QDialog, LiveUSBInterface):
                     self.driveBox.addItem(device)
             self.startButton.setEnabled(True)
         except LiveUSBError, e:
-            self.textEdit.setPlainText(str(e))
+            self.textEdit.setPlainText(e.message.encode('utf8'))
             self.startButton.setEnabled(False)
 
     def populate_releases(self):
@@ -302,7 +302,7 @@ class LiveUSBDialog(QtGui.QDialog, LiveUSBInterface):
         self.progressBar.setMaximum(value)
 
     def status(self, text):
-        self.textEdit.append(text)
+        self.textEdit.append(text.encode('utf8', 'replace'))
 
     def enable_widgets(self, enabled=True):
         self.startButton.setEnabled(enabled)
@@ -326,7 +326,7 @@ class LiveUSBDialog(QtGui.QDialog, LiveUSBInterface):
         try:
             self.live.mount_device()
         except LiveUSBError, e:
-            self.status(str(e))
+            self.status(e.message)
             self.enable_widgets(True)
             return 
 
@@ -351,7 +351,7 @@ class LiveUSBDialog(QtGui.QDialog, LiveUSBInterface):
                 try:
                     self.live.delete_liveos()
                 except LiveUSBError, e:
-                    self.status(str(e))
+                    self.status(e.message)
                     self.live.unmount_device()
                     self.enable_widgets(True)
                     return
@@ -396,7 +396,7 @@ class LiveUSBDialog(QtGui.QDialog, LiveUSBInterface):
             try:
                 self.live.iso = self._to_unicode(isofile)
             except Exception, e:
-                self.live.log.error(str(e))
+                self.live.log.error(e.message.encode('utf8'))
                 self.status(_("Sorry, I'm having trouble encoding the filename "
                               "of your livecd.  You may have better luck if "
                               "you move your ISO to the root of your drive "


commit 7a8cb6813ce3f0b6d23d3701e1082f2d502e12bd
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 18:25:34 2008 -0400

    Dynamically determine our locale directory

diff --git a/liveusb/__init__.py b/liveusb/__init__.py
index 9a71779..e819b15 100644
--- a/liveusb/__init__.py
+++ b/liveusb/__init__.py
@@ -21,8 +21,11 @@ import os
 import sys
 import gettext
 
-translation = gettext.translation('liveusb-creator', '/usr/share/locale',
-                                  fallback=True)
+if os.path.exists('locale'):
+    translation = gettext.translation('liveusb-creator', 'locale', fallback=True)
+else:
+    translation = gettext.translation('liveusb-creator', '/usr/share/locale',
+                                      fallback=True)
 _ = translation.ugettext
 
 from liveusb.creator import LiveUSBError


commit 010f4f3fe9295d67d78024f504ef2f8f193d0d5c
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 18:24:55 2008 -0400

    Update our RPM spec to handle the new translations

diff --git a/liveusb-creator.spec b/liveusb-creator.spec
index 7782fd2..880cb24 100644
--- a/liveusb-creator.spec
+++ b/liveusb-creator.spec
@@ -1,18 +1,18 @@
 %{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
 
 Name:           liveusb-creator
-Version:        2.7
+Version:        3.0
 Release:        1%{?dist}
 Summary:        A liveusb creator
 
 Group:          Applications/System
 License:        GPLv2
 URL:            https://fedorahosted.org/liveusb-creator
-Source0:        https://fedorahosted.org/releases/l/i/liveusb-creator/%{name}-linux-%{version}.tar.gz
+Source0:        https://fedorahosted.org/releases/l/i/liveusb-creator/%{name}-%{version}.tar.bz2
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 BuildArch:      noarch
-BuildRequires:  python-devel, python-setuptools, PyQt4-devel, desktop-file-utils
+BuildRequires:  python-devel, python-setuptools, PyQt4-devel, desktop-file-utils gettext
 Requires:       syslinux, PyQt4, usermode
 
 %description
@@ -21,10 +21,9 @@ A liveusb creator from Live Fedora images
 %prep
 %setup -q
 
-
 %build
 %{__python} setup.py build
-
+make mo
 
 %install
 rm -rf %{buildroot}
@@ -40,25 +39,38 @@ mkdir -p %{buildroot}%{_sysconfdir}/security/console.apps
 cp %{name}.console %{buildroot}%{_sysconfdir}/security/console.apps/%{name}
 
 desktop-file-install --vendor="fedora"                    \
---dir=${buildroot}%{_datadir}/applications           \
+--dir=%{buildroot}%{_datadir}/applications           \
 %{buildroot}/%{_datadir}/applications/liveusb-creator.desktop
 rm -rf %{buildroot}/%{_datadir}/applications/liveusb-creator.desktop
 
+%find_lang %{name}
+
 %clean
 rm -rf %{buildroot}
 
-
 %files
 %defattr(-,root,root,-)
 %doc README.txt LICENSE.txt
 # For noarch packages: sitelib
 %{python_sitelib}/*
-%{_bindir}/*
-%{_sbindir}/*
-%{_datadir}/*
+%{_bindir}/%{name}
+%{_sbindir}/%{name}
+%{_datadir}/applications/fedora-liveusb-creator.desktop
+%{_datadir}/pixmaps/fedorausb.png
+%{_datadir}/locale/*/LC_MESSAGES/liveusb-creator.mo
 %config(noreplace) %{_sysconfdir}/pam.d/%{name}
 %config(noreplace) %{_sysconfdir}/security/console.apps/%{name}
 
 %changelog
+* Fri Aug 29 2008 Luke Macken <lmacken at redhat.com> 3.0-1
+- Latest upstream release, containing various bugfixes
+- Add Fedora 10 Alpha support
+- Brazilian Portuguese translation (Igor Pires Soares)
+- Spanish translation (Domingo Becker)
+- Malay translation (Sharuzzaman Ahmat Raslan)
+- German Translation (Marcus Nitzschke, Fabian Affolter)
+- Polish translation (Piotr DrÄ…g)
+- Portuguese translation (Valter Fukuoka)
+
 * Tue Aug 12 2008 Kushal Das <kushal at fedoraproject.org> 2.7-1
 - Initial release


commit a36db752e0f287bdc6312ee421eb03cfafc1e36c
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 18:24:30 2008 -0400

    Update our 'mo' Makefile target

diff --git a/Makefile b/Makefile
index c0d1e78..f46ca66 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,9 @@ pot:
 	#cd po ; intltool-update --pot -g liveusb-creator
 
 mo:
+	cd po; for po in `ls *.po`; do cp $$po liveusb-creator_$$po; done
 	cd po; python mki18n.py -v --domain=liveusb-creator -m
+	rm po/liveusb-creator_*.po*
 
 clean:
 	rm -f *.py{c,o} */*.py{c,o} */*/*.py{c,o}


commit 1a5880d307236234b984e8138843595f50a13037
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 18:24:12 2008 -0400

    Add an 'rpm' Makefile target

diff --git a/Makefile b/Makefile
index deb1c7b..c0d1e78 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,11 @@ dist:
 srpm: dist
 	@rpmbuild -bs ${PKGRPMFLAGS} ${PKGNAME}.spec
 
+rpm: dist
+	cp dist/* ~/rpmbuild/SOURCES/
+	cp *.spec ~/rpmbuild/SPECS/
+	rpmbuild -ba ~/rpmbuild/SPECS/liveusb-creator.spec
+
 gui:
 	pyrcc4 data/resources.qrc -o liveusb/resources_rc.py
 	pyuic4 data/liveusb-creator.ui -o liveusb/windows_dialog.py


commit 9af1e5cb19986532d34a776d46299659225df3ed
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 18:23:54 2008 -0400

    Update our MANIFEST.in with some new files

diff --git a/MANIFEST.in b/MANIFEST.in
index 840d87e..5d3efd5 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,4 +1,5 @@
 include README.txt
+include Makefile
 include LICENSE.txt
 include liveusb-creator
 include setup.py
@@ -19,3 +20,4 @@ include data/fedorausb.png
 include liveusb-creator.console
 include liveusb-creator.pam
 include po/*.po
+include po/mki18n.py


commit 36f175af09520a2fa76c7787c3b9f86f2cab6b29
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 16:37:08 2008 -0400

    Add a 'mo' and 'clean' Makefile targets

diff --git a/Makefile b/Makefile
index adf52a9..deb1c7b 100644
--- a/Makefile
+++ b/Makefile
@@ -19,4 +19,12 @@ pylint:
 	pylint liveusb/*.py
 
 pot:
-	cd po ; intltool-update --pot -g liveusb-creator
+	cd po; python mki18n.py -v --domain=liveusb-creator -p
+	#cd po ; intltool-update --pot -g liveusb-creator
+
+mo:
+	cd po; python mki18n.py -v --domain=liveusb-creator -m
+
+clean:
+	rm -f *.py{c,o} */*.py{c,o} */*/*.py{c,o}
+	rm -fr po/${PKGNAME}*.po{,.new} po/locale


commit f25b556f959ce4d1ea86ce04992abac9595990f0
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 16:36:39 2008 -0400

    Update our README

diff --git a/README.txt b/README.txt
index 8a0ed2f..a576a0e 100644
--- a/README.txt
+++ b/README.txt
@@ -1,45 +1,32 @@
+===============
 liveusb-creator
 ===============
 
-This tool installs a Fedora LiveCD ISO on to a USB stick.
+A cross-platform tool for easily installing live operating systems on to USB
+flash drives.
 
 Using
-=====
-
-    See the wiki for instructions on how to use the liveusb-creator:
-
-        https://fedorahosted.org/liveusb-creator
+-----
+See the wiki for instructions on how to use the liveusb-creator:
 
+    https://fedorahosted.org/liveusb-creator
 
 Developing
-==========
-
-  In Windows
-  ----------
-  o Get the latest code
-
-        http://git.fedoraproject.org/git/liveusb-creator?p=liveusb-creator.git;a=snapshot;h=HEAD;sf=tgz
-
-  o Install Python2.5, PyQt4, and py2exe
-
-  o Compiling an exe:
-
-        python -OO setup.py py2exe
-
-  o If you change the QtDesigner ui file, you can compile it by doing:
-
-        pyuic4 data\liveusb-creator.ui -o liveusb\dialog.py
-
-  o If you add more PyQt resources (pixmaps, icons, etc), you can rebuild
-    the resources module by running:
-
-        pyrcc4 data\resources.qrc -o liveusb\resources_rc.py
+----------
+See the Developers Guide on the wiki for details,
 
+        https://fedorahosted.org/liveusb-creator/wiki/Development
 
 ================================================================================
 
 This tool is distributed with the following open source software
 
+   Python
+   http://python.org
+
+   PyQt4
+   http://wiki.python.org/moin/PyQt4
+
    7-Zip
    http://www.7-zip.org
    Copyright (C) 1999-2007 Igor Pavlov.


commit d104d0b8aa8f8716d9b6b5b266d3a8fd561cca46
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 16:35:10 2008 -0400

    Return 0 upon success, to make `make` happy.

diff --git a/po/mki18n.py b/po/mki18n.py
index 20c5a7e..2cee12d 100644
--- a/po/mki18n.py
+++ b/po/mki18n.py
@@ -450,7 +450,4 @@ if __name__ == "__main__":
             printUsage(e[1] + '\n   You must write a file app.fil that contains the list of all files to parse.')
     if option['mo']:
         makeMO(appDirPath,option['moTarget'],option['domain'],option['verbose'],option['forceEnglish'])
-    sys.exit(1)            
-            
-
-# -----------------------------------------------------------------------------
+    sys.exit(0)


commit 8490ff3b5a56e20be15232c86a31b5ff63c6964c
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 16:34:43 2008 -0400

    Instead of scraping the wx module for language names, lets just use whatever po
    files are in the current directory.  Transifex takes care of putting new languages
    there for us already.

diff --git a/po/mki18n.py b/po/mki18n.py
index 9ab7bf0..20c5a7e 100644
--- a/po/mki18n.py
+++ b/po/mki18n.py
@@ -80,26 +80,26 @@ You can get the gettext tools from the following sites:
 # 
 import os
 import sys
-import wx
-# -----------------------------------------------------------------------------
-# Global variables
-# ----------------
-#
 
-__author__ = "Pierre Rouleau"
-__version__= "$Revision: 1.5 $"
 
-# -----------------------------------------------------------------------------
+# Instead of scraping the wx module for language names, lets just use whatever po
+# files are in the current directory.  Transifex takes care of putting new languages
+# there for us already.
+# def getlanguageDict():
+#     import wx
+#     languageDict = {}
+# 
+#     for lang in [x for x in dir(wx) if x.startswith("LANGUAGE")]:
+#         i = wx.Locale(wx.LANGUAGE_DEFAULT).GetLanguageInfo(getattr(wx, lang))
+#         if i:
+#             languageDict[i.CanonicalName] = i.Description
+# 
+#     return languageDict
 
 def getlanguageDict():
-    languageDict = {}
-    
-    for lang in [x for x in dir(wx) if x.startswith("LANGUAGE")]:
-        i = wx.Locale(wx.LANGUAGE_DEFAULT).GetLanguageInfo(getattr(wx, lang))
-        if i:
-            languageDict[i.CanonicalName] = i.Description
-
-    return languageDict
+    #return dict([(lang, None) for lang in LANGUAGES])
+    # lang.po from our current directory!
+    return dict([(lang, None) for lang in ['.'.join(po.split('.')[:-1]) for po in os.listdir('.') if po.endswith('.po')]])
 
 # -----------------------------------------------------------------------------
 # m a k e P O ( )         -- Build the Portable Object file for the application --


commit 06468b92365324b51204c3539d394a90bbf77ccc
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Sep 25 16:33:53 2008 -0400

    Add mki18n.py to help with our internationalization.
    
    Trying hard to avoid autotools crackrock at all costs.

diff --git a/po/mki18n.py b/po/mki18n.py
new file mode 100644
index 0000000..9ab7bf0
--- /dev/null
+++ b/po/mki18n.py
@@ -0,0 +1,456 @@
+#! /usr/bin/env python
+# -*- coding: iso-8859-1 -*-
+# 
+#   PYTHON MODULE:     MKI18N.PY
+#                      =========
+# 
+#   Abstract:         Make Internationalization (i18n) files for an application.
+# 
+#   Copyright Pierre Rouleau. 2003. Released to public domain.
+# 
+#   Last update: Saturday, November 8, 2003. @ 15:55:18.
+# 
+#   File: ROUP2003N01::C:/dev/python/mki18n.py
+# 
+#   RCS $Header: //software/official/MKS/MKS_SI/TV_NT/dev/Python/rcs/mki18n.py 1.5 2003/11/05 19:40:04 PRouleau Exp $
+# 
+#   Update history:
+# 
+#   - File created: Saturday, June 7, 2003. by Pierre Rouleau
+#   - 10/06/03 rcs : RCS Revision 1.1  2003/06/10 10:06:12  PRouleau
+#   - 10/06/03 rcs : RCS Initial revision
+#   - 23/08/03 rcs : RCS Revision 1.2  2003/06/10 10:54:27  PRouleau
+#   - 23/08/03 P.R.: [code:fix] : The strings encoded in this file are encode in iso-8859-1 format.  Added the encoding
+#                    notification to Python to comply with Python's 2.3 PEP 263.
+#   - 23/08/03 P.R.: [feature:new] : Added the '-e' switch which is used to force the creation of the empty English .mo file.
+#   - 22/10/03 P.R.: [code] : incorporated utility functions in here to make script self sufficient.
+#   - 05/11/03 rcs : RCS Revision 1.4  2003/10/22 06:39:31  PRouleau
+#   - 05/11/03 P.R.: [code:fix] : included the unixpath() in this file.
+#   - 08/11/03 rcs : RCS Revision 1.5  2003/11/05 19:40:04  PRouleau
+# 
+#   RCS $Log: $
+# 
+# 
+# -----------------------------------------------------------------------------
+"""                                
+mki18n allows you to internationalize your software.  You can use it to 
+create the GNU .po files (Portable Object) and the compiled .mo files
+(Machine Object).
+
+mki18n module can be used from the command line or from within a script (see 
+the Usage at the end of this page).
+
+    Table of Contents
+    -----------------
+    
+    makePO()             -- Build the Portable Object file for the application --
+    catPO()              -- Concatenate one or several PO files with the application domain files. --
+    makeMO()             -- Compile the Portable Object files into the Machine Object stored in the right location. --
+    printUsage           -- Displays how to use this script from the command line --
+
+    Scriptexecution      -- Runs when invoked from the command line --
+
+
+NOTE:  this module uses GNU gettext utilities.
+
+You can get the gettext tools from the following sites:
+
+   - `GNU FTP site for gettetx`_ where several versions (0.10.40, 0.11.2, 0.11.5 and 0.12.1) are available.
+     Note  that you need to use `GNU libiconv`_ to use this. Get it from the `GNU
+     libiconv  ftp site`_ and get version 1.9.1 or later. Get the Windows .ZIP
+     files and install the packages inside c:/gnu. All binaries will be stored
+     inside  c:/gnu/bin.  Just  put c:/gnu/bin inside your PATH. You will need
+     the following files: 
+
+      - `gettext-runtime-0.12.1.bin.woe32.zip`_ 
+      - `gettext-tools-0.12.1.bin.woe32.zip`_
+      - `libiconv-1.9.1.bin.woe32.zip`_ 
+
+
+.. _GNU libiconv:                            http://www.gnu.org/software/libiconv/
+.. _GNU libiconv ftp site:                   http://www.ibiblio.org/pub/gnu/libiconv/
+.. _gettext-runtime-0.12.1.bin.woe32.zip:    ftp://ftp.gnu.org/gnu/gettext/gettext-runtime-0.12.1.bin.woe32.zip           
+.. _gettext-tools-0.12.1.bin.woe32.zip:      ftp://ftp.gnu.org/gnu/gettext/gettext-tools-0.12.1.bin.woe32.zip 
+.. _libiconv-1.9.1.bin.woe32.zip:            http://www.ibiblio.org/pub/gnu/libiconv/libiconv-1.9.1.bin.woe32.zip
+
+"""
+# -----------------------------------------------------------------------------
+# Module Import
+# -------------
+# 
+import os
+import sys
+import wx
+# -----------------------------------------------------------------------------
+# Global variables
+# ----------------
+#
+
+__author__ = "Pierre Rouleau"
+__version__= "$Revision: 1.5 $"
+
+# -----------------------------------------------------------------------------
+
+def getlanguageDict():
+    languageDict = {}
+    
+    for lang in [x for x in dir(wx) if x.startswith("LANGUAGE")]:
+        i = wx.Locale(wx.LANGUAGE_DEFAULT).GetLanguageInfo(getattr(wx, lang))
+        if i:
+            languageDict[i.CanonicalName] = i.Description
+
+    return languageDict
+
+# -----------------------------------------------------------------------------
+# m a k e P O ( )         -- Build the Portable Object file for the application --
+# ^^^^^^^^^^^^^^^
+#
+def makePO(applicationDirectoryPath,  applicationDomain=None, verbose=0) :
+    """Build the Portable Object Template file for the application.
+
+    makePO builds the .pot file for the application stored inside 
+    a specified directory by running xgettext for all application source 
+    files.  It finds the name of all files by looking for a file called 'app.fil'. 
+    If this file does not exists, makePo raises an IOError exception.
+    By default the application domain (the application
+    name) is the same as the directory name but it can be overridden by the
+    'applicationDomain' argument.
+
+    makePO always creates a new file called messages.pot.  If it finds files 
+    of the form app_xx.po where 'app' is the application name and 'xx' is one 
+    of the ISO 639 two-letter language codes, makePO resynchronizes those 
+    files with the latest extracted strings (now contained in messages.pot). 
+    This process updates all line location number in the language-specific
+    .po files and may also create new entries for translation (or comment out 
+    some).  The .po file is not changed, instead a new file is created with 
+    the .new extension appended to the name of the .po file.
+
+    By default the function does not display what it is doing.  Set the 
+    verbose argument to 1 to force it to print its commands.
+    """
+
+    if applicationDomain is None:
+        applicationName = fileBaseOf(applicationDirectoryPath,withPath=0)
+    else:
+        applicationName = applicationDomain
+    currentDir = os.getcwd()
+    os.chdir(applicationDirectoryPath)                    
+    if not os.path.exists('app.fil'):
+        raise IOError(2,'No module file: app.fil')
+
+    # Steps:                                  
+    #  Use xgettext to parse all application modules
+    #  The following switches are used:
+    #  
+    #   -s                          : sort output by string content (easier to use when we need to merge several .po files)
+    #   --files-from=app.fil        : The list of files is taken from the file: app.fil
+    #   --output=                   : specifies the name of the output file (using a .pot extension)
+    cmd = 'xgettext -s --no-wrap --files-from=app.fil --output=messages.pot'
+    if verbose: print cmd
+    os.system(cmd)                                                
+
+    languageDict = getlanguageDict()
+
+    for langCode in languageDict.keys():
+        if langCode == 'en':
+            pass
+        else:
+            langPOfileName = "%s_%s.po" % (applicationName , langCode)
+            if os.path.exists(langPOfileName):
+                cmd = 'msgmerge -s --no-wrap "%s" messages.pot > "%s.new"' % (langPOfileName, langPOfileName)
+                if verbose: print cmd
+                os.system(cmd)
+    os.chdir(currentDir)
+
+# -----------------------------------------------------------------------------
+# c a t P O ( )         -- Concatenate one or several PO files with the application domain files. --
+# ^^^^^^^^^^^^^
+#
+def catPO(applicationDirectoryPath, listOf_extraPo, applicationDomain=None, targetDir=None, verbose=0) :
+    """Concatenate one or several PO files with the application domain files.
+    """
+
+    if applicationDomain is None:
+        applicationName = fileBaseOf(applicationDirectoryPath,withPath=0)
+    else:
+        applicationName = applicationDomain
+    currentDir = os.getcwd()
+    os.chdir(applicationDirectoryPath)
+
+    languageDict = getlanguageDict()
+
+    for langCode in languageDict.keys():
+        if langCode == 'en':
+            pass
+        else:
+            langPOfileName = "%s_%s.po" % (applicationName , langCode)
+            if os.path.exists(langPOfileName):
+                fileList = ''
+                for fileName in listOf_extraPo:
+                    fileList += ("%s_%s.po " % (fileName,langCode))
+                cmd = "msgcat -s --no-wrap %s %s > %s.cat" % (langPOfileName, fileList, langPOfileName)
+                if verbose: print cmd
+                os.system(cmd)
+                if targetDir is None:
+                    pass
+                else:
+                    mo_targetDir = "%s/%s/LC_MESSAGES" % (targetDir,langCode)
+                    cmd = "msgfmt --output-file=%s/%s.mo %s_%s.po.cat" % (mo_targetDir,applicationName,applicationName,langCode)
+                    if verbose: print cmd
+                    os.system(cmd)
+    os.chdir(currentDir)
+
+# -----------------------------------------------------------------------------
+# m a k e M O ( )         -- Compile the Portable Object files into the Machine Object stored in the right location. --
+# ^^^^^^^^^^^^^^^
+# 
+def makeMO(applicationDirectoryPath,targetDir='./locale',applicationDomain=None, verbose=0, forceEnglish=0) :
+    """Compile the Portable Object files into the Machine Object stored in the right location.
+
+    makeMO converts all translated language-specific PO files located inside 
+    the  application directory into the binary .MO files stored inside the 
+    LC_MESSAGES sub-directory for the found locale files.
+
+    makeMO searches for all files that have a name of the form 'app_xx.po' 
+    inside the application directory specified by the first argument.  The 
+    'app' is the application domain name (that can be specified by the 
+    applicationDomain argument or is taken from the directory name). The 'xx' 
+    corresponds to one of the ISO 639 two-letter language codes.
+
+    makeMo stores the resulting files inside a sub-directory of `targetDir`
+    called xx/LC_MESSAGES where 'xx' corresponds to the 2-letter language
+    code.
+    """
+    if targetDir is None:
+        targetDir = './locale'
+    if verbose:
+        print "Target directory for .mo files is: %s" % targetDir
+
+    if applicationDomain is None:
+        applicationName = fileBaseOf(applicationDirectoryPath,withPath=0)
+    else:
+        applicationName = applicationDomain
+    currentDir = os.getcwd()
+    os.chdir(applicationDirectoryPath)
+
+    languageDict = getlanguageDict()
+
+    for langCode in languageDict.keys():
+        if (langCode == 'en') and (forceEnglish==0):
+            pass
+        else:
+            langPOfileName = "%s_%s.po" % (applicationName , langCode)
+            if os.path.exists(langPOfileName):
+                mo_targetDir = "%s/%s/LC_MESSAGES" % (targetDir,langCode) 
+                if not os.path.exists(mo_targetDir):
+                    mkdir(mo_targetDir)
+                cmd = 'msgfmt --output-file="%s/%s.mo" "%s_%s.po"' % (mo_targetDir,applicationName,applicationName,langCode)
+                if verbose: print cmd
+                os.system(cmd)
+            #else: print "%s does not exist" % langPOfileName
+    os.chdir(currentDir)
+   
+# -----------------------------------------------------------------------------
+# p r i n t U s a g e         -- Displays how to use this script from the command line --
+# ^^^^^^^^^^^^^^^^^^^
+#
+def printUsage(errorMsg=None) :
+    """Displays how to use this script from the command line."""
+    print """
+    ##################################################################################
+    #   mki18n :   Make internationalization files.                                  #
+    #              Uses the GNU gettext system to create PO (Portable Object) files  #
+    #              from source code, coimpile PO into MO (Machine Object) files.     #
+    #              Supports C,C++,Python source files.                               #
+    #                                                                                #
+    #   Usage: mki18n {OPTION} [appDirPath]                                          #
+    #                                                                                #
+    #   Options:                                                                     #
+    #     -e               : When -m is used, forces English .mo file creation       #
+    #     -h               : prints this help                                        #
+    #     -m               : make MO from existing PO files                          #
+    #     -p               : make PO, update PO files: Creates a new messages.pot    #
+    #                        file. Creates a dom_xx.po.new for every existing        #
+    #                        language specific .po file. ('xx' stands for the ISO639 #
+    #                        two-letter language code and 'dom' stands for the       #
+    #                        application domain name).  mki18n requires that you     #
+    #                        write a 'app.fil' file  which contains the list of all  #
+    #                        source code to parse.                                   #
+    #     -v               : verbose (prints comments while running)                 #
+    #     --domain=appName : specifies the application domain name.  By default      #
+    #                        the directory name is used.                             #
+    #     --moTarget=dir : specifies the directory where .mo files are stored.       #
+    #                      If not specified, the target is './locale'                #
+    #                                                                                #
+    #   You must specify one of the -p or -m option to perform the work.  You can    #
+    #   specify the path of the target application.  If you leave it out mki18n      #
+    #   will use the current directory as the application main directory.            #        
+    #                                                                                #
+    ##################################################################################"""
+    if errorMsg:
+        print "\n   ERROR: %s" % errorMsg
+
+# -----------------------------------------------------------------------------
+# f i l e B a s e O f ( )         -- Return base name of filename --
+# ^^^^^^^^^^^^^^^^^^^^^^^
+# 
+def fileBaseOf(filename,withPath=0) :
+   """fileBaseOf(filename,withPath) ---> string
+
+   Return base name of filename.  The returned string never includes the extension.
+   Use os.path.basename() to return the basename with the extension.  The 
+   second argument is optional.  If specified and if set to 'true' (non zero) 
+   the string returned contains the full path of the file name.  Otherwise the 
+   path is excluded.
+
+   [Example]
+   >>> fn = 'd:/dev/telepath/tvapp/code/test.html'
+   >>> fileBaseOf(fn)
+   'test'
+   >>> fileBaseOf(fn)
+   'test'
+   >>> fileBaseOf(fn,1)
+   'd:/dev/telepath/tvapp/code/test'
+   >>> fileBaseOf(fn,0)
+   'test'
+   >>> fn = 'abcdef'
+   >>> fileBaseOf(fn)
+   'abcdef'
+   >>> fileBaseOf(fn,1)
+   'abcdef'
+   >>> fn = "abcdef."
+   >>> fileBaseOf(fn)
+   'abcdef'
+   >>> fileBaseOf(fn,1)
+   'abcdef'
+   """            
+   pos = filename.rfind('.')             
+   if pos > 0:
+      filename = filename[:pos]
+   if withPath:
+      return filename
+   else:
+      return os.path.basename(filename)
+# -----------------------------------------------------------------------------
+# m k d i r ( )         -- Create a directory (and possibly the entire tree) --
+# ^^^^^^^^^^^^^
+# 
+def mkdir(directory) :
+   """Create a directory (and possibly the entire tree).
+
+   The os.mkdir() will fail to create a directory if one of the
+   directory in the specified path does not exist.  mkdir()
+   solves this problem.  It creates every intermediate directory
+   required to create the final path. Under Unix, the function 
+   only supports forward slash separator, but under Windows and MacOS
+   the function supports the forward slash and the OS separator (backslash
+   under windows).
+   """ 
+
+   # translate the path separators
+   directory = unixpath(directory)
+   # build a list of all directory elements
+   aList = filter(lambda x: len(x)>0, directory.split('/'))
+   theLen = len(aList)                     
+   # if the first element is a Windows-style disk drive
+   # concatenate it with the first directory
+   if aList[0].endswith(':'):
+      if theLen > 1:
+         aList[1] = aList[0] + '/' + aList[1]
+         del aList[0]      
+         theLen -= 1         
+   # if the original directory starts at root,
+   # make sure the first element of the list 
+   # starts at root too
+   if directory[0] == '/':     
+      aList[0] = '/' + aList[0]
+   # Now iterate through the list, check if the 
+   # directory exists and if not create it
+   theDir = ''
+   for i in range(theLen):
+      theDir += aList[i]
+      if not os.path.exists(theDir):
+         os.mkdir(theDir)
+      theDir += '/'   
+      
+# -----------------------------------------------------------------------------
+# u n i x p a t h ( )         -- Return a path name that contains Unix separator. --
+# ^^^^^^^^^^^^^^^^^^^
+# 
+def unixpath(thePath) :
+   r"""Return a path name that contains Unix separator.
+
+   [Example]
+   >>> unixpath(r"d:\test")
+   'd:/test'
+   >>> unixpath("d:/test/file.txt")
+   'd:/test/file.txt'
+   >>> 
+   """
+   thePath = os.path.normpath(thePath)
+   if os.sep == '/':
+      return thePath
+   else:
+      return thePath.replace(os.sep,'/')
+
+# ----------------------------------------------------------------------------- 
+
+# S c r i p t   e x e c u t i o n               -- Runs when invoked from the command line --
+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+# 
+if __name__ == "__main__":
+    import getopt     # command line parsing
+    argc = len(sys.argv)
+    if argc == 1:
+        printUsage('Missing argument: specify at least one of -m or -p (or both).')
+        sys.exit(1)
+    # If there is some arguments, parse the command line
+    validOptions     = "ehmpv"
+    validLongOptions = ['domain=', 'moTarget=']             
+    option = {}
+    option['forceEnglish'] = 0
+    option['mo'] = 0
+    option['po'] = 0        
+    option['verbose'] = 0
+    option['domain'] = None
+    option['moTarget'] = None
+    try:
+        optionList,pargs = getopt.getopt(sys.argv[1:],validOptions,validLongOptions)
+    except getopt.GetoptError, e:
+        printUsage(e[0])
+        sys.exit(1)       
+    for (opt,val) in optionList:
+        if  (opt == '-h'):    
+            printUsage()
+            sys.exit(0) 
+        elif (opt == '-e'):         option['forceEnglish'] = 1
+        elif (opt == '-m'):         option['mo'] = 1
+        elif (opt == '-p'):         option['po'] = 1
+        elif (opt == '-v'):         option['verbose'] = 1
+        elif (opt == '--domain'):   option['domain'] = val
+        elif (opt == '--moTarget'): option['moTarget'] = val
+    if len(pargs) == 0:
+        appDirPath = os.getcwd()
+        if option['verbose']:
+            print "No project directory given. Using current one:  %s" % appDirPath
+    elif len(pargs) == 1:
+        appDirPath = pargs[0]
+    else:
+        printUsage('Too many arguments (%u).  Use double quotes if you have space in directory name' % len(pargs))
+        sys.exit(1)
+    if option['domain'] is None:
+        # If no domain specified, use the name of the target directory
+        option['domain'] = fileBaseOf(appDirPath)
+    if option['verbose']:
+        print "Application domain used is: '%s'" % option['domain']
+    if option['po']:
+        try:
+            makePO(appDirPath,option['domain'],option['verbose'])
+        except IOError, e:
+            printUsage(e[1] + '\n   You must write a file app.fil that contains the list of all files to parse.')
+    if option['mo']:
+        makeMO(appDirPath,option['moTarget'],option['domain'],option['verbose'],option['forceEnglish'])
+    sys.exit(1)            
+            
+
+# -----------------------------------------------------------------------------




More information about the liveusb-creator mailing list