Author: esr
Date: Wed May 2 12:34:30 2007
New Revision: 17265
URL: http://svn.gna.org/viewcvs/wesnoth?rev=17265&view=rev
Log:
Checkpoint before moving to pure shell.
Added:
trunk/utils/change_textdomain (with props)
Added: trunk/utils/change_textdomain
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/change_textdomain?rev=17265&view=auto
==============================================================================
--- trunk/utils/change_textdomain (added)
+++ trunk/utils/change_textdomain Wed May 2 12:34:30 2007
@@ -1,0 +1,161 @@
+#!/usr/bin/env python
+#
+# change-textdomain -- hack the text domain of a specified campaign
+#
+# Code by Eric S. Raymond, May 2007.
+"""
+Ivanovic's original specification from FR #9039.
+
+ would be nice to have a tool maybe named utils/textdomain2textdomain
+ that is able to change the textdomain of a given campaign. The params
+ that the script should support are these: campaignname,
+ oldtextdomain, newtextdomain
+
+ * asumptions: campaign lies in data/campaigns, current textdomain
+ is wesnoth-oldtextdomain, the translation files are existing
+ (and maybe already uploaded) in the folder
+ /po/wesnoth-oldtextdomain/.
+
+Here is what is too be done for the campaign named 'foo' to move from
+the textdomain wesnoth-oldtextdomain to wesnoth-newtextdomain:
+
+1) search in all files in data/campaigns/foo* (yes, the .cfg file, too) for
this string:
+
+#textdomain wesnoth-oldtextdomain
+
+2) replace (be aware, there might be " " around the part after name=)
+
+[textdomain]
+name=wesnoth-oldtextdomain
+[/textdomain]
+
+with
+
+[textdomain]
+name=wesnoth-newtextdomain
+[/textdomain]
+
+3) move the folder po/wesnoth-oldtextdomain to
+ po/wesnoth-newtextdomain (svn mv if the file is already under
+ version conrol, normal mv if it is not)
+
+4) move the file (folders are already changed)
+ po/wesnoth-newtextdomain/wesnoth-oldtextdomain.pot to
+ po/wesnoth-newtextdomain/wensoth-newtextdomain.pot (via svn mv if
+ files are under version control already, --force will be needed,
+ since it is a 2nd move)
+
+5) replace wesnoth-oldtextdomain by wesnoth-newtextdomain in
+ po/wesnoth-newtextdomain/Makevars
+
+6) replace wesnoth-oldtextdomain by wesnoth-newtextdomain in po/Makefile.am
+
+7) replace wesnoth-oldtextdomain by wesnoth-newtextdomain in configure.ac
+"""
+
+import sys, os, getopt, re
+
+def hackfile(filename):
+ "Change text domain occurrences in a single file."
+ ifp = open(filename)
+ contents = ifp.read()
+ ifp.close()
+ if "wesnoth-" + oldtd in contents:
+ print " %s \\" % (filename)
+
+if __name__ == "__main__":
+ def help():
+ sys.stderr.write("""\
+Usage: change_textdomain {-h | campaign-name oldtextdomain newtextdomain}
+ Options may be any of these:
+ -h, --help Emit this help message and quit
+ Requires as first argument a campaign name.
+ Requires as second and third arguments old and new text domain names.
+ Call from the top-level directory of mainline.
+""")
+
+ # Process options
+ (options, arguments) = getopt.getopt(sys.argv[1:], "h", ['help',])
+ for (switch, val) in options:
+ if switch in ('-h', '--help'):
+ help()
+ sys.exit(0)
+ if len(arguments) == 0:
+ sys.stderr.write("change_textdomain: a campaign name is required.\n")
+ sys.exit(1)
+ else:
+ campaign = arguments[0]
+ if len(arguments) == 1:
+ sys.stderr.write("change_textdomain: a textdomain name is required.\n")
+ sys.exit(1)
+ else:
+ oldtd = arguments[1]
+ if len(arguments) == 2:
+ sys.stderr.write("change_textdomain: a textdomain name is required.\n")
+ sys.exit(1)
+ else:
+ newtd = arguments[2]
+
+ print '''#!/bin/sh
+# Generated script to change the text domain of %(campaign)s from %(oldtd)s to
%(newtd)s
+
+function replace()
+# Replace a specified string with another in any number of files
+{
+ left="$1"; right="$2"; shift; shift;
+
+ for file in $*
+ do
+ if grep "$left" $file >/dev/null 2>&1
+ then
+ overwrite $file sed "[EMAIL PROTECTED]@[EMAIL PROTECTED]" $file
+ fi
+ done
+}
+
+function overwrite()
+# Replace a file with itself filtered by a command
+{
+ opath=$PATH
+ PATH=/bin:usr/bin
+
+ file=$1; shift
+ new=/tmp/over$$; old=/tmp/under$$
+ trap \'rm -f $new $old ; exit 1\' 1 2 15
+
+ if PATH=$opath "$@" >$new
+ then
+ cp $file $old # save the old file
+ trap '' 1 2 15 # We are committed; ignore signals
+ cp $new $file
+ else
+ echo "overwrite: $1 failed, $file unchanged" 1 >&2
+ exit 1
+ fi
+ rm -f $new $old
+}
+
+function svnmove():
+# Move a file, whether under version control or not
+{
+ if svn mv --force $1 $2
+ then
+ :
+ else
+ mv $1 $2
+ fi
+}
+
+# First, hack scenario and autoconf files
+replace wesnoth-%(oldtd)s %(newtd)s \\
+ configure.ac \\
+ po/Makefile.am \\
+ po/wesnoth-%(oldtd)s/Makevars \\
+ data/%(campaign)s.cfg \\
+ `find data/%(campaign)s -name "*.cfg" -print`
+
+# Then do the .pot and folder moves
+svnmove po/wesnoth-%(oldtd)s/%(oldtd)s.pot po/wesnoth-%(oldtd)s/%(newtd)s.pot
+svnmove po/wesnoth-%(oldtd)s po/wesnoth-%(newtd)s
+''' % locals()
+
Propchange: trunk/utils/change_textdomain
------------------------------------------------------------------------------
svn:executable = *
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits