Skip to content

Commit

Permalink
scripts: Add a check that scripts are run from an installation direct…
Browse files Browse the repository at this point in the history
…ory.

This helps to assist our users when they try to run the scripts from the
'retdec/scripts' directory instead of from an installed RetDec (#418).
  • Loading branch information
s3rvac committed Oct 19, 2018
1 parent 1f76c5d commit c9673db
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/retdec-decompiler.py
Expand Up @@ -17,6 +17,7 @@
retdec_unpacker = importlib.import_module('retdec-unpacker')
utils = importlib.import_module('retdec-utils')
utils.check_python_version()
utils.ensure_script_is_being_run_from_installed_retdec()

SigFromLib = retdec_signature_from_library_creator.SigFromLib
Unpacker = retdec_unpacker.Unpacker
Expand Down
1 change: 1 addition & 0 deletions scripts/retdec-fileinfo.py
Expand Up @@ -15,6 +15,7 @@
config = importlib.import_module('retdec-config')
utils = importlib.import_module('retdec-utils')
utils.check_python_version()
utils.ensure_script_is_being_run_from_installed_retdec()
retdec_archive_decompiler = importlib.import_module('retdec-archive-decompiler')

ArchiveDecompiler = retdec_archive_decompiler.ArchiveDecompiler
Expand Down
1 change: 1 addition & 0 deletions scripts/retdec-signature-from-library-creator.py
Expand Up @@ -15,6 +15,7 @@
config = importlib.import_module('retdec-config')
utils = importlib.import_module('retdec-utils')
utils.check_python_version()
utils.ensure_script_is_being_run_from_installed_retdec()

CmdRunner = utils.CmdRunner
sys.stdout = utils.Unbuffered(sys.stdout)
Expand Down
1 change: 1 addition & 0 deletions scripts/retdec-tests-runner.py
Expand Up @@ -11,6 +11,7 @@
import importlib
utils = importlib.import_module('retdec-utils')
utils.check_python_version()
utils.ensure_script_is_being_run_from_installed_retdec()

try:
import colorama
Expand Down
1 change: 1 addition & 0 deletions scripts/retdec-unpacker.py
Expand Up @@ -28,6 +28,7 @@
config = importlib.import_module('retdec-config')
utils = importlib.import_module('retdec-utils')
utils.check_python_version()
utils.ensure_script_is_being_run_from_installed_retdec()

CmdRunner = utils.CmdRunner
sys.stdout = utils.Unbuffered(sys.stdout)
Expand Down
11 changes: 11 additions & 0 deletions scripts/retdec-utils.py
Expand Up @@ -282,6 +282,17 @@ def check_python_version():
if sys.version_info < (3,4):
print_error_and_die('Cannot use Python version {} ({}). Use at least Python 3.4.'.format(platform.python_version(), sys.executable))

def ensure_script_is_being_run_from_installed_retdec():
# Use this function to assist our users when they try to run the scripts
# from the 'retdec/scripts' directory instead of from an installed RetDec.
# See https://github.com/avast-tl/retdec/issues/418
if not os.path.dirname(__file__).endswith('bin'):
print_error_and_die(
'You need to build and install RetDec first and then run the installed script via '
'`python $RETDEC_INSTALL_DIR/bin/retdec-decompiler.py`.\n'
'For more details, see https://github.com/avast-tl/retdec#installation-and-use'
)

def tool_exists(tool_name):
return shutil.which(tool_name) is not None

Expand Down

0 comments on commit c9673db

Please sign in to comment.