changeset 2416:bf9fb139b5d3

Merge with devel.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Tue, 17 Jul 2007 03:37:38 +0200
parents c3d3d7b7a048 (current diff) 1007128cb089 (diff)
children b114a130c659
files
diffstat 8 files changed, 312 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_PageEditor.py	Mon Jul 16 12:38:29 2007 +0200
+++ b/MoinMoin/_tests/test_PageEditor.py	Tue Jul 17 03:37:38 2007 +0200
@@ -189,11 +189,11 @@
         deleter = PageEditor(request, pagename)
         deleter.deletePage()
         print 'BODY:', deleter.body
-    
+
     editor = PageEditor(request, pagename)
     print 'BODY:', editor.body
     editor.saveText(testtext, 0)
-    
+
     print "PageEditor can't save a page if Abort is returned from PreSave event handlers"
     page = Page(request, pagename)
     assert page.body != testtext
--- a/MoinMoin/_tests/test_packages.py	Mon Jul 16 12:38:29 2007 +0200
+++ b/MoinMoin/_tests/test_packages.py	Tue Jul 17 03:37:38 2007 +0200
@@ -12,7 +12,7 @@
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.packages import Package, ScriptEngine, MOIN_PACKAGE_FILE, packLine, unpackLine
-
+from MoinMoin._tests.common import gain_superuser_rights
 
 
 class DebugPackage(Package, ScriptEngine):
@@ -62,15 +62,9 @@
 DeletePage|FooPage|Test ...
 """).installPackage()
 
-    def gain_superuser_rights(self):
-        self.request.user.name = "SuperUserName"
-        self.request.user.valid = 1
-        self.request.user.may.name = self.request.user.name
-        self.request.cfg.superuser.append(self.request.user.name)
-        self.request.user.auth_method = self.request.cfg.trusted_auth_methods[0]
 
     def testBasicPackageThings(self):
-        self.gain_superuser_rights()
+        gain_superuser_rights(self.request)
         myPackage = DebugPackage(self.request, 'test')
         myPackage.installPackage()
         assert myPackage.msg == u'foo\nFooPage added \n'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/i18n/jabberbot/JabberBot.pot	Tue Jul 17 03:37:38 2007 +0200
@@ -0,0 +1,139 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2007-07-17 03:14+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#, python-format
+msgid ""
+"Here's the page \"%(pagename)s\" that you've requested:\n"
+"\n"
+"%(data)s"
+msgstr ""
+
+#, python-format
+msgid ""
+"That's the list of pages accesible to you:\n"
+"\n"
+"%s"
+msgstr ""
+
+#, python-format
+msgid ""
+"Following detailed information on page \"%(pagename)s\" is available::\n"
+"\n"
+"%(data)s"
+msgstr ""
+
+msgid "Submit this form to perform a wiki search"
+msgstr ""
+
+msgid "Title search"
+msgstr ""
+
+msgid "Full-text search"
+msgstr ""
+
+msgid "Wiki search"
+msgstr ""
+
+msgid "Search text"
+msgstr ""
+
+msgid "Please specify the search criteria."
+msgstr ""
+
+msgid "This command requires a client supporting Data Forms"
+msgstr ""
+
+msgid ""
+"The \"help\" command prints a short, helpful message about a given topic or "
+"function.\n"
+"\n"
+"Usage: help [topic_or_function]"
+msgstr ""
+
+msgid ""
+"The \"ping\" command returns a \"pong\" message as soon as it's received."
+msgstr ""
+
+msgid "searchform - perform a wiki search using a form"
+msgstr ""
+
+#, python-format
+msgid ""
+"%(command)s - %(description)s\n"
+"\n"
+"Usage: %(command)s %(params)s"
+msgstr ""
+
+#, python-format
+msgid "Unknown command \"%s\" "
+msgstr ""
+
+#, python-format
+msgid ""
+"You've specified a wrong parameter list. The call should look like:\n"
+"\n"
+"%(command)s %(params)s"
+msgstr ""
+
+#, python-format
+msgid ""
+"Hello there! I'm a MoinMoin Notification Bot. Available commands:\n"
+"\n"
+"%(internal)s\n"
+"%(xmlrpc)s"
+msgstr ""
+
+msgid "You must set a (long) secret string!"
+msgstr ""
+
+msgid "Error"
+msgstr ""
+
+#, python-format
+msgid ""
+"Your request has failed. The reason is:\n"
+"%s"
+msgstr ""
+
+#, python-format
+msgid ""
+"A serious error occured while processing your request:\n"
+"%s"
+msgstr ""
+
+msgid "An internal error has occured, please contact the administrator."
+msgstr ""
+
+msgid "Credentials check failed, you may be unable to see all information."
+msgstr ""
+
+msgid "This command may take a while to complete, please be patient..."
+msgstr ""
+
+#, python-format
+msgid ""
+"Last author: %(author)s\n"
+"Last modification: %(modification)s\n"
+"Current version: %(version)s"
+msgstr ""
+
+msgid "You must set a (long) secret string"
+msgstr ""
+
+msgid "You are not allowed to use this bot!"
+msgstr ""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/i18n/jabberbot/Makefile	Tue Jul 17 03:37:38 2007 +0200
@@ -0,0 +1,79 @@
+POFILES = $(wildcard *.po)
+UPDATEPOFILES = $(POFILES:.po=.po-update)
+NOPFILES = $(POFILES:.po=.nop)
+DOMAIN = JabberBot
+
+.SUFFIXES: .po .po-update .nop
+
+-include POTFILES
+
+POTFILES.in POTFILES:
+	@python ../tools/mk_POTFILES.py ../../../jabberbot
+
+.nop.po-update:
+	@lang=`echo $@ | sed -e 's/\.MoinMoin\.po-update$$//'`; \
+	echo "$$lang:"; \
+	../tools/wiki2po.py $${lang}; \
+	echo "msgmerge $$lang.$(DOMAIN).po $(DOMAIN).pot -o $$lang.$(DOMAIN).new.po"; \
+	if msgmerge $$lang.$(DOMAIN).po $(DOMAIN).pot -o $$lang.$(DOMAIN).new.po; then \
+	  if cmp $$lang.$(DOMAIN).po $$lang.$(DOMAIN).new.po >/dev/null 2>&1; then \
+	    rm -f $$lang.$(DOMAIN).new.po; \
+	  else \
+	    ../tools/po2wiki.py $$lang <$$lang.$(DOMAIN).new.po; \
+	    rm -f $$lang.$(DOMAIN).new.po; \
+	  fi; \
+	else \
+	  echo "msgmerge for $$lang.$(DOMAIN).po failed!" 1>&2; \
+	  rm -f $$lang.$(DOMAIN).new.po; \
+	fi
+
+# remove "--no-location" if you want to have file names and line numbers
+# that's bad for merging branches - this is why we don't use it
+$(DOMAIN).pot-update: $(POTFILES) POTFILES.in
+	xgettext --default-domain=$(DOMAIN) --directory=../../../jabberbot \
+	  --files-from=POTFILES.in \
+	  --no-location \
+	  --add-comments=TRANSLATORS:
+	@test ! -f $(DOMAIN).po || { \
+	  if test -f $(DOMAIN).pot; then \
+	    sed -e 's/^"POT-Creation-Date: .*\"$$//' < $(DOMAIN).pot > $(DOMAIN).1po && \
+	    sed -e 's/^"POT-Creation-Date: .*"$$//' < $(DOMAIN).po > $(DOMAIN).2po && \
+	    if cmp $(DOMAIN).1po $(DOMAIN).2po >/dev/null 2>&1; then \
+	      rm -f $(DOMAIN).1po $(DOMAIN).2po $(DOMAIN).po; \
+	    else \
+	      rm -f $(DOMAIN).1po $(DOMAIN).2po $(DOMAIN).pot && \
+	      mv $(DOMAIN).po $(DOMAIN).pot; \
+	    fi; \
+	  else \
+	    mv $(DOMAIN).po $(DOMAIN).pot; \
+	  fi; \
+	}
+
+$(DOMAIN).pot: $(POTFILES) POTFILES.in
+	$(MAKE) $(DOMAIN).pot-update
+
+$(POFILES):
+	@lang=`echo $@ | sed -e 's,.*/,,' -e 's/\.MoinMoin\.po$$//'`; \
+	../tools/wiki2po.py $${lang}; \
+	echo msgmerge $${lang}.$(DOMAIN).po $(DOMAIN).pot -o $${lang}.$(DOMAIN).new.po; \
+	msgmerge $${lang}.$(DOMAIN).po $(DOMAIN).pot -o $${lang}.$(DOMAIN).new.po; \
+	../tools/po2wiki.py $${lang} <$$lang.$(DOMAIN).new.po; \
+	rm -f $$lang.$(DOMAIN).new.po
+
+$(NOPFILES):
+
+update-po: clean
+	$(MAKE) $(DOMAIN).pot-update
+	$(MAKE) $(UPDATEPOFILES)
+
+stats:
+	@files="$(POFILES)"; \
+	for i in $$files; do \
+	  lang=`echo $$i | sed -e 's,.*/,,' -e 's/\.MoinMoin\.po$$//'`; \
+	  echo -n "$$lang: "; \
+	  ../msgfmt -o /dev/null --statistics $$i; \
+	done
+
+clean:
+	rm -f POTFILES POTFILES.in
+
--- a/MoinMoin/i18n/tools/mk_POTFILES.py	Mon Jul 16 12:38:29 2007 +0200
+++ b/MoinMoin/i18n/tools/mk_POTFILES.py	Tue Jul 17 03:37:38 2007 +0200
@@ -1,10 +1,16 @@
 #!/usr/bin/env python
 
 import os
+from sys import argv
 
 # Define the starting directory.
 
-startdir = os.path.join("..") # MoinMoin
+startdir = ""
+
+if len(argv) == 2:
+    startdir = os.path.join(argv[1])
+else:
+    startdir = os.path.join("..") # MoinMoin
 
 # Define a blacklist.
 
@@ -77,10 +83,10 @@
     outfile.write("POTFILES = \\\n")
     try:
         for file in files[:-1]:
-            outfile.write("\t" + os.path.join("..", file) + " \\\n")
+            outfile.write("\t" + os.path.join(startdir, file) + " \\\n")
         if files[-1]:
             file = files[-1]
-            outfile.write("\t" + os.path.join("..", file) + "\n")
+            outfile.write("\t" + os.path.join(startdir, file) + "\n")
     finally:
         outfile.close()
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jabberbot/i18n.py	Tue Jul 17 03:37:38 2007 +0200
@@ -0,0 +1,24 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - jabber bot i18n routines
+
+    @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
+    @license: GNU GPL, see COPYING for details.
+"""
+
+translations = None
+
+def getText(original, lang="en"):
+    global translations
+
+    if not translations:
+        init_i18n()
+
+    try:
+        return translations[lang][original]
+    except KeyError:
+        return original
+
+def init_i18n():
+    global translations
+    translations = {'en': {}}
--- a/jabberbot/xmlrpcbot.py	Mon Jul 16 12:38:29 2007 +0200
+++ b/jabberbot/xmlrpcbot.py	Tue Jul 17 03:37:38 2007 +0200
@@ -6,13 +6,15 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import Queue
+import datetime, logging, time, xmlrpclib, Queue
+from SimpleXMLRPCServer import SimpleXMLRPCServer
 from threading import Thread
-import datetime, logging, time, xmlrpclib
-from SimpleXMLRPCServer import SimpleXMLRPCServer
 
 import jabberbot.commands as cmd
 from jabberbot.multicall import MultiCall
+from jabberbot.i18n import getText
+
+_ = getText
 
 class ConfigurationError(Exception):
     def __init__(self, message):
@@ -36,7 +38,7 @@
         self.log = logging.getLogger("log")
 
         if not config.secret:
-            error = "You must set a (long) secret string!"
+            error = _("You must set a (long) secret string!")
             self.log.critical(error)
             raise ConfigurationError(error)
 
@@ -74,7 +76,7 @@
             self.get_page_info(command)
 
     def report_error(self, jid, text):
-        report = cmd.NotificationCommand(jid, text, u"Error", async=False)
+        report = cmd.NotificationCommand(jid, text, _("Error"), async=False)
         self.commands_out.put_nowait(report)
 
     def get_auth_token(self, jid):
@@ -105,15 +107,15 @@
                     function(self, command)
                     self.commands_out.put_nowait(command)
                 except xmlrpclib.Fault, fault:
-                    msg = u"""Your request has failed. The reason is:\n%s"""
+                    msg = _("Your request has failed. The reason is:\n%s")
                     self.log.error(str(fault))
                     self.report_error(jid, msg % (fault.faultString, ))
                 except xmlrpclib.Error, err:
-                    msg = u"""A serious error occured while processing your request:\n%s"""
+                    msg = _("A serious error occured while processing your request:\n%s")
                     self.log.error(str(err))
                     self.report_error(jid, msg % (str(err), ))
                 except Exception, exc:
-                    msg = u"An internal error has occured, please contact the administrator."
+                    msg = _("An internal error has occured, please contact the administrator.")
                     self.log.critical(str(exc))
                     self.report_error(jid, msg)
 
@@ -124,7 +126,7 @@
         return wrapped_func
 
     def warn_no_credentials(self, jid):
-        msg = u"""Credentials check failed, you may be unable to see all information."""
+        msg = _("Credentials check failed, you may be unable to see all information.")
         warning = cmd.NotificationCommand([jid], msg, async=False)
         self.commands_out.put_nowait(warning)
 
@@ -165,7 +167,7 @@
     def get_page_list(self, command):
         """Returns a list of all accesible pages"""
 
-        txt = u"""This command may take a while to complete, please be patient..."""
+        txt = _("This command may take a while to complete, please be patient...")
         info = cmd.NotificationCommand([command.jid], txt, async=False)
         self.commands_out.put_nowait(info)
 
@@ -208,9 +210,9 @@
                     'time': datestr[9:17],
                 }
 
-        msg = u"""Last author: %(author)s
+        msg = _("""Last author: %(author)s
 Last modification: %(modification)s
-Current version: %(version)s""" % {
+Current version: %(version)s""") % {
              'author': author,
              'modification': date,
              'version': getpageinfo_result[0]['version'],
@@ -240,7 +242,7 @@
         if config.secret:
             self.secret = config.secret
         else:
-            error = "You must set a (long) secret string"
+            error = _("You must set a (long) secret string")
             self.log.critical(error)
             raise ConfigurationError(error)
 
@@ -268,7 +270,7 @@
         """
         def protected_func(secret, *args):
             if secret != self.secret:
-                raise xmlrpclib.Fault(1, "You are not allowed to use this bot!")
+                raise xmlrpclib.Fault(1, _("You are not allowed to use this bot!"))
             else:
                 return function(self, *args)
 
--- a/jabberbot/xmppbot.py	Mon Jul 16 12:38:29 2007 +0200
+++ b/jabberbot/xmppbot.py	Tue Jul 17 03:37:38 2007 +0200
@@ -18,6 +18,9 @@
 import pyxmpp.jabber.dataforms as forms
 
 import jabberbot.commands as cmd
+from jabberbot.i18n import getText
+
+_ = getText
 
 class Contact:
     """Abstraction of a roster item / contact
@@ -212,17 +215,25 @@
             self.remove_subscription(jid)
 
         elif isinstance(command, cmd.GetPage) or isinstance(command, cmd.GetPageHTML):
-            msg = u"""Here's the page "%s" that you've requested:\n\n%s"""
-            self.send_message(command.jid, msg % (command.pagename, command.data))
+            msg = _("""Here's the page "%(pagename)s" that you've requested:\n\n%(data)s""")
+            self.send_message(command.jid, msg % {
+                      'pagename': command.pagename,
+                      'data': command.data,
+            })
 
         elif isinstance(command, cmd.GetPageList):
-            msg = u"""That's the list of pages accesible to you:\n\n%s"""
+            msg = _("That's the list of pages accesible to you:\n\n%s")
             pagelist = "\n".join(command.data)
             self.send_message(command.jid, msg % (pagelist, ))
 
         elif isinstance(command, cmd.GetPageInfo):
-            msg = u"""Following detailed information on page "%s" is available::\n\n%s"""
-            self.send_message(command.jid, msg % (command.pagename, command.data))
+            msg = _("""Following detailed information on page "%(pagename)s" \
+is available::\n\n%(data)s""")
+
+            self.send_message(command.jid, msg % {
+                      'pagename': command.pagename,
+                      'data': command.data,
+            })
 
     def ask_for_subscription(self, jid):
         """Sends a <presence/> stanza with type="subscribe"
@@ -263,16 +274,16 @@
         pass
 
     def send_search_form(self, jid):
-        help_form = u"Submit this form to perform a wiki search"
-
-        title_search = forms.Option("t", "Title search")
-        full_search = forms.Option("f", "Full-text search")
+        help_form = _("Submit this form to perform a wiki search")
 
-        form = forms.Form(xmlnode_or_type="form", title="Wiki search", instructions=help_form)
+        title_search = forms.Option("t", _("Title search"))
+        full_search = forms.Option("f", _("Full-text search"))
+
+        form = forms.Form(xmlnode_or_type="form", title=_("Wiki search"), instructions=help_form)
         form.add_field(name="search_type", options=[title_search, full_search], field_type="list-single", label="Search type")
-        form.add_field(name="search", field_type="text-single", label="Search text")
+        form.add_field(name="search", field_type="text-single", label=_("Search text"))
 
-        message = Message(to_jid=jid, body="Please specify the search criteria.", subject="Wiki search")
+        message = Message(to_jid=jid, body=_("Please specify the search criteria."), subject=_("Wiki search"))
         message.add_content(form)
         self.get_stream().send(message)
 
@@ -350,7 +361,7 @@
             if self.contacts[jid].supports_forms(resource):
                 self.send_search_form(sender)
             else:
-                msg = u"This command requires a client supporting Data Forms"
+                msg = _("This command requires a client supporting Data Forms")
                 self.send_message(sender, msg, u"Error")
         else:
             # For unknown command return a generic help message
@@ -379,22 +390,27 @@
 
         """
         if command == "help":
-            return u"""The "help" command prints a short, helpful message about a given topic or function.\n\nUsage: help [topic_or_function]"""
+            return _("""The "help" command prints a short, helpful message \
+about a given topic or function.\n\nUsage: help [topic_or_function]""")
 
         elif command == "ping":
-            return u"""The "ping" command returns a "pong" message as soon as it's received."""
+            return _("""The "ping" command returns a "pong" message as soon \
+as it's received.""")
 
         elif command == "searchform":
-            return u"""searchform - perform a wiki search using a form"""
+            return _("""searchform - perform a wiki search using a form""")
 
         # Here we have to deal with help messages of external (xmlrpc) commands
         else:
             if command in self.xmlrpc_commands:
                 classobj = self.xmlrpc_commands[command]
-                help_str = u"%s - %s\n\nUsage: %s %s"
-                return help_str % (command, classobj.description, command, classobj.parameter_list)
+                help_str = _("%(command)s - %(description)s\n\nUsage: %(command)s %(params)s")
+                return help_str % {'command': command,
+                                   'description': classobj.description,
+                                   'params': classobj.parameter_list,
+                                  }
             else:
-                return u"""Unknown command "%s" """ % (command, )
+                return _("""Unknown command "%s" """) % (command, )
 
     def handle_xmlrpc_command(self, sender, command):
         """Creates a command object, and puts it the command queue
@@ -415,8 +431,10 @@
 
         # This happens when user specifies wrong parameters
         except TypeError:
-            msg = u"You've specified a wrong parameter list. The call should look like:\n\n%s %s"
-            return msg % (command[0], command_class.parameter_list)
+            msg = _("You've specified a wrong parameter list. \
+The call should look like:\n\n%(command)s %(params)s")
+
+            return msg % {'command': command[0], 'params': command_class.parameter_list}
 
     def handle_unsubscribed_presence(self, stanza):
         """Handles unsubscribed presence stanzas"""
@@ -563,7 +581,8 @@
         It's sent in response to an uknown message or the "help" command.
 
         """
-        msg = u"""Hello there! I'm a MoinMoin Notification Bot. Available commands:\n\n%s\n%s"""
+        msg = _("Hello there! I'm a MoinMoin Notification Bot. Available commands:\
+\n\n%(internal)s\n%(xmlrpc)s")
         internal = ", ".join(self.internal_commands)
         xmlrpc = ", ".join(self.xmlrpc_commands.keys())