Commit 54ca41c809ce1c36072c25fef9524b69285c61c6
1 parent
12653de9
olebrowse: fixed absolute imports (issue #141)
Showing
1 changed file
with
22 additions
and
6 deletions
oletools/olebrowse.py
| ... | ... | @@ -12,7 +12,7 @@ olebrowse project website: http://www.decalage.info/python/olebrowse |
| 12 | 12 | olebrowse is part of the python-oletools package: |
| 13 | 13 | http://www.decalage.info/python/oletools |
| 14 | 14 | |
| 15 | -olebrowse is copyright (c) 2012-2015, Philippe Lagadec (http://www.decalage.info) | |
| 15 | +olebrowse is copyright (c) 2012-2017, Philippe Lagadec (http://www.decalage.info) | |
| 16 | 16 | All rights reserved. |
| 17 | 17 | |
| 18 | 18 | Redistribution and use in source and binary forms, with or without modification, |
| ... | ... | @@ -36,12 +36,13 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 36 | 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 37 | 37 | """ |
| 38 | 38 | |
| 39 | -__version__ = '0.02' | |
| 40 | - | |
| 41 | 39 | #------------------------------------------------------------------------------ |
| 42 | 40 | # CHANGELOG: |
| 43 | 41 | # 2012-09-17 v0.01 PL: - first version |
| 44 | 42 | # 2014-11-29 v0.02 PL: - use olefile instead of OleFileIO_PL |
| 43 | +# 2017-04-26 v0.51 PL: - fixed absolute imports (issue #141) | |
| 44 | + | |
| 45 | +__version__ = '0.51' | |
| 45 | 46 | |
| 46 | 47 | #------------------------------------------------------------------------------ |
| 47 | 48 | # TODO: |
| ... | ... | @@ -51,10 +52,25 @@ __version__ = '0.02' |
| 51 | 52 | # - for a stream, display info: size, path, etc |
| 52 | 53 | # - stream info: magic, entropy, ... ? |
| 53 | 54 | |
| 55 | +# === IMPORTS ================================================================ | |
| 56 | + | |
| 54 | 57 | import optparse, sys, os |
| 55 | -from .thirdparty.easygui import easygui | |
| 56 | -from .thirdparty import olefile | |
| 57 | -from . import ezhexviewer | |
| 58 | + | |
| 59 | +# IMPORTANT: it should be possible to run oletools directly as scripts | |
| 60 | +# in any directory without installing them with pip or setup.py. | |
| 61 | +# In that case, relative imports are NOT usable. | |
| 62 | +# And to enable Python 2+3 compatibility, we need to use absolute imports, | |
| 63 | +# so we add the oletools parent folder to sys.path (absolute+normalized path): | |
| 64 | +_thismodule_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) | |
| 65 | +# print('_thismodule_dir = %r' % _thismodule_dir) | |
| 66 | +_parent_dir = os.path.normpath(os.path.join(_thismodule_dir, '..')) | |
| 67 | +# print('_parent_dir = %r' % _thirdparty_dir) | |
| 68 | +if not _parent_dir in sys.path: | |
| 69 | + sys.path.insert(0, _parent_dir) | |
| 70 | + | |
| 71 | +from oletools.thirdparty.easygui import easygui | |
| 72 | +from oletools.thirdparty import olefile | |
| 73 | +from oletools import ezhexviewer | |
| 58 | 74 | |
| 59 | 75 | ABOUT = '~ About olebrowse' |
| 60 | 76 | QUIT = '~ Quit' | ... | ... |