(interactive=False, on_root=False, on_pyenv=False, force=False)
| 100 | |
| 101 | |
| 102 | def install(interactive=False, on_root=False, on_pyenv=False, force=False) -> bool: |
| 103 | |
| 104 | if binaryninja_installed() and not force: |
| 105 | print_error("Binary Ninja API already in the path. Use --force to overwrite.") |
| 106 | return False |
| 107 | |
| 108 | api_path = get_expected_binaryninja_installed_directory() |
| 109 | if not os.path.isdir(api_path): |
| 110 | print_error("Failed to find installed python expected at {}".format(api_path)) |
| 111 | return False |
| 112 | |
| 113 | print(f"Found install folder of {api_path}") |
| 114 | |
| 115 | while not validate_path(api_path): |
| 116 | |
| 117 | print(f"Binary Ninja not found: {api_path}") |
| 118 | |
| 119 | if not interactive: |
| 120 | print_error("silent mode selected (-s, --silent), failing.") |
| 121 | return False |
| 122 | |
| 123 | try: |
| 124 | new_path = input("Please provide the path to Binary Ninja's install directory: \n [{}] : ".format(api_path)) |
| 125 | except KeyboardInterrupt: |
| 126 | print_error("KeyboardInterrupt detected.") |
| 127 | return False |
| 128 | |
| 129 | if not new_path: |
| 130 | print("Invalid path.") |
| 131 | continue |
| 132 | |
| 133 | if not new_path.endswith("python"): |
| 134 | os.path.join(new_path, "python") |
| 135 | |
| 136 | api_path = new_path |
| 137 | |
| 138 | if on_root: |
| 139 | install_path = getsitepackage() |
| 140 | if not install_path or not os.access(install_path, os.W_OK): |
| 141 | print_error(f"Root install specified but cannot write to \"{install_path}\"") |
| 142 | return False |
| 143 | else: |
| 144 | print(f"Installing on root site: \"{install_path}\"") |
| 145 | |
| 146 | elif on_pyenv: |
| 147 | install_path = getsitepackage() |
| 148 | print(f"Installing on pyenv site: \"{install_path}") |
| 149 | |
| 150 | elif check_virtual_environment(): |
| 151 | install_path = getsitepackage() |
| 152 | print(f"Installing on virtual environment site: \"{install_path}\"") |
| 153 | |
| 154 | else: |
| 155 | if not check_enableusersite(): |
| 156 | print_error("Warning, trying to write to user site packages, but check_enableusersite fails.") |
| 157 | return False |
| 158 | else: |
| 159 | install_path = getusersitepackages() |
no test coverage detected