From 20c3de818dc4e70ca4f5232153fd28666b50ab42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Matox?= Date: Fri, 22 Sep 2006 10:37:44 +0000 Subject: [PATCH] Fix compatibility with python 2.2.0 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_4_X@15117 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ChangeLog | 10 ++++++- lib/configure.py | 12 +++++--- lib/scripts/TeXFiles.py | 51 +++++++++++++++++++++++++++++++++ lib/scripts/fig_copy.py | 15 ++++++++++ lib/scripts/lyxpreview_tools.py | 15 ++++++++++ 5 files changed, 98 insertions(+), 5 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 5f94c4dc61..d46d10a9b9 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,4 +1,12 @@ -2009-09-21 José Matos +2006-09-22 José Matos + + * scripts/lyxpreview_tools.py + * scripts/fig_copy.py + * scripts/TeXFiles.py + * configure.py: make code compatible with python 2.2.0 and document + the changes. + +2006-09-21 José Matos * configure.py: make it compatible with python 2.2 diff --git a/lib/configure.py b/lib/configure.py index f36cdbb7ad..9553083030 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -579,10 +579,14 @@ def checkLatexConfig(check_config, bool_docbook, bool_linuxdoc): for line in open('chkconfig.vars').readlines(): key, val = re.sub('-', '_', line).split('=') val = val.strip() - tmp = val.split("'") - while tmp and not tmp[0]: tmp = tmp[1:] - while tmp and not tmp[-1]: tmp = tmp[:-1] - values[key] = "'".join(tmp) + try: + values[key] = val.strip("'") + except TypeError: + # workaround for python 2.2.0 and 2.2.1 + tmp = val.split("'") + while tmp and not tmp[0]: tmp = tmp[1:] + while tmp and not tmp[-1]: tmp = tmp[:-1] + values[key] = "'".join(tmp) # chk_fontenc may not exist try: addToRC(r'\font_encoding "%s"' % values["chk_fontenc"]) diff --git a/lib/scripts/TeXFiles.py b/lib/scripts/TeXFiles.py index 48987ad9d8..77413ed63b 100755 --- a/lib/scripts/TeXFiles.py +++ b/lib/scripts/TeXFiles.py @@ -33,6 +33,9 @@ # relies on python and kpsewhich (no shell command is used). # +# this import is required for 2.2 compatibility +from __future__ import generators + import os, sys, re cls_stylefile = 'clsFiles.lst' @@ -40,6 +43,54 @@ sty_stylefile = 'styFiles.lst' bst_stylefile = 'bstFiles.lst' bib_files = 'bibFiles.lst' +# this code was taken from twisted +# http://twistedmatrix.com/trac/browser/trunk/twisted/python/compat.py?rev=14178&format=txt +# and allow us to use os.walk with python 2.2 +try: + os.walk +except AttributeError: + if sys.version_info[:3] == (2, 2, 0): + __builtin__.True = (1 == 1) + __builtin__.False = (1 == 0) + def bool(value): + """Demote a value to 0 or 1, depending on its truth value + + This is not to be confused with types.BooleanType, which is + way too hard to duplicate in 2.1 to be worth the trouble. + """ + return not not value + __builtin__.bool = bool + del bool + + def walk(top, topdown=True, onerror=None): + from os.path import join, isdir, islink + + try: + names = os.listdir(top) + except OSError, e: + if onerror is not None: + onerror(err) + return + + nondir, dir = [], [] + nameLists = [nondir, dir] + for name in names: + nameLists[isdir(join(top, name))].append(name) + + if topdown: + yield top, dir, nondir + + for name in dir: + path = join(top, name) + if not islink(path): + for x in walk(path, topdown, onerror): + yield x + + if not topdown: + yield top, dir, nondir + os.walk = walk +# end compatibility chunk + def cmdOutput(cmd): '''utility function: run a command and get its output as a string cmd: command to run diff --git a/lib/scripts/fig_copy.py b/lib/scripts/fig_copy.py index 8f33efa807..8739ecf1ca 100644 --- a/lib/scripts/fig_copy.py +++ b/lib/scripts/fig_copy.py @@ -20,6 +20,21 @@ import os, sys +# compatibility with python 2.2 +if sys.version_info[:3] == (2, 2, 0): + __builtin__.True = (1 == 1) + __builtin__.False = (1 == 0) + def bool(value): + """Demote a value to 0 or 1, depending on its truth value + + This is not to be confused with types.BooleanType, which is + way too hard to duplicate in 2.1 to be worth the trouble. + """ + return not not value + __builtin__.bool = bool + del bool +# end compatibility chunk + if len(sys.argv) != 3: print >> sys.stderr, "Usage: fig_copy.py " sys.exit(1) diff --git a/lib/scripts/lyxpreview_tools.py b/lib/scripts/lyxpreview_tools.py index bab609706a..dc4986ce24 100644 --- a/lib/scripts/lyxpreview_tools.py +++ b/lib/scripts/lyxpreview_tools.py @@ -16,6 +16,21 @@ import os, re, string, sys, tempfile +# compatibility with python 2.2 +if sys.version_info[:3] == (2, 2, 0): + __builtin__.True = (1 == 1) + __builtin__.False = (1 == 0) + def bool(value): + """Demote a value to 0 or 1, depending on its truth value + + This is not to be confused with types.BooleanType, which is + way too hard to duplicate in 2.1 to be worth the trouble. + """ + return not not value + __builtin__.bool = bool + del bool +# end compatibility chunk + use_win32_modules = 0 if os.name == "nt": use_win32_modules = 1