summaryrefslogtreecommitdiffstats
path: root/l10ntools
diff options
context:
space:
mode:
authorIvo Hinkelmann <ihi@openoffice.org>2010-07-14 16:59:49 +0200
committerIvo Hinkelmann <ihi@openoffice.org>2010-07-14 16:59:49 +0200
commit31236973b376567a7acf33962385329855f89665 (patch)
tree00588ca5e49a699b8730d19ec84ca5e770260bb9 /l10ntools
parenttxtl10n: #i113008# #i113125# Support of help tree files and single txt files ... (diff)
downloadcore-31236973b376567a7acf33962385329855f89665.tar.gz
core-31236973b376567a7acf33962385329855f89665.zip
txtl10n: #i113008# #i113125# Python 2.3.x compatible
Diffstat (limited to 'l10ntools')
-rw-r--r--l10ntools/scripts/tool/l10ntool.py20
-rw-r--r--l10ntools/scripts/tool/pseudo.py184
-rw-r--r--l10ntools/scripts/tool/sdf.py65
-rw-r--r--l10ntools/scripts/tool/xhtex.py1
4 files changed, 202 insertions, 68 deletions
diff --git a/l10ntools/scripts/tool/l10ntool.py b/l10ntools/scripts/tool/l10ntool.py
index 66afc309a1fb..42e8a6b4e428 100644
--- a/l10ntools/scripts/tool/l10ntool.py
+++ b/l10ntools/scripts/tool/l10ntool.py
@@ -27,6 +27,8 @@
from optparse import OptionParser
from sdf import SdfData
+from pseudo import PseudoSet
+
import sys
import os
import shutil
@@ -68,9 +70,15 @@ class abstractL10nTool:
def format_outputfile(self, filename, language):
extension = filename[filename.rfind('.')+1:]
file = filename[:filename.rfind('.')]
- return self.get_outputfile_format_str().replace('[', '{').replace(']','}').format(
- filename=filename, fileNoExt=file, language=language, extension=extension, path_prefix=self._options.path_prefix,
- path_postfix=self._options.path_postfix, path=self.get_path())
+
+ # Python 2.3.x friendly
+ return self.get_outputfile_format_str().replace('[', '%(').replace(']',')s') % \
+ { 'filename': filename, 'fileNoExt': file, 'language': language, 'extension': extension, 'path_prefix': self._options.path_prefix,
+ 'path_postfix': self._options.path_postfix, 'path': self.get_path() }
+
+ #return self.get_outputfile_format_str().replace('[', '{').replace(']','}').format(
+ # filename=filename, fileNoExt=file, language=language, extension=extension, path_prefix=self._options.path_prefix,
+ # path_postfix=self._options.path_postfix, path=self.get_path())
def get_path(self):
if self._options.outputfile.find('/') == -1:
@@ -79,12 +87,12 @@ class abstractL10nTool:
return self._options.outputfile[:self._options.outputfile.rfind('/')]
def merge(self, sdfdata):
- langset,forcedset, foundset = set(), set() , set()
+ langset,forcedset, foundset = PseudoSet(), PseudoSet() , PseudoSet()
if self._options.languages:
- langset = set(self._options.languages)
+ langset = PseudoSet(self._options.languages)
if self._options.forcedlanguages:
- forcedset = set(self._options.forcedlanguages)
+ forcedset = PseudoSet(self._options.forcedlanguages)
if sdfdata.get_languages_found_in_sdf():
foundset = sdfdata.get_languages_found_in_sdf()
diff --git a/l10ntools/scripts/tool/pseudo.py b/l10ntools/scripts/tool/pseudo.py
new file mode 100644
index 000000000000..ee23b22f4e79
--- /dev/null
+++ b/l10ntools/scripts/tool/pseudo.py
@@ -0,0 +1,184 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+# to support macosx baseline machines from Cretaceous period
+
+# incomplete set() class implementation of Python 2.4
+class PseudoSet:
+ _list = []
+
+ def __str__(self):
+ return str(self._list)
+
+ def __init__(self, newlist=[]):
+ self._list = self._remove_dupes(newlist)
+
+ def __or__(self, other):
+ tmplist = []
+ if self._list != None and other != None:
+ tmplist.extend(self._list)
+ tmplist.extend(other)
+ return PseudoSet(self._remove_dupes(tmplist))
+ else:
+ print "__or__(None)"
+
+ def __sub__(self,other):
+ tmplist = []
+ if self._list != None and other != None:
+ tmplist.extend(self._list)
+ [tmplist.remove(key) for key in other if key in tmplist]
+ else:
+ print __sub__(none)
+ return PseudoSet(tmplist)
+
+ def __and__(self, other):
+ tmplist = []
+ if other != None and self._list != None:
+ [tmplist.append(key) for key in self._list if key in other]
+ return PseudoSet(tmplist)
+ else:
+ print "__and__(None)"
+
+ def __iter__(self):
+ return self._list.__iter__()
+
+ def __items__(self):
+ return self._list.items()
+
+ def __keys__(self):
+ return keys(self._list)
+
+ def _remove_dupes(self, list):
+ tmpdict = {}
+ for key in list:
+ tmpdict[key] = 1
+ return tmpdict.keys()
+
+# incomplete OrderedDict() class implementation
+class PseudoOrderedDict(dict):
+ _keylist = []
+ _valuelist = []
+
+ def __init__(self, defaults={}):
+ dict.__init__(self)
+ for n,v in defaults.items():
+ self[n] = v
+
+ def __setitem__(self, key, value):
+ self._keylist.append(key)
+ self._valuelist.append(value)
+ return dict.__setitem__(self, key, value)
+
+ def __delattr__(self, key):
+ self._keylist.__delattr__(key)
+ self._valuelist.__delattr__(dict[key])
+ return dict.__delattr__(self, key)
+
+ def __delitem__(self, key):
+ self._keylist.__delitem__(key)
+ self._valuelist.__delitem__(dict[key])
+ return dict.__delitem__(self, key)
+
+ def __iter__(self):
+ raise NotImplementedError("__iter__")
+
+ def __iterkeys__(self):
+ return self._keylist
+
+ def iteritems(self):
+ #return self._valuelist
+ return zip(self._keylist, self._valuelist)
+
+ def items(self):
+ return zip(self._keylist,self._valuelist)
+
+ def __keys__(self):
+ return self._keylist
+
+ def keys(self):
+ return self._keylist
+
+ def __keysattr__(self):
+ return self._keylist
+
+ def pop(self, key):
+ self._keylist.pop(key)
+ self._valuelist.pop(key)
+ return dict.__pop__(self, key)
+
+ def popitem(self):
+ raise NotImplementedError("popitem")
+
+def _testdriver_set():
+ list, list1 = [] ,[]
+ list.append("a")
+ list.append("b")
+ list.append("c")
+
+ list1.append("a")
+ list1.append("b")
+ list1.append("d")
+ list1.append("e")
+ list1.append("e")
+
+ if "a" in list:
+ print "YEAH!"
+
+ a = PseudoSet(list)
+ b = PseudoSet(list1)
+
+ print "a="+str(a)
+ print "b="+str(b)
+ print "a|b=" + str(a|b)
+ print "a="+str(a)
+ print "b="+str(b)
+ print "a&b=" + str(a&b)
+ print "a="+str(a)
+ print "b="+str(b)
+ print "a-b" + str(a-b)
+
+ for key in a:
+ print key
+
+def _testdriver_dict():
+ d = PseudoOrderedDict()
+ d["a"] = 1
+ d["b"] = 2
+ d["c"] = 3
+ d["d"] = 4
+ d["e"] = 5
+ d["f"] = 6
+
+ print "a="+str(d["a"])
+ print "e="+str(d["e"])
+ for key,value in d.iteritems():
+ print "d["+key+"]="+str(d[key])
+ print "key="+str(key)+" value="+str(value)
+
+ print "keys="+str(d.keys())
+
+#_testdriver_dict()
diff --git a/l10ntools/scripts/tool/sdf.py b/l10ntools/scripts/tool/sdf.py
index 33bf90b4ea68..2afcbaf4bb1f 100644
--- a/l10ntools/scripts/tool/sdf.py
+++ b/l10ntools/scripts/tool/sdf.py
@@ -25,70 +25,11 @@
#
#*************************************************************************
-class MyOrderedDict(dict):
- _keylist = []
- _valuelist = []
-
- def __init__(self, defaults={}):
- dict.__init__(self)
- for n,v in defaults.items():
- self[n] = v
-
- def __setitem__(self, key, value):
- self._keylist.append(key)
- self._valuelist.append(value)
- return dict.__setitem__(self, key, value)
-
- def __delattr__(self, key):
- self._keylist.__delattr__(key)
- self._valuelist.__delattr__(dict[key])
- return dict.__delattr__(self, key)
+from pseudo import PseudoSet,PseudoOrderedDict
- def __delitem__(self, key):
- self._keylist.__delitem__(key)
- self._valuelist.__delitem__(dict[key])
- return dict.__delitem__(self, key)
-
- def __iter(self):
- return zip(self._keylist, self._valuelist)
-
- def __iterkeys__(self):
- return self._keylist
-
- def __iteritems__(self):
- return self._valuelist
-
- def items(self):
- return zip(self._keylist,self._valuelist)
-
- def keys(self):
- return self._keylist
-
- def __keysattr__(self):
- return self._keylist
-
- def pop(self, key):
- self._keylist.pop(key)
- self._valuelist.pop(key)
- return dict.__pop__(self, key)
-
- def popitem(self):
- raise NotImplementedError("popitem")
-
- def clear(self):
- self._keylist.clear()
- self._valuelist.clear()
- return dict.clear()
-
- def copy(self):
- newobj = MyOrderedDict(self)
- newobj._keylist = self._keylist
- newobj._valuelist = self._valuelist
- return newobj
-
class SdfData:
_filename = "";
- _dict = MyOrderedDict()
+ _dict = PseudoOrderedDict()
_languages_found = [];
def __init__ (self, filename=""):
@@ -107,7 +48,7 @@ class SdfData:
self._dict[key] = value
def get_languages_found_in_sdf(self):
- return set(self._languages_found)
+ return PseudoSet(self._languages_found)
def read(self):
try:
diff --git a/l10ntools/scripts/tool/xhtex.py b/l10ntools/scripts/tool/xhtex.py
index 99e0f39259a2..c876b9f7c2a0 100644
--- a/l10ntools/scripts/tool/xhtex.py
+++ b/l10ntools/scripts/tool/xhtex.py
@@ -83,6 +83,7 @@ class xhtex(abstractL10nTool):
def merge_file(self, inputfilename, outputfilename, parsed_file_ref, lang,is_forced_lang, sdfdata):
if lang == "en-US":
mod_outputfilename = outputfilename.replace("_en-US",'')
+ self.make_dirs(mod_outputfilename)
self.copy_file(inputfilename, mod_outputfilename)
return
dom = parsed_file_ref.cloneNode(True)