diff options
author | Frederic Lepied <flepied@mandriva.com> | 2002-04-19 18:17:02 +0000 |
---|---|---|
committer | Frederic Lepied <flepied@mandriva.com> | 2002-04-19 18:17:02 +0000 |
commit | 3a7ba7237314e183cbece1e39cf0762bf9e53fa8 (patch) | |
tree | 0b0a35cdfdf2fa9705a15fa3c0ee4926fd63b785 /share/msec.py | |
parent | 140c54cfbae78a2a8100b816000facc9965b4664 (diff) | |
download | msec-3a7ba7237314e183cbece1e39cf0762bf9e53fa8.tar msec-3a7ba7237314e183cbece1e39cf0762bf9e53fa8.tar.gz msec-3a7ba7237314e183cbece1e39cf0762bf9e53fa8.tar.bz2 msec-3a7ba7237314e183cbece1e39cf0762bf9e53fa8.tar.xz msec-3a7ba7237314e183cbece1e39cf0762bf9e53fa8.zip |
load the config file using the context of mseclib.
Diffstat (limited to 'share/msec.py')
-rwxr-xr-x | share/msec.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/share/msec.py b/share/msec.py index ed8ea0c..f281bae 100755 --- a/share/msec.py +++ b/share/msec.py @@ -28,10 +28,37 @@ except IOError: _ = str # Eval a file +import mseclib +def import_only_mseclib(name, globals = None, locals = None, fromlist = None): + """ Import hook to allow only the mseclib module to be imported. """ + + if name == 'mseclib': + return mseclib + else: + raise ImportError, '%s cannot be imported' % name + def eval_file(name): - file = os.fdopen(os.open(os.path.expanduser(name), os.O_RDONLY)) - imp.load_source('', name, file) - file.close() + """ Eval level.local file. Only allow mseclib to be imported for + backward compatibility. """ + + globals = {} + locals = {} + builtins = {} + + # Insert symbols from mseclib into globals + non_exported_names = ['FAKE', 'indirect', 'commit_changes'] + for attrib_name in dir(mseclib): + if attrib_name[0] != '_' and attrib_name not in non_exported_names: + globals[attrib_name] = getattr(mseclib, attrib_name) + + # Set import hook -- it needs to be in globals['__builtins'] so we make + # a copy of builtins to put there + builtins.update(__builtins__.__dict__) + builtins['__import__'] = import_only_mseclib + globals['__builtins__'] = builtins + + # Exec file + execfile(os.path.expanduser(name), globals, locals) # program _name = 'msec' @@ -217,7 +244,7 @@ if os.path.exists(CONFIG): try: eval_file(CONFIG) except: - log(_('Error loading %s: %s') % (CONFIG, sys.exc_value[0])) + log(_('Error loading %s: %s') % (CONFIG, str(sys.exc_value))) commit_changes() |