[SCM] GUI front-end for Debian Live. branch, master, updated. 01bfe15e9de19d2543322586f63218907a764f82

Chris Lamb chris at chris-lamb.co.uk
Sat Aug 9 05:29:36 UTC 2008


The following commit has been merged in the master branch:
commit 01bfe15e9de19d2543322586f63218907a764f82
Author: Chris Lamb <chris at chris-lamb.co.uk>
Date:   Sat Aug 9 06:24:32 2008 +0100

    Add gettext support.
    
    Signed-off-by: Chris Lamb <chris at chris-lamb.co.uk>

diff --git a/.gitignore b/.gitignore
index 004a8d7..df8f767 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 *.pyc
 .coverage
+mo/
diff --git a/LiveMagic/__init__.py b/LiveMagic/__init__.py
index 0091f93..34d4da2 100644
--- a/LiveMagic/__init__.py
+++ b/LiveMagic/__init__.py
@@ -19,16 +19,37 @@
 import gtk
 import pygtk
 pygtk.require('2.0')
+import gtk.glade
 
+import locale
+import gettext
 import optparse
+import __builtin__
 
 from LiveMagic import views, controllers
+from LiveMagic.utils import find_resource
 
 __version__ = '1.0'
 
+def init_gettext():
+    try:
+        locale_dir = [find_resource('mo')]
+    except ValueError:
+        # Fall back to /usr/share/locale
+        locale_dir = []
+
+    locale.setlocale(locale.LC_ALL, '')
+    for module in gettext, gtk.glade:
+        module.bindtextdomain('live-magic', *locale_dir)
+        module.textdomain('live-magic')
+
+    __builtin__._ = gettext.gettext
+
 class LiveMagic(object):
 
     def __init__(self, args):
+        init_gettext()
+
         try:
             gtk.init_check()
         except RuntimeError, e:
diff --git a/LiveMagic/controllers/build.py b/LiveMagic/controllers/build.py
index 2679f53..24b494f 100644
--- a/LiveMagic/controllers/build.py
+++ b/LiveMagic/controllers/build.py
@@ -56,17 +56,17 @@ class BuildController(object):
         self.pid = self.view.vte_terminal.fork_command(cmd[0], cmd, None, os.getcwd())
 
         if self.pid < 0:
-            self.view.set_build_titles("Error creating Debian Live system!", \
+            self.view.set_build_titles(_("Error creating Debian Live system!"), \
                 "Could not fork the build process!")
             self.view.set_build_status_change(initial=False)
 
-    def on_window_build_delete_event(self, *_):
+    def on_window_build_delete_event(self, *args):
         # If no command is running, close the window
         if self.pid < 0:
             self.view.do_hide_window_build()
         return True
 
-    def on_vte_child_exited(self, *_):
+    def on_vte_child_exited(self, *args):
         def _exec(*cmds):
             glue = ' | tee -a %s ;' % LOG_FILE
             args = ['/bin/sh', '-c', glue.join(cmds)]
@@ -79,12 +79,12 @@ class BuildController(object):
                 # This may fail as we removed the build directory
                 pass
             self.view.set_build_uncancellable()
-            self.view.set_build_titles("Cleaning build process",
-                "Purging unnecessary parts of the build system...")
+            self.view.set_build_titles(_("Cleaning build system"),
+                _("Purging unnecessary parts of the build system..."))
 
         def ok():
-            self.view.set_build_titles("Build process finished",
-                "Your Debian Live system has been created successfully.")
+            self.view.set_build_titles(_("Build process finished"),
+                _("Your Debian Live system has been created successfully."))
 
             if self.options.kde_full_session != '-':
                 os.environ['KDE_FULL_SESSION'] = self.options.kde_full_session
@@ -103,8 +103,8 @@ class BuildController(object):
             return OK
 
         def failed():
-            self.view.set_build_titles("Error when building Debian Live system",
-                "There was an error when building your Debian Live system.")
+            self.view.set_build_titles(_("Error when building Debian Live system"),
+                _("There was an error when building your Debian Live system."))
             return DONE
 
         def failed_clean():
@@ -114,8 +114,8 @@ class BuildController(object):
             return FAILED
 
         def cancelled():
-            self.view.set_build_titles("Build process cancelled",
-                "The creation of your Debian Live system was cancelled.")
+            self.view.set_build_titles(_("Build process cancelled"),
+                _("The creation of your Debian Live system was cancelled."))
             return DONE
 
         def cancelled_clean():
@@ -153,14 +153,14 @@ class BuildController(object):
         if self.view.get_build_auto_close() and self.build_successful:
             self.view.do_hide_window_build()
 
-    def do_pulse_cb(self, *_):
+    def do_pulse_cb(self, *args):
         if self.state != DONE:
             self.view.do_build_pulse()
             return True
 
-    def on_button_build_close_clicked(self, *_):
+    def on_button_build_close_clicked(self, *args):
         self.view.do_hide_window_build()
 
-    def on_button_build_cancel_clicked(self, *_):
+    def on_button_build_cancel_clicked(self, *args):
         self.state = CANCELLED_CLEAN
         subprocess.call(['/bin/kill', '-s', 'KILL', '-%d' % self.pid])
diff --git a/LiveMagic/controllers/main.py b/LiveMagic/controllers/main.py
index dc9dcc5..6bb346f 100644
--- a/LiveMagic/controllers/main.py
+++ b/LiveMagic/controllers/main.py
@@ -31,10 +31,10 @@ class MainController(object):
         else:
             self.view.do_show_wizard()
 
-    def on_quit_request(self, *_):
+    def on_quit_request(self, *args):
         return self._confirm_save(lambda: gtk.main_quit(), quit_dialog=True)
 
-    def on_about_request(self, *_):
+    def on_about_request(self, *args):
         self.view.do_show_about_dialog()
 
     def get_host_architecture(self):
diff --git a/LiveMagic/controllers/wizard.py b/LiveMagic/controllers/wizard.py
index 3e51f28..a61a51a 100644
--- a/LiveMagic/controllers/wizard.py
+++ b/LiveMagic/controllers/wizard.py
@@ -29,7 +29,7 @@ from LiveMagic import utils
 from DebianLive import Config
 
 class WizardController(object):
-    def on_wizard_apply(self, _):
+    def on_wizard_apply(self, asst):
         data, build_dir = self.view.get_wizard_completed_details()
 
         if build_dir in (self.get_homedir(), os.path.expanduser('~/DebianLive')):
@@ -53,8 +53,9 @@ class WizardController(object):
         os.chdir(build_dir)
 
         def gain_superuser():
-            title = "Enter your password to continue"
-            text = "Live-magic requires superuser capabilities to build your Debian Live system."
+            global _
+            title = _("Enter your password to continue")
+            text = _("Debian Live Magic requires superuser capabilities to build your Debian Live system.")
 
             for _ in range(3):
                 cmd = ['gksu', '--disable-grab',
diff --git a/LiveMagic/utils.py b/LiveMagic/utils.py
index 85f52c6..32d8c2c 100644
--- a/LiveMagic/utils.py
+++ b/LiveMagic/utils.py
@@ -32,7 +32,7 @@ def find_resource(resource):
     tried = []
     for base in dirs:
         path = os.path.join(base, resource)
-        if os.path.isfile(path):
+        if os.path.exists(path):
             return path
         tried.append(path)
 
diff --git a/LiveMagic/views/wizard.py b/LiveMagic/views/wizard.py
index 3b3689e..1325c7f 100644
--- a/LiveMagic/views/wizard.py
+++ b/LiveMagic/views/wizard.py
@@ -26,7 +26,7 @@ from LiveMagic.utils import find_resource
 class WizardView(object):
     def __init__(self):
         self.asst = gtk.Assistant()
-        self.asst.set_title('Debian Live Magic')
+        self.asst.set_title(_('Debian Live Magic'))
         self.asst.set_default_size(640, 480)
         self.asst.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_MENU)
         self.asst.set_position(gtk.WIN_POS_CENTER)
@@ -35,7 +35,7 @@ class WizardView(object):
         self.asst.connect('cancel', self.controller.on_wizard_cancel)
 
         def add_about_button():
-            label = gtk.Label('About')
+            label = gtk.Label(_('About'))
             label.show()
 
             image = gtk.Image()
@@ -155,7 +155,7 @@ class WizardView(object):
             flags=gtk.DIALOG_MODAL,
             type=gtk.MESSAGE_QUESTION,
             buttons=gtk.BUTTONS_YES_NO,
-            message_format="Are you sure you wish to cancel?");
+            message_format=_("Are you sure you wish to cancel?"));
 
         res = dialog.run()
         dialog.destroy()
@@ -169,12 +169,12 @@ class WizardView(object):
 
     def do_show_about_dialog(self):
         about = gtk.AboutDialog()
-        about.set_name("Debian Live Magic")
-        about.set_comments("GUI tool to build Debian Live systems.")
+        about.set_name(_("Debian Live Magic"))
+        about.set_comments(_("GUI tool to build Debian Live systems."))
         about.set_copyright("Copyright (C) 2007-2008 Chris Lamb <chris at chris-lamb.co.uk>")
 
         about.set_website("http://debian-live.alioth.debian.org/")
-        about.set_website_label("Debian Live homepage")
+        about.set_website_label(_("Debian Live homepage"))
         about.set_license(file(find_resource('GPL-3')).read())
 
         logo = gtk.gdk.pixbuf_new_from_file(find_resource('debian_openlogo-nd-100.png'))
diff --git a/debian/control b/debian/control
index 5dd57df..40dc544 100644
--- a/debian/control
+++ b/debian/control
@@ -4,7 +4,7 @@ Priority: optional
 Maintainer: Debian Live <debian-live-maint at lists.alioth.debian.org>
 Uploaders: Chris Lamb <chris at chris-lamb.co.uk>, Daniel Baumann <daniel at debian.org>
 Build-Depends: debhelper (>= 5)
-Build-Depends-Indep: python-support
+Build-Depends-Indep: python-support, gettext
 Standards-Version: 3.8.0
 Homepage: http://debian-live.alioth.debian.org/
 Vcs-Git: git://git.debian.org/git/users/lamby-guest/live-magic.git
diff --git a/debian/rules b/debian/rules
index a137661..ec612a9 100755
--- a/debian/rules
+++ b/debian/rules
@@ -15,6 +15,7 @@ clean:
 	rm -f build-stamp
 	dh_clean
 	find -type f -name "*.pyc" -print0 | xargs -0 rm -f
+	rm -rf build live_magic.egg-info mo/
 
 install: build
 	dh_testdir
diff --git a/misc/live-magic.glade b/misc/live-magic.glade
index 267f174..b5fbbba 100644
--- a/misc/live-magic.glade
+++ b/misc/live-magic.glade
@@ -1588,7 +1588,7 @@ If the specified directory is not empty, images will be created in a &lt;i&gt;De
                         <property name="use_preview_label">False</property>
                         <property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</property>
                         <property name="focus_on_click">False</property>
-                        <property name="title" translatable="yes">Select A Build Folder</property>
+                        <property name="title" translatable="yes">Select build folder</property>
                       </widget>
                       <packing>
                         <property name="left_attach">1</property>
diff --git a/po/gettext-config b/po/gettext-config
new file mode 100644
index 0000000..0310d22
--- /dev/null
+++ b/po/gettext-config
@@ -0,0 +1,4 @@
+APPLICATION="live-magic"
+EMAIL="chris at chris-lamb.co.uk"
+EXTENSIONS="glade py"
+DIRS="LiveMagic misc"
diff --git a/po/live-magic.pot b/po/live-magic.pot
new file mode 100644
index 0000000..e0a88a8
--- /dev/null
+++ b/po/live-magic.pot
@@ -0,0 +1,284 @@
+# SOME DESCRIPTIVE TITLE.
+# This file is put in the public domain.
+# FIRST AUTHOR <EMAIL at ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: live-magic\n"
+"Report-Msgid-Bugs-To: chris at chris-lamb.co.uk\n"
+"POT-Creation-Date: 2008-08-09 06:24+0100\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
+"Language-Team: LANGUAGE <LL at li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: LiveMagic/views/wizard.py:29 LiveMagic/views/wizard.py:172
+msgid "Debian Live Magic"
+msgstr ""
+
+#: LiveMagic/views/wizard.py:38
+msgid "About"
+msgstr ""
+
+#: LiveMagic/views/wizard.py:158
+msgid "Are you sure you wish to cancel?"
+msgstr ""
+
+#: LiveMagic/views/wizard.py:173
+msgid "GUI tool to build Debian Live systems."
+msgstr ""
+
+#: LiveMagic/views/wizard.py:177
+msgid "Debian Live homepage"
+msgstr ""
+
+#: LiveMagic/controllers/wizard.py:57
+msgid "Enter your password to continue"
+msgstr ""
+
+#: LiveMagic/controllers/wizard.py:58
+msgid ""
+"Debian Live Magic requires superuser capabilities to build your Debian Live "
+"system."
+msgstr ""
+
+#: LiveMagic/controllers/build.py:59
+msgid "Error creating Debian Live system!"
+msgstr ""
+
+#: LiveMagic/controllers/build.py:82
+msgid "Cleaning build system"
+msgstr ""
+
+#: LiveMagic/controllers/build.py:83
+msgid "Purging unnecessary parts of the build system..."
+msgstr ""
+
+#: LiveMagic/controllers/build.py:86
+msgid "Build process finished"
+msgstr ""
+
+#: LiveMagic/controllers/build.py:87
+msgid "Your Debian Live system has been created successfully."
+msgstr ""
+
+#: LiveMagic/controllers/build.py:106
+msgid "Error when building Debian Live system"
+msgstr ""
+
+#: LiveMagic/controllers/build.py:107
+msgid "There was an error when building your Debian Live system."
+msgstr ""
+
+#: LiveMagic/controllers/build.py:117
+msgid "Build process cancelled"
+msgstr ""
+
+#: LiveMagic/controllers/build.py:118
+msgid "The creation of your Debian Live system was cancelled."
+msgstr ""
+
+#: misc/live-magic.glade:7
+msgid "Generating Debian Live system..."
+msgstr ""
+
+#: misc/live-magic.glade:44
+msgid ""
+"<big><b>Generating Debian Live system...</b></big>\n"
+"\n"
+"Please wait while your Debian Live image is generated for you."
+msgstr ""
+
+#: misc/live-magic.glade:72
+msgid "Automatically close after Live system has been created"
+msgstr ""
+
+#: misc/live-magic.glade:112
+msgid "Details"
+msgstr ""
+
+#: misc/live-magic.glade:201
+msgid ""
+"<b>Welcome to Debian Live Magic!</b>\n"
+"\n"
+"A <i>live</i> system is an operating system that does not require\n"
+"a classical installer to use it. It can boot from various media,\n"
+"including CDs, DVDs, USB sticks, or via netboot. \n"
+"\n"
+"The following screens will lead you through the process\n"
+"of building your own Debian Live system."
+msgstr ""
+
+#: misc/live-magic.glade:223
+msgid "Welcome to Debian Live Magic!"
+msgstr ""
+
+#: misc/live-magic.glade:258
+msgid "<b>What type of image would you like?</b>"
+msgstr ""
+
+#: misc/live-magic.glade:360
+msgid "GNOME desktop environment"
+msgstr ""
+
+#: misc/live-magic.glade:400
+msgid "KDE desktop environment"
+msgstr ""
+
+#: misc/live-magic.glade:442
+msgid "Xfce desktop environment"
+msgstr ""
+
+#: misc/live-magic.glade:484
+msgid "Standard Debian GNU/Linux image"
+msgstr ""
+
+#: misc/live-magic.glade:522
+msgid "Debian GNU/Linux rescue image"
+msgstr ""
+
+#: misc/live-magic.glade:560
+msgid "Choose image type"
+msgstr ""
+
+#: misc/live-magic.glade:597
+msgid ""
+"<b>What distribution of Debian would you like to build?</b>\n"
+"\n"
+"If unsure, select \"<i>Testing (lenny)</i>\"."
+msgstr ""
+
+#: misc/live-magic.glade:625
+msgid "Stable (etch) - well-tested and rarely changes."
+msgstr ""
+
+#: misc/live-magic.glade:643
+msgid ""
+"Testing (lenny) - receives new versions from unstable if they are not too "
+"buggy."
+msgstr ""
+
+#: misc/live-magic.glade:664
+msgid "Unstable (sid) - untested and frequently changing"
+msgstr ""
+
+#: misc/live-magic.glade:734
+msgid "Select distribution"
+msgstr ""
+
+#: misc/live-magic.glade:760
+msgid "<b>What media type would you like to target?</b>"
+msgstr ""
+
+#: misc/live-magic.glade:851
+msgid "ISO image for a CD or DVD"
+msgstr ""
+
+#: misc/live-magic.glade:892
+msgid "USB / HDD image"
+msgstr ""
+
+#: misc/live-magic.glade:936
+msgid "Network boot image"
+msgstr ""
+
+#: misc/live-magic.glade:998
+msgid "Server type:"
+msgstr ""
+
+#: misc/live-magic.glade:1008
+msgid "Server address:"
+msgstr ""
+
+#: misc/live-magic.glade:1019
+msgid "Server path:"
+msgstr ""
+
+#: misc/live-magic.glade:1071
+msgid "Select media type"
+msgstr ""
+
+#: misc/live-magic.glade:1108
+msgid ""
+"<b>Please choose a local mirror.</b>\n"
+"\n"
+"To select a mirror that is not on the list, simply enter it below."
+msgstr ""
+
+#: misc/live-magic.glade:1233
+msgid "Choose mirror"
+msgstr ""
+
+#: misc/live-magic.glade:1270
+msgid ""
+"<b>What type of machine is your Debian Live system for?</b>\n"
+"\n"
+"If you are unsure, select \"<i>i386</i>\"."
+msgstr ""
+
+#: misc/live-magic.glade:1321
+msgid ""
+"amd64\n"
+"Most new computers with e.g. AMD Opteron, Turion 64, Athlon 64, or\n"
+"Intel Core2, Pentium 4xx, Pentium D CPUs."
+msgstr ""
+
+#: misc/live-magic.glade:1344
+msgid ""
+"i386\n"
+"Computers with e.g. AMD Sempron or Intel Celeron, almost all\n"
+"desktop computers dating 2004 or earlier."
+msgstr ""
+
+#: misc/live-magic.glade:1380
+msgid "Select architecture"
+msgstr ""
+
+#: misc/live-magic.glade:1417
+msgid ""
+"<b>Select Debian Installer integration</b>\n"
+"\n"
+"Selecting \"<i>yes</i>\" below adds additional boot options that launch the "
+"Debian Installer, the\n"
+"official installation system for Debian systems. \n"
+"\n"
+"If unsure, select \"<i>no</i>\"."
+msgstr ""
+
+#: misc/live-magic.glade:1448
+msgid "No, do not integrate the Debian Installer."
+msgstr ""
+
+#: misc/live-magic.glade:1481
+msgid "Yes, integrate the Debian Installer."
+msgstr ""
+
+#: misc/live-magic.glade:1525
+msgid "Select Debian Installer integration"
+msgstr ""
+
+#: misc/live-magic.glade:1551
+msgid ""
+"<b>Please choose a build folder:</b>\n"
+"\n"
+"If the specified directory is not empty, images will be created in a "
+"<i>DebianLive/</i> subfolder."
+msgstr ""
+
+#: misc/live-magic.glade:1591 misc/live-magic.glade:1640
+msgid "Select build folder"
+msgstr ""
+
+#: misc/live-magic.glade:1657
+msgid ""
+"<b>Your Debian Live image is ready to build!</b>\n"
+"\n"
+"Press <i>Apply</i> to begin the build process."
+msgstr ""
+
+#: misc/live-magic.glade:1685
+msgid "Ready to build!"
+msgstr ""
diff --git a/po/update-mo.sh b/po/update-mo.sh
new file mode 100755
index 0000000..1702197
--- /dev/null
+++ b/po/update-mo.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+set -eu
+
+. po/gettext-config
+
+Msgfmt () {
+	echo msgfmt "$@"
+	msgfmt "$@"
+}
+
+rm -rf mo
+
+if ! ls po/*.po >/dev/null 2>&1
+then
+	exit 0
+fi
+
+for FILENAME in po/*.po
+do
+	LANG="$(basename ${FILENAME} .po)"
+	DIR="mo/${LANG}/LC_MESSAGES"
+	mkdir -p "${DIR}"
+	Msgfmt "${FILENAME}" -o "${DIR}/${APPLICATION}.mo"
+done
diff --git a/po/update-pot.sh b/po/update-pot.sh
new file mode 100755
index 0000000..f083ff9
--- /dev/null
+++ b/po/update-pot.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -eu
+
+. po/gettext-config
+
+if [ ! -d po/ ] && [ -d ../po/ ]
+then
+	cd ..
+fi
+
+FILES="$(mktemp)"
+trap 'rm -f ${FILES}' EXIT
+
+find ${DIRS} -type f -printf "%p\n" > ${FILES}
+
+REGEX="$(echo ${EXTENSIONS} | sed 's@ @\\|@g')"
+sed -i -n -e '/\('"${REGEX}"'\)$/p' ${FILES}
+
+exec xgettext \
+	--files-from=${FILES} \
+	--default-domain=${APPLICATION} \
+	--force-po \
+	--foreign-user \
+	--package-name=${APPLICATION} \
+	--msgid-bugs-address=${EMAIL} \
+	--output=po/${APPLICATION}.pot
diff --git a/setup.py b/setup.py
index 898f271..498e5ad 100755
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,27 @@
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+import os
+
 from distutils.core import setup
+from distutils.file_util import copy_file
+from distutils.command.build_py import build_py
+from distutils.command.install_data import install_data
+
+from glob import glob
+from subprocess import check_call
+
+class my_install(install_data):
+    def run(self):
+        # Generating and installing .mo files
+        check_call('po/update-mo.sh')
+        for langdir in glob('mo/*'):
+            lang = os.path.basename(langdir)
+            src = os.path.join(langdir, 'LC_MESSAGES', 'live-magic.mo')
+            dst = os.path.join('share', 'locale', lang, 'LC_MESSAGES')
+            self.data_files.append((dst, [src]))
+
+        install_data.run(self)
 
 setup(
     name='live-magic',
@@ -27,7 +47,10 @@ setup(
     description = "GTK+ frontend for configuring Debian Live systems",
     license = "GNU GPL v3",
     scripts = ['live-magic'],
-    packages= [
+    cmdclass = {
+        'install_data': my_install,
+    },
+    packages = [
         'LiveMagic',
         'LiveMagic.views',
         'LiveMagic.controllers',

-- 
GUI front-end for Debian Live.



More information about the debian-live-changes mailing list