Commit 7b3a713e096061d67c91f6d13d8e0a371758c09e
1 parent
6a2ddc7e
mraptor3: fixed absolute imports (issue #141)
Showing
1 changed file
with
17 additions
and
6 deletions
oletools/mraptor3.py
| ... | ... | @@ -52,8 +52,9 @@ http://www.decalage.info/python/oletools |
| 52 | 52 | # 2016-03-08 v0.04 PL: - collapse long lines before analysis |
| 53 | 53 | # 2016-07-19 v0.50 SL: - converted to Python 3 |
| 54 | 54 | # 2016-08-26 PL: - changed imports for Python 3 |
| 55 | +# 2017-04-26 v0.51 PL: - fixed absolute imports (issue #141) | |
| 55 | 56 | |
| 56 | -__version__ = '0.50py3' | |
| 57 | +__version__ = '0.51dev6' | |
| 57 | 58 | |
| 58 | 59 | #------------------------------------------------------------------------------ |
| 59 | 60 | # TODO: |
| ... | ... | @@ -61,15 +62,25 @@ __version__ = '0.50py3' |
| 61 | 62 | |
| 62 | 63 | #--- IMPORTS ------------------------------------------------------------------ |
| 63 | 64 | |
| 64 | -import sys, logging, optparse, re | |
| 65 | +import sys, os, logging, optparse, re | |
| 65 | 66 | |
| 66 | -from .thirdparty.xglob import xglob | |
| 67 | +# IMPORTANT: it should be possible to run oletools directly as scripts | |
| 68 | +# in any directory without installing them with pip or setup.py. | |
| 69 | +# In that case, relative imports are NOT usable. | |
| 70 | +# And to enable Python 2+3 compatibility, we need to use absolute imports, | |
| 71 | +# so we add the oletools parent folder to sys.path (absolute+normalized path): | |
| 72 | +_thismodule_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) | |
| 73 | +# print('_thismodule_dir = %r' % _thismodule_dir) | |
| 74 | +_parent_dir = os.path.normpath(os.path.join(_thismodule_dir, '..')) | |
| 75 | +# print('_parent_dir = %r' % _thirdparty_dir) | |
| 76 | +if not _parent_dir in sys.path: | |
| 77 | + sys.path.insert(0, _parent_dir) | |
| 67 | 78 | |
| 68 | -# import the python 3 version of tablestream: | |
| 69 | -from .thirdparty.tablestream import tablestream | |
| 79 | +from oletools.thirdparty.xglob import xglob | |
| 80 | +from oletools.thirdparty.tablestream import tablestream | |
| 70 | 81 | |
| 71 | 82 | # import the python 3 version of olevba |
| 72 | -from . import olevba3 as olevba | |
| 83 | +from oletools import olevba3 as olevba | |
| 73 | 84 | |
| 74 | 85 | # === LOGGING ================================================================= |
| 75 | 86 | ... | ... |