diff --git a/pyglance/glance/config_organizer.py b/pyglance/glance/config_organizer.py index 5a3c3192480139c53953d93fbdfb97f8ea5849e6..6d135a70776d8b237a312cdbddae722e82dda075 100644 --- a/pyglance/glance/config_organizer.py +++ b/pyglance/glance/config_organizer.py @@ -10,7 +10,7 @@ Created by evas Dec 2012. Copyright (c) 2012 University of Wisconsin SSEC. All rights reserved. """ -import os, sys, imp, logging, re +import os, sys, importlib, logging, re import argparse import glance.io as io @@ -311,6 +311,17 @@ def _get_missing_values_if_needed(fileA, fileB, return missing_value_A, missing_value_B +def _import_module(full_name, full_file_path,) : + """ + load up a python module from a file on the fly, this should be used when loading configuration files for Glance + """ + + spec = importlib.util.spec_from_file_location(full_name, full_file_path,) + mod = importlib.util.module_from_spec(spec) + + spec.loader.exec_module(mod) + return mod + # TODO, right now this is the top level function that the library functions in # compare.py call def load_config_or_options(aPath, bPath, optionsSet, requestedVars = [ ]) : @@ -373,9 +384,11 @@ def load_config_or_options(aPath, bPath, optionsSet, requestedVars = [ ]) : # load the file LOG.debug ('loading config file: ' + str(requestedConfigFile)) - glanceRunConfig = imp.load_module(fileBaseName, file(requestedConfigFile, 'U'), - requestedConfigFile, ('.py' , 'U', 1)) - + glanceRunConfig = _import_module(fileBaseName, requestedConfigFile,) + #import imp + #glanceRunConfig = imp.load_module(fileBaseName, open(requestedConfigFile, 'U'), + # requestedConfigFile, ('.py' , 'U', 1)) + # this is an exception, since it is not advertised to the user we don't expect it to be in the file # (at least not at the moment, it could be added later and if they did happen to put it in the # config file, it would override this line)