diff --git a/BUILD.md b/BUILD.md index 813cceb..09d4060 100644 --- a/BUILD.md +++ b/BUILD.md @@ -106,7 +106,8 @@ poetry install After that you can launch dangerzone during development with: ``` -poetry run dangerzone +.\dev_scripts\dangerzone.bat +.\dev_scripts\dangerzone-cli.bat --help ``` ### If you want to build a .exe diff --git a/dangerzone/__init__.py b/dangerzone/__init__.py index d89750d..baf50a8 100644 --- a/dangerzone/__init__.py +++ b/dangerzone/__init__.py @@ -1,14 +1,20 @@ import os import sys -# Depending on the filename, decide if we want to run: -# dangerzone, dangerzone-cli, or dangerzone-container +if "DANGERZONE_MODE" in os.environ: + mode = os.environ["DANGERZONE_MODE"] +else: + basename = os.path.basename(sys.argv[0]) + if basename == "dangerzone-container" or basename == "dangerzone-container.exe": + mode = "container" + elif basename == "dangerzone-cli" or basename == "dangerzone-cli.exe": + mode = "cli" + else: + mode = "gui" -basename = os.path.basename(sys.argv[0]) - -if basename == "dangerzone-container" or basename == "dangerzone-container.exe": +if mode == "container": from .container import container_main as main -elif basename == "dangerzone-cli" or basename == "dangerzone-cli.exe": +elif mode == "cli": from .cli import cli_main as main else: from .gui import gui_main as main diff --git a/dangerzone/cli.py b/dangerzone/cli.py index f94ef14..0a0b6b5 100644 --- a/dangerzone/cli.py +++ b/dangerzone/cli.py @@ -22,7 +22,7 @@ def exec_container(global_common, args): # Hack to add colors to the command executing if line.startswith(b"\xe2\x80\xa3 "): print( - Fore.WHITE + "\u2023 " + Fore.LIGHTCYAN_EX + line.decode()[2:], + Fore.WHITE + "\x10 " + Fore.LIGHTCYAN_EX + line.decode()[2:], end="", ) else: diff --git a/dangerzone/container.py b/dangerzone/container.py index c003b2b..c3d00d7 100644 --- a/dangerzone/container.py +++ b/dangerzone/container.py @@ -9,7 +9,7 @@ import shutil if platform.system() == "Darwin": container_runtime = "/usr/local/bin/docker" elif platform.system() == "Windows": - container_runtime = "C:\\Program Files\\Docker\\Docker\\resources\\docker.exe" + container_runtime = "C:\\Program Files\\Docker\\Docker\\resources\\bin\\docker.exe" else: container_runtime = shutil.which("docker") @@ -25,7 +25,7 @@ def exec_container(args): args = [container_runtime] + args args_str = " ".join(pipes.quote(s) for s in args) - print("\u2023 " + args_str) # ‣ + print("\x10 " + args_str) sys.stdout.flush() with subprocess.Popen( diff --git a/dangerzone/global_common.py b/dangerzone/global_common.py index e19680d..60ac783 100644 --- a/dangerzone/global_common.py +++ b/dangerzone/global_common.py @@ -18,8 +18,13 @@ class GlobalCommon(object): def __init__(self): # Version - with open(self.get_resource_path("version.txt")) as f: - self.version = f.read().strip() + try: + with open(self.get_resource_path("version.txt")) as f: + self.version = f.read().strip() + except FileNotFoundError: + # In dev mode, in Windows, get_resource_path doesn't work properly for dangerzone-container, but luckily + # it doesn't need to know the version + self.version = "unknown" # Initialize terminal colors colorama.init(autoreset=True) @@ -409,7 +414,7 @@ class GlobalCommon(object): def get_dangerzone_container_path(self): if getattr(sys, "dangerzone_dev", False): # Look for resources directory relative to python file - return os.path.join( + path = os.path.join( os.path.dirname( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe())) @@ -418,6 +423,9 @@ class GlobalCommon(object): "dev_scripts", "dangerzone-container", ) + if platform.system() == "Windows": + path = f"{path}.bat" + return path else: if platform.system() == "Darwin": return os.path.join( @@ -442,7 +450,7 @@ class GlobalCommon(object): # Execute dangerzone-container args_str = " ".join(pipes.quote(s) for s in args) - print(Fore.YELLOW + "\u2023 " + Fore.CYAN + args_str) # ‣ + print(Fore.YELLOW + "\x10 " + Fore.CYAN + args_str) return subprocess.Popen( args, startupinfo=self.get_subprocess_startupinfo(), @@ -469,7 +477,7 @@ class GlobalCommon(object): ) as p: stdout_data, _ = p.communicate() lines = stdout_data.split(b"\n") - if b"\u2023 " in lines[0]: # ‣ + if b"\x10 " in lines[0]: stdout_data = b"\n".join(lines[1:]) # The user canceled, or permission denied diff --git a/dangerzone/gui/docker_installer.py b/dangerzone/gui/docker_installer.py index 150b2f2..b8a59ee 100644 --- a/dangerzone/gui/docker_installer.py +++ b/dangerzone/gui/docker_installer.py @@ -34,7 +34,7 @@ def is_docker_installed(): def is_docker_ready(global_common): # Run `docker image ls` without an error with global_common.exec_dangerzone_container(["ls"]) as p: - p.communicate() + outs, errs = p.communicate() # The user canceled, or permission denied if p.returncode == 126 or p.returncode == 127: @@ -44,6 +44,8 @@ def is_docker_ready(global_common): if p.returncode == 0: return True else: + print(outs.decode()) + print(errs.decode()) return False diff --git a/dev_scripts/dangerzone-cli.bat b/dev_scripts/dangerzone-cli.bat new file mode 100644 index 0000000..21d9afe --- /dev/null +++ b/dev_scripts/dangerzone-cli.bat @@ -0,0 +1,2 @@ +set DANGERZONE_MODE=cli +poetry run python .\dev_scripts\dangerzone %* \ No newline at end of file diff --git a/dev_scripts/dangerzone-container.bat b/dev_scripts/dangerzone-container.bat new file mode 100644 index 0000000..07b3fc3 --- /dev/null +++ b/dev_scripts/dangerzone-container.bat @@ -0,0 +1,2 @@ +set DANGERZONE_MODE=container +poetry run python .\dev_scripts\dangerzone %* \ No newline at end of file diff --git a/dev_scripts/dangerzone.bat b/dev_scripts/dangerzone.bat new file mode 100644 index 0000000..1caaaa6 --- /dev/null +++ b/dev_scripts/dangerzone.bat @@ -0,0 +1,2 @@ +set DANGERZONE_MODE=gui +poetry run python .\dev_scripts\dangerzone %* \ No newline at end of file