src/*.py : Make it work for Python 2 and 3. Thanks Michael.

This commit is contained in:
Erik de Castro Lopo 2011-12-24 08:14:24 +11:00
parent acf4b7807b
commit 6cc206055e
3 changed files with 61 additions and 55 deletions

View File

@ -1,3 +1,8 @@
2011-11-24 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/binheader_writef_check.py src/create_symbols_file.py
Make it work for Python 2 and 3. Thanks Michael.
2011-11-19 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* libsndfile.spec.in

View File

@ -48,19 +48,19 @@ def find_binheader_writefs (data):
def find_format_string (s):
fmt = re.search ('"([^"]+)"', s)
if not fmt:
print "Bad format in :\n\n\t%s\n\n" % s
print ("Bad format in :\n\n\t%s\n\n" % s)
sys.exit (1)
fmt = fmt.groups ()
if len (fmt) != 1:
print "Bad format in :\n\n\t%s\n\n" % s
print ("Bad format in :\n\n\t%s\n\n" % s)
sys.exit (1)
return _whitespace_re.sub ("", fmt [0])
def get_param_list (data):
dlist = re.search ("\((.+)\)\s*;", data)
dlist = dlist.groups ()[0]
dlist = string.split (dlist, ",")
dlist = [string.strip (x) for x in dlist]
dlist = dlist.split(",")
dlist = [x.strip() for x in dlist]
return dlist [2:]
def handle_file (fname):
@ -88,13 +88,14 @@ def handle_file (fname):
# print item
# print " param [%d] %c : %s <-> %s" % (param_index, ch, params [param_index], params [param_index + 1])
if string.find (params [param_index + 1], "sizeof") < 0 \
and string.find (params [param_index + 1], "make_size_t") < 0 \
and string.find (params [param_index + 1], "strlen") < 0:
if errors == 0: print
print "\n%s :" % fname
print " param [%d] %c : %s <-> %s" % (param_index, ch, params [param_index], params [param_index + 1])
print " %s" % item
print (params [param_index + 1])
if params [param_index + 1].find ("sizeof") < 0 \
and params [param_index + 1].find ("make_size_t") < 0 \
and params [param_index + 1].find ("strlen") < 0:
if errors == 0: sys.stdout.write ("\n")
print ("\n%s :" % fname)
print (" param [%d] %c : %s <-> %s" % (param_index, ch, params [param_index], params [param_index + 1]))
print (" %s" % item)
errors += 1
param_index += 2
@ -103,14 +104,14 @@ def handle_file (fname):
#===============================================================================
if len (sys.argv) > 1:
print "\n binheader_writef_check :",
sys.stdout.write ("\n binheader_writef_check :")
sys.stdout.flush ()
errors = 0
for fname in sys.argv [1:]:
errors += handle_file (fname)
if errors > 0:
print "\nErrors : %d\n" % errors
print ("\nErrors : %d\n" % errors)
sys.exit (1)
print "ok\n"
print ("ok\n")

View File

@ -79,61 +79,61 @@ ALL_SYMBOLS = (
#-------------------------------------------------------------------------------
def linux_symbols (progname, version):
print "# Auto-generated by %s\n" %progname
print "libsndfile.so.%s" % version
print "{"
print " global:"
print ("# Auto-generated by %s\n" %progname)
print ("libsndfile.so.%s" % version)
print ("{")
print (" global:")
for name, ordinal in ALL_SYMBOLS:
if name == "sf_wchar_open":
continue
print " %s ;" % name
print " local:"
print " * ;"
print "} ;"
print
print (" %s ;" % name)
print (" local:")
print (" * ;")
print ("} ;")
sys.stdout.write ("\n")
return
def darwin_symbols (progname, version):
print "# Auto-generated by %s\n" %progname
print ("# Auto-generated by %s\n" %progname)
for name, ordinal in ALL_SYMBOLS:
if name == "sf_wchar_open":
continue
print "_%s" % name
print
print ("_%s" % name)
sys.stdout.write ("\n")
return
def win32_symbols (progname, version, name):
print "; Auto-generated by %s\n" %progname
print "LIBRARY %s-%s.dll" % (name, re.sub ("\..*", "", version))
print "EXPORTS\n"
print ("; Auto-generated by %s\n" %progname)
print ("LIBRARY %s-%s.dll" % (name, re.sub ("\..*", "", version)))
print ("EXPORTS\n")
for name, ordinal in ALL_SYMBOLS:
print "%-20s @%s" % (name, ordinal)
print
print ("%-20s @%s" % (name, ordinal))
sys.stdout.write ("\n")
return
def os2_symbols (progname, version, name):
print "; Auto-generated by %s\n" %progname
print "LIBRARY %s%s" % (name, re.sub ("\..*", "", version))
print "INITINSTANCE TERMINSTANCE"
print "CODE PRELOAD MOVEABLE DISCARDABLE"
print "DATA PRELOAD MOVEABLE MULTIPLE NONSHARED"
print "EXPORTS\n"
print ("; Auto-generated by %s\n" %progname)
print ("LIBRARY %s%s" % (name, re.sub ("\..*", "", version)))
print ("INITINSTANCE TERMINSTANCE")
print ("CODE PRELOAD MOVEABLE DISCARDABLE")
print ("DATA PRELOAD MOVEABLE MULTIPLE NONSHARED")
print ("EXPORTS\n")
for name, ordinal in ALL_SYMBOLS:
if name == "sf_wchar_open":
continue
print "_%-20s @%s" % (name, ordinal)
print
print ("_%-20s @%s" % (name, ordinal))
sys.stdout.write ("\n")
return
def plain_symbols (progname, version, name):
for name, ordinal in ALL_SYMBOLS:
print name
print (name)
def no_symbols (os_name):
print
print "No known way of restricting exported symbols on '%s'." % os_name
print "If you know a way, please contact the author."
print
sys.stdout.write ("\n")
print ("No known way of restricting exported symbols on '%s'." % os_name)
print ("If you know a way, please contact the author.")
sys.stdout.write ("\n")
return
#-------------------------------------------------------------------------------
@ -141,17 +141,17 @@ def no_symbols (os_name):
progname = re.sub (".*[\\/]", "", sys.argv [0])
if len (sys.argv) != 3:
print
print "Usage : %s <target OS name> <libsndfile version>." % progname
print
print " Currently supported values for target OS are:"
print " linux"
print " darwin (ie MacOSX)"
print " win32 (ie wintendo)"
print " cygwin (Cygwin on wintendo)"
print " os2 (OS/2)"
print " plain (plain list of symbols)"
print
sys.stdout.write ("\n")
print ("Usage : %s <target OS name> <libsndfile version>." % progname)
sys.stdout.write ("\n")
print (" Currently supported values for target OS are:")
print (" linux")
print (" darwin (ie MacOSX)")
print (" win32 (ie wintendo)")
print (" cygwin (Cygwin on wintendo)")
print (" os2 (OS/2)")
print (" plain (plain list of symbols)")
sys.stdout.write ("\n")
sys.exit (1)
os_name = sys.argv [1]