Commit abece8c536c25653697907f28754a39b252db730
1 parent
ab6a1e75
olemap: fixed absolute imports
Showing
1 changed file
with
27 additions
and
10 deletions
oletools/olemap.py
| @@ -13,7 +13,7 @@ http://www.decalage.info/python/oletools | @@ -13,7 +13,7 @@ http://www.decalage.info/python/oletools | ||
| 13 | 13 | ||
| 14 | #=== LICENSE ================================================================== | 14 | #=== LICENSE ================================================================== |
| 15 | 15 | ||
| 16 | -# olemap is copyright (c) 2015-2016 Philippe Lagadec (http://www.decalage.info) | 16 | +# olemap is copyright (c) 2015-2017 Philippe Lagadec (http://www.decalage.info) |
| 17 | # All rights reserved. | 17 | # All rights reserved. |
| 18 | # | 18 | # |
| 19 | # Redistribution and use in source and binary forms, with or without modification, | 19 | # Redistribution and use in source and binary forms, with or without modification, |
| @@ -43,25 +43,33 @@ http://www.decalage.info/python/oletools | @@ -43,25 +43,33 @@ http://www.decalage.info/python/oletools | ||
| 43 | # 2016-01-13 v0.02 PL: - improved display with tablestream, added colors | 43 | # 2016-01-13 v0.02 PL: - improved display with tablestream, added colors |
| 44 | # 2016-07-20 v0.50 SL: - added Python 3 support | 44 | # 2016-07-20 v0.50 SL: - added Python 3 support |
| 45 | # 2016-09-05 PL: - added main entry point for setup.py | 45 | # 2016-09-05 PL: - added main entry point for setup.py |
| 46 | +# 2017-03-20 v0.51 PL: - fixed absolute imports | ||
| 46 | 47 | ||
| 47 | -__version__ = '0.50' | 48 | +__version__ = '0.51dev3' |
| 48 | 49 | ||
| 49 | #------------------------------------------------------------------------------ | 50 | #------------------------------------------------------------------------------ |
| 50 | # TODO: | 51 | # TODO: |
| 51 | 52 | ||
| 52 | # === IMPORTS ================================================================ | 53 | # === IMPORTS ================================================================ |
| 53 | 54 | ||
| 54 | -import sys | ||
| 55 | -from .thirdparty.olefile import olefile | ||
| 56 | -from .thirdparty.tablestream import tablestream | 55 | +import sys, os |
| 57 | 56 | ||
| 57 | +# IMPORTANT: it should be possible to run oletools directly as scripts | ||
| 58 | +# in any directory without installing them with pip or setup.py. | ||
| 59 | +# In that case, relative imports are NOT usable. | ||
| 60 | +# And to enable Python 2+3 compatibility, we need to use absolute imports, | ||
| 61 | +# so we add the oletools parent folder to sys.path (absolute+normalized path): | ||
| 62 | +_thismodule_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) | ||
| 63 | +# print('_thismodule_dir = %r' % _thismodule_dir) | ||
| 64 | +_parent_dir = os.path.normpath(os.path.join(_thismodule_dir, '..')) | ||
| 65 | +# print('_parent_dir = %r' % _thirdparty_dir) | ||
| 66 | +if not _parent_dir in sys.path: | ||
| 67 | + sys.path.insert(0, _parent_dir) | ||
| 58 | 68 | ||
| 69 | +from oletools.thirdparty.olefile import olefile | ||
| 70 | +from oletools.thirdparty.tablestream import tablestream | ||
| 59 | 71 | ||
| 60 | -def sid_display(sid): | ||
| 61 | - if sid == olefile.NOSTREAM: | ||
| 62 | - return None | ||
| 63 | - else: | ||
| 64 | - return sid | 72 | +# === CONSTANTS ============================================================== |
| 65 | 73 | ||
| 66 | STORAGE_NAMES = { | 74 | STORAGE_NAMES = { |
| 67 | olefile.STGTY_EMPTY: 'Empty', | 75 | olefile.STGTY_EMPTY: 'Empty', |
| @@ -88,6 +96,15 @@ FAT_COLORS = { | @@ -88,6 +96,15 @@ FAT_COLORS = { | ||
| 88 | } | 96 | } |
| 89 | 97 | ||
| 90 | 98 | ||
| 99 | +# === FUNCTIONS ============================================================== | ||
| 100 | + | ||
| 101 | +def sid_display(sid): | ||
| 102 | + if sid == olefile.NOSTREAM: | ||
| 103 | + return None | ||
| 104 | + else: | ||
| 105 | + return sid | ||
| 106 | + | ||
| 107 | + | ||
| 91 | # === MAIN =================================================================== | 108 | # === MAIN =================================================================== |
| 92 | 109 | ||
| 93 | def main(): | 110 | def main(): |