Move loading a module by filename into a helper function
authorRalf Jung <post@ralfj.de>
Mon, 23 Sep 2013 15:33:50 +0000 (17:33 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 23 Sep 2013 15:33:50 +0000 (17:33 +0200)
mass_build.py

index 88db907bd01ebb41fdfab6eadca4aa66d684cfec..e327b7ee2e91c23ea86b6226f949813de281c5ae 100755 (executable)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
-import vcs, build_system, importlib.machinery
+import vcs, build_system
 import argparse, os, sys, subprocess
 from collections import OrderedDict
 
+# helper funcrions
+def load_module(name, path):
+       import importlib.machinery
+       old_val = sys.dont_write_bytecode
+       sys.dont_write_bytecode = True
+       module = importlib.machinery.SourceFileLoader(name, path).load_module()
+       sys.dont_write_bytecode = old_val
+       return module
+
 # an entire Project
 class Project:
        def __init__(self, folder, config):
@@ -78,11 +87,8 @@ args = parser.parse_args()
 if args.reset_source and not args.update:
        raise Exception("Can not reset sources without doing an update")
 
-# load config
-old_val = sys.dont_write_bytecode
-sys.dont_write_bytecode = True
-config = importlib.machinery.SourceFileLoader('config', args.config).load_module().__dict__
-sys.dont_write_bytecode = old_val
+# load config as dictionary
+config = load_module('config', args.config).__dict__
 
 # initialise variables holding the configuration
 allProjects = OrderedDict() # all projects