diff --git a/oletools/oletimes.py b/oletools/oletimes.py index 0dd5aa8..0a4a0a7 100644 --- a/oletools/oletimes.py +++ b/oletools/oletimes.py @@ -16,7 +16,7 @@ http://www.decalage.info/python/oletools #=== LICENSE ================================================================= -# oletimes is copyright (c) 2013-2016, Philippe Lagadec (http://www.decalage.info) +# oletimes is copyright (c) 2013-2017, Philippe Lagadec (http://www.decalage.info) # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -48,8 +48,9 @@ http://www.decalage.info/python/oletools # 2014-11-30 v0.03 PL: - improved output with prettytable # 2016-07-20 v0.50 SL: - added Python 3 support # 2016-09-05 PL: - added main entry point for setup.py +# 2017-05-03 v0.51 PL: - fixed absolute imports (issue #141) -__version__ = '0.50' +__version__ = '0.51dev7' #------------------------------------------------------------------------------ # TODO: @@ -60,9 +61,22 @@ __version__ = '0.50' #=== IMPORTS ================================================================= -import sys, datetime -from .thirdparty import olefile -from .thirdparty.prettytable import prettytable +import sys, os, datetime + +# 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 not _parent_dir in sys.path: + sys.path.insert(0, _parent_dir) + +from oletools.thirdparty import olefile +from oletools.thirdparty.prettytable import prettytable # === MAIN ===================================================================