Skip to content
Snippets Groups Projects
Commit 91e1289b authored by Eva Schiffer's avatar Eva Schiffer
Browse files

moving from imp to importlib for loading our configuration files

parent 80dbb92e
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment