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
This commit is contained in:
José Matox 2006-09-22 10:37:44 +00:00
parent 75ffbdd2e0
commit 20c3de818d
5 changed files with 98 additions and 5 deletions

View File

@ -1,4 +1,12 @@
2009-09-21 José Matos <jamatos@lyx.org> 2006-09-22 José Matos <jamatos@lyx.org>
* 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 <jamatos@lyx.org>
* configure.py: make it compatible with python 2.2 * configure.py: make it compatible with python 2.2

View File

@ -579,6 +579,10 @@ def checkLatexConfig(check_config, bool_docbook, bool_linuxdoc):
for line in open('chkconfig.vars').readlines(): for line in open('chkconfig.vars').readlines():
key, val = re.sub('-', '_', line).split('=') key, val = re.sub('-', '_', line).split('=')
val = val.strip() val = val.strip()
try:
values[key] = val.strip("'")
except TypeError:
# workaround for python 2.2.0 and 2.2.1
tmp = val.split("'") tmp = val.split("'")
while tmp and not tmp[0]: tmp = tmp[1:] while tmp and not tmp[0]: tmp = tmp[1:]
while tmp and not tmp[-1]: tmp = tmp[:-1] while tmp and not tmp[-1]: tmp = tmp[:-1]

View File

@ -33,6 +33,9 @@
# relies on python and kpsewhich (no shell command is used). # 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 import os, sys, re
cls_stylefile = 'clsFiles.lst' cls_stylefile = 'clsFiles.lst'
@ -40,6 +43,54 @@ sty_stylefile = 'styFiles.lst'
bst_stylefile = 'bstFiles.lst' bst_stylefile = 'bstFiles.lst'
bib_files = 'bibFiles.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): def cmdOutput(cmd):
'''utility function: run a command and get its output as a string '''utility function: run a command and get its output as a string
cmd: command to run cmd: command to run

View File

@ -20,6 +20,21 @@
import os, sys 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: if len(sys.argv) != 3:
print >> sys.stderr, "Usage: fig_copy.py <from file> <to file>" print >> sys.stderr, "Usage: fig_copy.py <from file> <to file>"
sys.exit(1) sys.exit(1)

View File

@ -16,6 +16,21 @@
import os, re, string, sys, tempfile 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 use_win32_modules = 0
if os.name == "nt": if os.name == "nt":
use_win32_modules = 1 use_win32_modules = 1