Commit 7f492486a99c5bb74b779f3bf1d13fdcf26984be
1 parent
f55f8966
msodde: slight fix to use the current dir to import oletools in case it's not th…
…e version installed by pip
Showing
1 changed file
with
12 additions
and
0 deletions
oletools/msodde.py
| ... | ... | @@ -57,6 +57,18 @@ import csv |
| 57 | 57 | |
| 58 | 58 | import olefile |
| 59 | 59 | |
| 60 | +# IMPORTANT: it should be possible to run oletools directly as scripts | |
| 61 | +# in any directory without installing them with pip or setup.py. | |
| 62 | +# In that case, relative imports are NOT usable. | |
| 63 | +# And to enable Python 2+3 compatibility, we need to use absolute imports, | |
| 64 | +# so we add the oletools parent folder to sys.path (absolute+normalized path): | |
| 65 | +_thismodule_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) | |
| 66 | +# print('_thismodule_dir = %r' % _thismodule_dir) | |
| 67 | +_parent_dir = os.path.normpath(os.path.join(_thismodule_dir, '..')) | |
| 68 | +# print('_parent_dir = %r' % _thirdparty_dir) | |
| 69 | +if _parent_dir not in sys.path: | |
| 70 | + sys.path.insert(0, _parent_dir) | |
| 71 | + | |
| 60 | 72 | from oletools import ooxml |
| 61 | 73 | from oletools import xls_parser |
| 62 | 74 | from oletools import rtfobj | ... | ... |