Revision: 9141
          http://sourceforge.net/p/playerstage/svn/9141
Author:   jpgr87
Date:     2014-11-02 16:26:25 +0000 (Sun, 02 Nov 2014)
Log Message:
-----------
Port interface and xdr generators to python 3

The xdr and interface generation scripts have been ported to python 3 with the 
help of the python "2to3" script.  Both scripts now work with python >= 2.6.

Player can now be built on systems without a python 2 interpreter.

Modified Paths:
--------------
    code/player/trunk/libplayerinterface/playerinterfacegen.py
    code/player/trunk/libplayerinterface/playerxdrgen.py

Modified: code/player/trunk/libplayerinterface/playerinterfacegen.py
===================================================================
--- code/player/trunk/libplayerinterface/playerinterfacegen.py  2014-02-18 
02:50:47 UTC (rev 9140)
+++ code/player/trunk/libplayerinterface/playerinterfacegen.py  2014-11-02 
16:26:25 UTC (rev 9141)
@@ -22,12 +22,15 @@
 # *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 
USA
 # */
 
+from __future__ import print_function
+
 import re
 import string
 import sys
 import os
 import glob
 
+
 HEADER_MODE = "--header"
 FUNCTIONTABLE_MODE = "--functiontable"
 UTILS_MODE = "--utils"
@@ -43,14 +46,14 @@
 def get_interface(filename):
   interface_filename = os.path.splitext(os.path.split(filename)[-1])[0]
   interface_code = int(interface_filename.split("_")[0])
-  interface_name = string.join(interface_filename.split("_")[1:],'_').lower()
+  interface_name = "_".join(interface_filename.split("_")[1:]).lower()
   return (interface_code, interface_name)
 
 def processfile(mode, filename, plugin):
   interface_code, interface_name = get_interface(filename)
   interface_def = "PLAYER_%s_CODE" % interface_name.upper()
 
-  print >> sys.stderr, "Processing interface: ", interface_code, interface_name
+  print("Processing interface: ", interface_code, interface_name, 
file=sys.stderr)
   
   # now we process the input file
   interface_file = open(filename, 'r')
@@ -103,13 +106,13 @@
 
     ifndefsymbol = '_' + interface_name.upper() + '_INTERFACE_H_'
     if plugin:
-      print '#ifndef ' + ifndefsymbol
-      print '#define ' + ifndefsymbol + '\n'
+      print('#ifndef ' + ifndefsymbol)
+      print('#define ' + ifndefsymbol + '\n')
       
-      print "#include <libplayerinterface/player.h>"
+      print("#include <libplayerinterface/player.h>")
     
     
-    print """
+    print("""
 /** @ingroup message_codes
  * @{ */
 #define %(interface_def)s %(interface_code)d
@@ -139,26 +142,26 @@
   "interface_code" : interface_code,  
   "interface_messages" : message_string,  
   "interface_types" : interface_types,  
-  "interface_comment" : interface_comment}  
+  "interface_comment" : interface_comment})  
     if plugin:
-      print "#endif // " + ifndefsymbol
+      print("#endif // " + ifndefsymbol)
   elif mode == FUNCTIONTABLE_MODE:
     if plugin:
-      print """
+      print("""
 #include "%(interface_name)s_interface.h"
 #include "%(interface_name)s_xdr.h"
 
 // Function table for this interface
 static playerxdr_function_t %(interface_name)s_ftable[] =
 {
-""" % {"interface_name": interface_name}
-    print "\n  /* %s messages */" % interface_name
+""" % {"interface_name": interface_name})
+    print("\n  /* %s messages */" % interface_name)
     for m in interface_messages:
       if m.datatype != "NULL":
-        print "  {", interface_def, ",", m.msg_type, ",", 
m.msg_subtype_string, ","
-        print "    (player_pack_fn_t)%(dt_base)s_pack, 
(player_copy_fn_t)%(dt)s_copy, 
(player_cleanup_fn_t)%(dt)s_cleanup,(player_clone_fn_t)%(dt)s_clone,(player_free_fn_t)%(dt)s_free,(player_sizeof_fn_t)%(dt)s_sizeof},"
 % { "dt_base": m.datatype[:-2], "dt": m.datatype}
+        print("  {", interface_def, ",", m.msg_type, ",", 
m.msg_subtype_string, ",")
+        print("    (player_pack_fn_t)%(dt_base)s_pack, 
(player_copy_fn_t)%(dt)s_copy, 
(player_cleanup_fn_t)%(dt)s_cleanup,(player_clone_fn_t)%(dt)s_clone,(player_free_fn_t)%(dt)s_free,(player_sizeof_fn_t)%(dt)s_sizeof},"
 % { "dt_base": m.datatype[:-2], "dt": m.datatype})
     if plugin:
-      print """
+      print("""
   /* This NULL element signals the end of the list */
   {0,0,0,NULL,NULL,NULL}
 };
@@ -179,7 +182,7 @@
 {
     return %(interface_name)s_ftable;
 }
-""" % {"interface_name": interface_name}
+""" % {"interface_name": interface_name})
     
 
 def process_for_utils(targetfile):
@@ -188,7 +191,7 @@
     for file in glob.glob(os.path.join(targetfile ,"*.def")):
       if not os.path.isdir(file):
         interfaces.append(get_interface(file))
-  print """  
+  print("""  
   /* this array lists the interfaces that Player knows how to load
   * It is important that this list is kept in strict numerical order
   * with respect to the interface numeric codes.
@@ -196,18 +199,18 @@
   * NOTE: the last element must be NULL
   */
 static player_interface_t interfaces[] = {  
-  """
+  """)
   interfaces.sort()
   last_code = -1 # start at -1 so that we generate and entry for 0
   for interface in interfaces:
     last_code += 1
     while interface[0] > last_code:
-      print """  {0xFFFF, "nointerf%d"},""" % last_code
+      print("""  {0xFFFF, "nointerf%d"},""" % last_code)
       last_code += 1
-    print """  {PLAYER_%(i)s_CODE, PLAYER_%(i)s_STRING},""" % {"i" : 
interface[1].upper() }
-  print """
+    print("""  {PLAYER_%(i)s_CODE, PLAYER_%(i)s_STRING},""" % {"i" : 
interface[1].upper() })
+  print("""
   {0,NULL}
-};""" 
+};""") 
 
 if __name__ == '__main__':
   mode = HEADER_MODE
@@ -216,7 +219,7 @@
 
   for option in sys.argv[1:]:
     if option == "-h" or option == "--help":
-      print USAGE
+      print(USAGE)
       sys.exit(-1)
     elif option == HEADER_MODE or option == FUNCTIONTABLE_MODE or option == 
UTILS_MODE:
       mode = option
@@ -228,12 +231,12 @@
   if targets == []:
       targets = ["interfaces"]
       
-  print "/* START OF AUTOGENERATED CODE */"
+  print("/* START OF AUTOGENERATED CODE */")
   if plugin:
-    print "/* This file or section was automatically generated by 
playerinterfacegen.py */"
+    print("/* This file or section was automatically generated by 
playerinterfacegen.py */")
   else:
-    print "/* This file or section was automatically generated by 
playerinterfacegen.py"
-    print "To modify the interfaces in this file please edit their interface 
definition in libplayerinterface/interfaces/ */"
+    print("/* This file or section was automatically generated by 
playerinterfacegen.py")
+    print("To modify the interfaces in this file please edit their interface 
definition in libplayerinterface/interfaces/ */")
 
   for target in targets:
     if mode == UTILS_MODE:
@@ -251,5 +254,5 @@
       else:
         processfile(mode, target, plugin)
 
-  print "/* END OF AUTOGENERATED CODE */"
+  print("/* END OF AUTOGENERATED CODE */")
 

Modified: code/player/trunk/libplayerinterface/playerxdrgen.py
===================================================================
--- code/player/trunk/libplayerinterface/playerxdrgen.py        2014-02-18 
02:50:47 UTC (rev 9140)
+++ code/player/trunk/libplayerinterface/playerxdrgen.py        2014-11-02 
16:26:25 UTC (rev 9141)
@@ -5,6 +5,8 @@
 #    header gets installed for general use, has copyright boilerplate,
 #    etc.) or a user XDR lib
 
+from __future__ import print_function
+
 import re
 import string
 import sys
@@ -82,7 +84,7 @@
   declpattern = re.compile('\s*([^;]*?;)', re.MULTILINE)
   
   def __init__(self, body):
-    split = string.split(body)
+    split = body.split()
     self.prefix = split[2]
     self.typename = split[-1]
     self.dynamic = False
@@ -93,8 +95,8 @@
     # pick out the contents of the struct
     varpart = self.contentspattern.findall(body)
     if len(varpart) != 1:
-      print 'skipping nested / empty struct ' + typename
-      raise "Empty Struct"
+      print('skipping nested / empty struct ' + typename)
+      raise Exception("Empty Struct")
     # separate the variable declarations
     decls = self.declpattern.findall(varpart[0])
     for dstring in decls:
@@ -456,7 +458,7 @@
 if __name__ == '__main__':
 
   if len(sys.argv) < 4:
-    print USAGE
+    print(USAGE)
     sys.exit(-1)
 
   distro = 0
@@ -464,7 +466,7 @@
   idx = 1
   if sys.argv[1] == '-distro':
     if len(sys.argv) < 5:
-      print USAGE
+      print(USAGE)
       sys.exit(-1)
     distro = 1
     idx += 1
@@ -478,7 +480,7 @@
   if len(sys.argv) > idx:
     for opt in sys.argv[idx:]:
       infilenames.append(opt)
-      print "processeing extra file ", opt
+      print("processeing extra file ", opt)
 
 
   # Read in the entire file
@@ -568,7 +570,7 @@
                    re.MULTILINE)
   structs = pattern.findall(instream)
 
-  print 'Found ' + `len(structs)` + ' struct(s)'
+  print('Found ' + repr(len(structs)) + ' struct(s)')
   
   #arraypattern = re.compile('\[\s*(\w*?)\s*\]')
 #  pointerpattern = re.compile('[A-Za-z0-9_]+\*|\*[A-Za-z0-9_]+')

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to