[Lldb-commits] [lldb] r249467 - Update swig generation scripts to support Python 3.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 6 14:11:28 PDT 2015


Author: zturner
Date: Tue Oct  6 16:11:28 2015
New Revision: 249467

URL: http://llvm.org/viewvc/llvm-project?rev=249467&view=rev
Log:
Update swig generation scripts to support Python 3.

Modified:
    lldb/trunk/scripts/Python/buildSwigPython.py
    lldb/trunk/scripts/Python/modify-python-lldb.py
    lldb/trunk/scripts/buildSwigWrapperClasses.py
    lldb/trunk/scripts/finishSwigWrapperClasses.py
    lldb/trunk/scripts/utilsArgsParse.py
    lldb/trunk/scripts/utilsDebug.py
    lldb/trunk/scripts/utilsOsType.py

Modified: lldb/trunk/scripts/Python/buildSwigPython.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/buildSwigPython.py?rev=249467&r1=249466&r2=249467&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/buildSwigPython.py (original)
+++ lldb/trunk/scripts/Python/buildSwigPython.py Tue Oct  6 16:11:28 2015
@@ -123,7 +123,7 @@ def get_header_files( vDictArgs ):
 						"/include/lldb/API/SBValue.h",
 						"/include/lldb/API/SBValueList.h",
 						"/include/lldb/API/SBWatchpoint.h" ];
-	bDebug = vDictArgs.has_key( "-d" );
+	bDebug = "-d" in vDictArgs;
 	strRt = vDictArgs[ "--srcRoot" ];
 	strRt = os.path.normcase( strRt );
 	
@@ -133,8 +133,8 @@ def get_header_files( vDictArgs ):
 		strHeaderFiles += " %s%s" % (strRt, strHdr);
 	
 	if bDebug:
-		print strMsgHdrFiles;
- 		print strHeaderFiles;
+		print(strMsgHdrFiles);
+		print(strHeaderFiles);
 		
 	vDictArgs[ "--headerFiles" ] = strHeaderFiles;
 	
@@ -201,7 +201,7 @@ def get_interface_files( vDictArgs ):
 						"/scripts/interface/SBValue.i",
 						"/scripts/interface/SBValueList.i",
 						"/scripts/interface/SBWatchpoint.i" ];	
-	bDebug = vDictArgs.has_key( "-d" );
+	bDebug = "-d" in vDictArgs;
 	strRt = vDictArgs[ "--srcRoot" ];
 	strRt = os.path.normcase( strRt );
 	
@@ -211,8 +211,8 @@ def get_interface_files( vDictArgs ):
 		strInterfaceFiles += " %s%s" % (strRt, strIFace);
 	
 	if bDebug:
-		print strMsgIFaceFiles;
-		print strInterfaceFiles;
+		print(strMsgIFaceFiles);
+		print(strInterfaceFiles);
 	
 	vDictArgs[ "--ifaceFiles" ] = strInterfaceFiles;
 		
@@ -251,12 +251,12 @@ def which_file_is_newer( vFile1, vFile2
 #--
 def check_file_exists( vDictArgs, vstrFileNamePath ):
 	bExists = False;
-	bDebug = vDictArgs.has_key( "-d" );
+	bDebug = "-d" in vDictArgs;
 	
 	if os.path.exists( vstrFileNamePath ):
 		bExists = True;
 	elif bDebug:
-		print strMsgFileNotExist % vstrFileNamePath;
+		print(strMsgFileNotExist % vstrFileNamePath);
 	
 	return bExists;
 
@@ -271,7 +271,7 @@ def check_file_exists( vDictArgs, vstrFi
 #--
 def check_newer_file( vDictArgs, vstrSwigOpFileNamePath, vstrFileNamePath ):
 	bNeedUpdate = False;
-	bDebug = vDictArgs.has_key( "-d" );
+	bDebug = "-d" in vDictArgs;
 	
 	strMsg = "";
 	nResult = which_file_is_newer( vstrFileNamePath, vstrSwigOpFileNamePath );
@@ -284,7 +284,7 @@ def check_newer_file( vDictArgs, vstrSwi
 		bNeedUpdate = True;
 	
 	if bNeedUpdate and bDebug:
-		print strMsg;
+		print(strMsg);
 	
 	return bNeedUpdate;
 
@@ -328,7 +328,7 @@ def get_framework_python_dir_windows( vD
 	# on the system other stuff may need to be put here as well.
 	from distutils.sysconfig import get_python_lib;
 	strPythonInstallDir = "";
-	bHaveArgPrefix = vDictArgs.has_key( "--prefix" );
+	bHaveArgPrefix = "--prefix" in vDictArgs;
 	if bHaveArgPrefix: 
 		strPythonInstallDir = vDictArgs[ "--prefix" ];
 	if strPythonInstallDir.__len__() != 0:
@@ -354,9 +354,9 @@ def get_framework_python_dir_other_platf
 	bOk = True;
 	strWkDir = "";
 	strErrMsg = "";
-	bDbg = vDictArgs.has_key( "-d" );
+	bDbg = "-d" in vDictArgs;
 	
-	bMakeFileCalled = vDictArgs.has_key( "-m" );
+	bMakeFileCalled = "-m" in vDictArgs;
 	if bMakeFileCalled:
 		dbg.dump_text( "Built by LLVM" );
 		return get_framework_python_dir_windows( vDictArgs );
@@ -368,7 +368,7 @@ def get_framework_python_dir_other_platf
 		strWkDir += "/LLDB.framework";
 		if os.path.exists( strWkDir ):
 			if bDbg:
-				print strMsgFoundLldbFrameWkDir % strWkDir;
+				print(strMsgFoundLldbFrameWkDir % strWkDir);
 			strWkDir += "/Resources/Python/lldb";
 			strWkDir = os.path.normcase( strWkDir );
 		else:
@@ -420,7 +420,7 @@ def get_config_build_dir( vDictArgs, vst
 	strErrMsg = "";
 	
 	strConfigBldDir = "";
-	bHaveConfigBldDir = vDictArgs.has_key( "--cfgBldDir" );
+	bHaveConfigBldDir = "--cfgBldDir" in vDictArgs;
 	if bHaveConfigBldDir:
 		strConfigBldDir = vDictArgs[ "--cfgBldDir" ];
 	if (bHaveConfigBldDir == False) or (strConfigBldDir.__len__() == 0):
@@ -463,8 +463,8 @@ def do_swig_rebuild( vDictArgs, vstrSwig
 	dbg = utilsDebug.CDebugFnVerbose( "Python script do_swig_rebuild()" );
 	bOk = True;
 	strMsg = "";
-	bDbg = vDictArgs.has_key( "-d" );
-	bGenDependencies = vDictArgs.has_key( "-M" );
+	bDbg = "-d" in vDictArgs;
+	bGenDependencies = "-M" in vDictArgs;
 	strSwigExePath = vDictArgs[ "--swigExePath" ];
 	strSwigExeName = vDictArgs[ "--swigExeName" ];
 	strSrcRoot = vDictArgs[ "--srcRoot" ];
@@ -502,7 +502,7 @@ def do_swig_rebuild( vDictArgs, vstrSwig
 	strCmd += "-o \"%s\" " % strOp;
 	strCmd += "\"%s\" " % strIp;
 	if bDbg:
-		print strMsgSwigExecute % strCmd;
+		print(strMsgSwigExecute % strCmd);
 
 	# Execute SWIG
 	process = subprocess.Popen( strCmd, stdout=subprocess.PIPE, 
@@ -547,7 +547,7 @@ def run_python_script( vDictArgs, vstrAr
 	dbg = utilsDebug.CDebugFnVerbose( "Python script run_python_script()" );
 	bOk = True;
 	strMsg = "";
-	bDbg = vDictArgs.has_key( "-d" );
+	bDbg = "-d" in vDictArgs;
 	
 	strPy = "%s %s" % (sys.executable, vstrArgs);
 	process = subprocess.Popen( strPy, shell=True );
@@ -583,7 +583,7 @@ def do_modify_python_lldb( vDictArgs, vs
 	dbg = utilsDebug.CDebugFnVerbose( "Python script do_modify_python_lldb()" );
 	bOk = True;
 	strMsg = "";
-	bDbg = vDictArgs.has_key( "-d" );
+	bDbg = "-d" in vDictArgs;
 	strCwd = vDictArgs[ "--srcRoot" ]; # /llvm/tools/lldb
 	strCwd += "/scripts/Python";
 	strPyScript = "modify-python-lldb.py";
@@ -654,22 +654,22 @@ def main( vDictArgs ):
 	strMsg = "";
 	strErrMsgProgFail = "";
 	
-	if not( vDictArgs.has_key( "--swigExePath" ) and vDictArgs.has_key( "--swigExeName" ) ):
+	if not("--swigExePath" in vDictArgs) and ("--swigExeName" in vDictArgs):
 		strErrMsgProgFail += strErrMsgSwigParamsMissing;
 		return (-100, strErrMsgProgFail );	
 	
-	bDebug = vDictArgs.has_key( "-d" );
+	bDebug = "-d" in vDictArgs;
 	
 	strSwigDepFile = "";
 	strSwigDepOptions = "";
-	bGenDependencies = vDictArgs.has_key( "-M" );
+	bGenDependencies = "-M" in vDictArgs;
 	if bGenDependencies:
 		strSwigDepFile = vDictArgs[ "--targetDir" ] + "/LLDBWrapPython.cpp.d";
 		strSwigDepOptions = "-MMD -MF \"%s.tmp\"" % strSwigDepFile;
 		strSwigDepFile = os.path.normcase( strSwigDepFile );
 		strSwigDepOptions = os.path.normcase( strSwigDepOptions );
 		
-	bMakeFileCalled = vDictArgs.has_key( "-m" );			
+	bMakeFileCalled = "-m" in vDictArgs;
 	strSwigOutputFile = ""
 	if bMakeFileCalled:
 		strSwigOutputFile = vDictArgs[ "--targetDir" ] + "/LLDBWrapPython.cpp";
@@ -760,7 +760,7 @@ def main( vDictArgs ):
 	if bOk and (bNeedUpdate == False):
 		strInitPiPath = strFrameworkPythonDir + "/__init__.py";
 		strInitPiPath = os.path.normcase( strInitPiPath );
-		print strInitPiPath
+		print(strInitPiPath)
 		bNeedUpdate = not check_file_exists( vDictArgs, strInitPiPath );
 		dbg.dump_object( "check_file_exists( vDictArgs, strInitPiPath ), bNeedUpdate =", bNeedUpdate);
 		
@@ -769,12 +769,12 @@ def main( vDictArgs ):
 			strMsg = strMsgNotNeedUpdate;
 			return (0, strMsg );
 		else:
-			print strMsgSwigNeedRebuild;
+			print(strMsgSwigNeedRebuild);
 			bOk, strMsg, nExitResult = do_swig_rebuild( vDictArgs, strSwigDepFile, 
 														strCfgBldDir, 
 														strSwigOutputFile,
 														strSwigInputFile );
-			bGenDependencies = vDictArgs.has_key( "-M" );
+			bGenDependencies = "-M" in vDictArgs;
 			if bGenDependencies == True:
 				return (nExitResult, strMsg);
 				   	
@@ -794,5 +794,5 @@ def main( vDictArgs ):
 # This script can be called by another Python script by calling the main() 
 # function directly
 if __name__ == "__main__":
-	print "Script cannot be called directly, called by buildSwigWrapperClasses.py";
+	print("Script cannot be called directly, called by buildSwigWrapperClasses.py");
 	

Modified: lldb/trunk/scripts/Python/modify-python-lldb.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/modify-python-lldb.py?rev=249467&r1=249466&r2=249467&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/modify-python-lldb.py (original)
+++ lldb/trunk/scripts/Python/modify-python-lldb.py Tue Oct  6 16:11:28 2015
@@ -21,7 +21,11 @@
 # subsystem.
 #
 
-import sys, re, StringIO
+import sys, re
+if sys.version_info.major >= 3:
+    import io as StringIO
+else:
+    import StringIO
 
 if len (sys.argv) != 2:
     output_name = "./lldb.py"
@@ -269,7 +273,7 @@ class NewContent(StringIO.StringIO):
     def add_line(self, a_line):
         """Add a line to the content, if there is a previous line, commit it."""
         if self.prev_line != None:
-            print >> self, self.prev_line
+            self.write(self.prev_line + "\n")
         self.prev_line = a_line
     def del_line(self):
         """Forget about the previous line, do not commit it."""
@@ -281,7 +285,7 @@ class NewContent(StringIO.StringIO):
     def finish(self):
         """Call this when you're finished with populating content."""
         if self.prev_line != None:
-            print >> self, self.prev_line
+            self.write(self.prev_line + "\n")
         self.prev_line = None
 
 # The new content will have the iteration protocol defined for our lldb objects.

Modified: lldb/trunk/scripts/buildSwigWrapperClasses.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/buildSwigWrapperClasses.py?rev=249467&r1=249466&r2=249467&view=diff
==============================================================================
--- lldb/trunk/scripts/buildSwigWrapperClasses.py (original)
+++ lldb/trunk/scripts/buildSwigWrapperClasses.py Tue Oct  6 16:11:28 2015
@@ -126,7 +126,7 @@ def program_exit_success( vnResult, vMsg
 
     if vMsg.__len__() != 0:
         strMsg = "%s: %s (%d)" % (strExitMsgSuccess, vMsg, vnResult);
-        print strMsg;
+        print(strMsg);
 
     sys.exit( vnResult );
 
@@ -139,7 +139,7 @@ def program_exit_success( vnResult, vMsg
 # Throws:   None.
 #--
 def program_exit_on_failure( vnResult, vMsg ):
-    print "%s%s (%d)" % (strExitMsgError, vMsg, vnResult);
+    print("%s%s (%d)" % (strExitMsgError, vMsg, vnResult));
     sys.exit( vnResult );
 
 #++---------------------------------------------------------------------------
@@ -170,7 +170,7 @@ def print_out_input_parameters( vDictArg
         if val.__len__() != 0:
             strEqs = " =";
             strQ = "\"";
-        print "%s%s%s %s%s%s\n" % (strParameter, arg, strEqs, strQ, val, strQ);
+        print("%s%s%s %s%s%s\n" % (strParameter, arg, strEqs, strQ, val, strQ));
 
 #++---------------------------------------------------------------------------
 # Details:  Locate the lldb.swig file. No checking for path correctness is
@@ -193,7 +193,7 @@ def check_lldb_swig_file_exists( vstrSrc
     bOk = os.path.isfile( strFullPath );
     if bOk:
         if gbDbgFlag:
-            print strSwigFileFound;
+            print(strSwigFileFound);
     else:
         strStatusMsg = strSwigFileFoundNotFound % strFullPath;
 
@@ -227,8 +227,8 @@ def run_swig( vStrScriptLang, vSwigBuild
         return (-9, strStatusMsg);
 
     if gbDbgFlag:
-        print strSwigScriptLangFound % vStrScriptLang;
-        print strSwigExecuteMsg % vStrScriptLang;
+        print(strSwigScriptLangFound % vStrScriptLang);
+        print(strSwigExecuteMsg % vStrScriptLang);
 
     # Change where Python looks for our modules
     strDir = os.path.normcase( strScriptFileDir );
@@ -287,16 +287,18 @@ def run_swig_for_each_script_supported(
         listDirs.remove('.svn')
 
     if gbDbgFlag:
-        print strSwigScriptLangsFound,
+        sys.stdout.write(strSwigScriptLangsFound)
         for dir in listDirs:
-            print dir,
-        print "\n";
+            sys.stdout.write(dir)
+        print("\n");
 
     # Iterate script directory find any script language directories
     for scriptLang in listDirs:
-        dbg.dump_text( "Executing language script for \'%s\'" % scriptLang );
-        nResult, strStatusMsg = run_swig( scriptLang, strSwigBuildFileName,
-                                          vDictArgs );
+        # __pycache__ is a magic directory in Python 3 that holds .pyc files
+        if scriptLang != "__pycache__":
+            dbg.dump_text( "Executing language script for \'%s\'" % scriptLang );
+            nResult, strStatusMsg = run_swig( scriptLang, strSwigBuildFileName,
+                                              vDictArgs );
         if nResult < 0:
             break;
 
@@ -503,7 +505,7 @@ def main( vArgv ):
         program_exit( -4, strMsgErrorOsTypeUnknown );
 
     global gbDbgFlag;
-    gbDbgFlag = dictArgs.has_key( "-d" );
+    gbDbgFlag = "-d" in dictArgs;
     if gbDbgFlag:
         print_out_input_parameters( dictArgs );
 
@@ -513,8 +515,8 @@ def main( vArgv ):
     # called by this program
     global gbMakeFileFlag;
     global gbSwigGenDepFileFlag;
-    gbMakeFileFlag = dictArgs.has_key( "-m" );
-    gbSwigGenDepFileFlag = dictArgs.has_key( "-M" );
+    gbMakeFileFlag = "-m" in dictArgs;
+    gbSwigGenDepFileFlag = "-M" in dictArgs;
 
     bOk, strMsg = check_lldb_swig_file_exists( dictArgs[ "--srcRoot" ], eOSType );
     if bOk == False:

Modified: lldb/trunk/scripts/finishSwigWrapperClasses.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/finishSwigWrapperClasses.py?rev=249467&r1=249466&r2=249467&view=diff
==============================================================================
--- lldb/trunk/scripts/finishSwigWrapperClasses.py (original)
+++ lldb/trunk/scripts/finishSwigWrapperClasses.py Tue Oct  6 16:11:28 2015
@@ -97,7 +97,7 @@ def program_exit_success( vnResult, vMsg
 
     if vMsg.__len__() != 0:
         strMsg = "%s: %s (%d)" % (strExitMsgSuccess, vMsg, vnResult);
-        print strMsg;
+        print(strMsg);
 
     sys.exit( vnResult );
 
@@ -110,7 +110,7 @@ def program_exit_success( vnResult, vMsg
 # Throws:   None.
 #--
 def program_exit_on_failure( vnResult, vMsg ):
-    print "%s%s (%d)" % (strExitMsgError, vMsg, vnResult);
+    print("%s%s (%d)" % (strExitMsgError, vMsg, vnResult));
     sys.exit( vnResult );
 
 #++---------------------------------------------------------------------------
@@ -141,7 +141,7 @@ def print_out_input_parameters( vDictArg
         if val.__len__() != 0:
             strEqs = " =";
             strQ = "\"";
-        print "%s%s%s %s%s%s\n" % (strParameter, arg, strEqs, strQ, val, strQ);
+        print("%s%s%s %s%s%s\n" % (strParameter, arg, strEqs, strQ, val, strQ));
 
 #++---------------------------------------------------------------------------
 # Details:  Validate the arguments passed to the program. This function exits
@@ -210,8 +210,8 @@ def run_post_process( vStrScriptLang, vs
         return (-9, strStatusMsg);
 
     if gbDbgFlag:
-        print strScriptLangFound % vStrScriptLang;
-        print strExecuteMsg % vStrScriptLang;
+        print(strScriptLangFound % vStrScriptLang);
+        print(strExecuteMsg % vStrScriptLang);
 
     # Change where Python looks for our modules
     strDir = os.path.normcase( strScriptFileDir );
@@ -267,16 +267,18 @@ def run_post_process_for_each_script_sup
         listDirs.remove('.svn')
 
     if gbDbgFlag:
-        print strScriptLangsFound,
+        sys.stdout.write(strScriptLangsFound)
         for dir in listDirs:
-            print dir,
-        print "\n";
+            sys.stdout.write(dir)
+        print("\n")
 
     # Iterate script directory find any script language directories
     for scriptLang in listDirs:
-        dbg.dump_text( "Executing language script for \'%s\'" % scriptLang );
-        nResult, strStatusMsg = run_post_process( scriptLang, strFinishFileName,
-                                                  vDictArgs );
+        # __pycache__ is a magic directory in Python 3 that holds .pyc files
+        if scriptLang != "__pycache__":
+            dbg.dump_text( "Executing language script for \'%s\'" % scriptLang );
+            nResult, strStatusMsg = run_post_process( scriptLang, strFinishFileName,
+                                                      vDictArgs );
         if nResult < 0:
             break;
 

Modified: lldb/trunk/scripts/utilsArgsParse.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/utilsArgsParse.py?rev=249467&r1=249466&r2=249467&view=diff
==============================================================================
--- lldb/trunk/scripts/utilsArgsParse.py (original)
+++ lldb/trunk/scripts/utilsArgsParse.py Tue Oct  6 16:11:28 2015
@@ -87,7 +87,7 @@ def parse( vArgv, vstrListArgs, vListLon
 	
 	# Count the number of mandatory args required (if any one found)
 	countMandatory = 0;
-	for opt, man in vDictArgReq.iteritems():
+	for opt, man in vDictArgReq.items():
 		if man == "m":
 		  countMandatory = countMandatory + 1;
 	

Modified: lldb/trunk/scripts/utilsDebug.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/utilsDebug.py?rev=249467&r1=249466&r2=249467&view=diff
==============================================================================
--- lldb/trunk/scripts/utilsDebug.py (original)
+++ lldb/trunk/scripts/utilsDebug.py Tue Oct  6 16:11:28 2015
@@ -55,9 +55,9 @@ class CDebugFnVerbose:
 	def dump_object( self, vstrText, vObject ):
 		if CDebugFnVerbose.bVerboseOn == False:
 			return;
-		print "%d%s> Dp: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(), 
-								vstrText),;
-		print vObject;
+		sys.stdout.write("%d%s> Dp: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(), 
+								vstrText));
+		print(vObject);
 	
 	#++------------------------------------------------------------------------
 	# Details:	Print out some progress text given by the client.
@@ -69,8 +69,8 @@ class CDebugFnVerbose:
 	def dump_text( self, vstrText ):
 		if CDebugFnVerbose.bVerboseOn == False:
 			return;
-		print "%d%s> Dp: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(),
-								vstrText);
+		print("%d%s> Dp: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(),
+								vstrText));
 				
 	# Private methods:
 	def __init__( self, vstrFnName ):
@@ -100,8 +100,8 @@ class CDebugFnVerbose:
 	#--
 	def __indent_back( self ):
 		if CDebugFnVerbose.bVerboseOn:
-			print "%d%s< fn: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(),
-									self.__strFnName);
+			print("%d%s< fn: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(),
+									self.__strFnName));
 		CDebugFnVerbose.__nLevel -= 1;
 
 	#++------------------------------------------------------------------------
@@ -116,8 +116,8 @@ class CDebugFnVerbose:
 		CDebugFnVerbose.__nLevel += 1;
 		self.__strFnName = vstrFnName;
 		if CDebugFnVerbose.bVerboseOn:
-			print "%d%s> fn: %s" % ( CDebugFnVerbose.__nLevel, self.__get_dots(), 
-									 self.__strFnName);
+			print("%d%s> fn: %s" % ( CDebugFnVerbose.__nLevel, self.__get_dots(), 
+									 self.__strFnName));
 
 	# Private statics attributes:
 	__nLevel = 0;	# Indentation level counter

Modified: lldb/trunk/scripts/utilsOsType.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/utilsOsType.py?rev=249467&r1=249466&r2=249467&view=diff
==============================================================================
--- lldb/trunk/scripts/utilsOsType.py (original)
+++ lldb/trunk/scripts/utilsOsType.py Tue Oct  6 16:11:28 2015
@@ -26,22 +26,32 @@ import sys      # Provide system informa
 # Authors:  Illya Rudkin 28/11/2013.
 # Changes:  None.
 #--
-class EnumOsType( object ):
-    values = [  "Unknown",
-                "Darwin",
-                "FreeBSD",
-                "Linux", 
-                "NetBSD",
-                "Windows" ]
-    class __metaclass__( type ):
+if sys.version_info.major >= 3:
+    from enum import Enum
+    class EnumOsType(Enum):
+        Unknown = 0
+        Darwin = 1
+        FreeBSD = 2
+        Linux = 3
+        NetBSD = 4
+        Windows = 5
+else:
+    class EnumOsType( object ):
+        values = [  "Unknown",
+                    "Darwin",
+                    "FreeBSD",
+                    "Linux", 
+                    "NetBSD",
+                    "Windows" ]
+        class __metaclass__( type ):
 #++---------------------------------------------------------------------------
 # Details:  Fn acts as an enumeration.
 # Args:     vName - (R) Enumeration to match.
 # Returns:  Int - Matching enumeration/index.
 # Throws:   None.
 #--
-        def __getattr__( self, vName ):
-            return self.values.index( vName );
+            def __getattr__( self, vName ):
+                return self.values.index( vName );
 
 #++---------------------------------------------------------------------------
 # Details:  Reverse fast lookup of the values list.
@@ -49,8 +59,8 @@ class EnumOsType( object ):
 # Returns:  Str - text description matching enumeration.
 # Throws:   None.
 #--
-        def name_of( self, vI ):
-            return EnumOsType.values[ vI ];
+            def name_of( self, vI ):
+                return EnumOsType.values[ vI ];
 
 #-----------------------------------------------------------------------------
 #-----------------------------------------------------------------------------




More information about the lldb-commits mailing list