From 7f492486a99c5bb74b779f3bf1d13fdcf26984be Mon Sep 17 00:00:00 2001 From: decalage2 Date: Wed, 27 Mar 2019 18:35:19 +0100 Subject: [PATCH] msodde: slight fix to use the current dir to import oletools in case it's not the version installed by pip --- oletools/msodde.py | 12 ++++++++++++ 1 file changed, 12 insertions(+), 0 deletions(-) diff --git a/oletools/msodde.py b/oletools/msodde.py index a09f7ab..34a26db 100644 --- a/oletools/msodde.py +++ b/oletools/msodde.py @@ -57,6 +57,18 @@ import csv import olefile +# IMPORTANT: it should be possible to run oletools directly as scripts +# in any directory without installing them with pip or setup.py. +# In that case, relative imports are NOT usable. +# And to enable Python 2+3 compatibility, we need to use absolute imports, +# so we add the oletools parent folder to sys.path (absolute+normalized path): +_thismodule_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) +# print('_thismodule_dir = %r' % _thismodule_dir) +_parent_dir = os.path.normpath(os.path.join(_thismodule_dir, '..')) +# print('_parent_dir = %r' % _thirdparty_dir) +if _parent_dir not in sys.path: + sys.path.insert(0, _parent_dir) + from oletools import ooxml from oletools import xls_parser from oletools import rtfobj -- libgit2 0.21.4