make load_module compatible with python 3.2
authorRalf Jung <post@ralfj.de>
Tue, 11 Nov 2014 10:18:51 +0000 (11:18 +0100)
committerRalf Jung <post@ralfj.de>
Tue, 11 Nov 2014 10:18:51 +0000 (11:18 +0100)
mass_build.py

index c5f4dddf9a1f11fbbab85b882baa3dc824b067f4..79bc17a9db3f41edfe6c0c74eff1f2a570e2569b 100755 (executable)
@@ -20,14 +20,20 @@ import vcs, build_system
 import argparse, os, sys, subprocess
 from collections import OrderedDict
 
 import argparse, os, sys, subprocess
 from collections import OrderedDict
 
-# helper funcrions
+# helper functions
 def load_module(name, path, write_bytecode = False):
 def load_module(name, path, write_bytecode = False):
-       import importlib.machinery
-       old_val = sys.dont_write_bytecode
-       sys.dont_write_bytecode = not write_bytecode
-       module = importlib.machinery.SourceFileLoader(name, path).load_module()
-       sys.dont_write_bytecode = old_val
-       return module
+    old_val = sys.dont_write_bytecode
+    sys.dont_write_bytecode = not write_bytecode
+    module = None
+    try:
+        from importlib.machinery import SourceFileLoader
+        module = SourceFileLoader(name, path).load_module()
+    except ImportError:
+        import imp
+        module = imp.load_source(name, path)
+    finally:
+        sys.dont_write_bytecode = old_val
+    return module
 
 # an entire Project
 class Project:
 
 # an entire Project
 class Project: