diff options
| author | Jordan Wiens <jordan@psifertex.com> | 2019-05-09 01:04:19 -0400 |
|---|---|---|
| committer | Jordan Wiens <jordan@psifertex.com> | 2019-05-09 01:04:19 -0400 |
| commit | 2ac718fbd3574561f245bd42e5b0ffd77380937c (patch) | |
| tree | 2e6933ee0cc1b521717034388174d490fabb48c1 /python | |
| parent | 82a6cb68019f11b9d2b317eea948fd7402126890 (diff) | |
warning for older pth files not including ui paths and install script now updates if ui is missing as well
Diffstat (limited to 'python')
| -rw-r--r-- | python/__init__.py | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/python/__init__.py b/python/__init__.py index c659aa1c..c8f42251 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -27,10 +27,15 @@ from time import gmtime # 2-3 compatibility +PY2 = sys.version_info[0] == 2 +PY3 = sys.version_info[0] == 3 +PY34 = sys.version_info[0:2] >= (3, 4) + try: import builtins # __builtins__ for python2 except ImportError: pass + def range(*args): """ A Python2 and Python3 Compatible Range Generator """ try: @@ -38,17 +43,37 @@ def range(*args): except NameError: return builtins.range(*args) +def valid_import(mod_name): + if PY2: + import imp + try: + imp.find_module(mod_name) + found = True + except ImportError: + found = False + elif PY34: + import importlib + mod_spec = importlib.util.find_spec(mod_name) + found = mod_spec is not None + elif PY3: + import importlib + mod_loader = importlib.find_loader(mod_name) + found = mod_loader is not None + else: + return False + return found + def with_metaclass(meta, *bases): - """Create a base class with a metaclass.""" - class metaclass(type): - def __new__(cls, name, this_bases, d): - return meta(name, bases, d) + """Create a base class with a metaclass.""" + class metaclass(type): + def __new__(cls, name, this_bases, d): + return meta(name, bases, d) - @classmethod - def __prepare__(cls, name, this_bases): - return meta.__prepare__(name, bases) - return type.__new__(metaclass, 'temporary_class', (), {}) + @classmethod + def __prepare__(cls, name, this_bases): + return meta.__prepare__(name, bases) + return type.__new__(metaclass, 'temporary_class', (), {}) try: @@ -315,3 +340,7 @@ def get_memory_usage_info(): result[info[i].name] = info[i].value core.BNFreeMemoryUsageInfo(info, count.value) return result + +if not valid_import("binaryninjaui") and not core_ui_enabled(): + #Use print because we're headless and log_functions won't work yet + print("BINARYNINJAUI module not available.\nPlease re-run the install_api.py python script (with the appropriate version of python you plan to use) to properly set up your Binary Ninja python paths.")
\ No newline at end of file |
