Change a bunch of stuff so Windows will work again

This commit is contained in:
Micah Lee 2021-06-16 16:55:25 -07:00
parent ebd3a841dc
commit 3105a2c229
9 changed files with 39 additions and 16 deletions

View file

@ -106,7 +106,8 @@ poetry install
After that you can launch dangerzone during development with: 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 ### If you want to build a .exe

View file

@ -1,14 +1,20 @@
import os import os
import sys import sys
# Depending on the filename, decide if we want to run: if "DANGERZONE_MODE" in os.environ:
# dangerzone, dangerzone-cli, or dangerzone-container 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 mode == "container":
if basename == "dangerzone-container" or basename == "dangerzone-container.exe":
from .container import container_main as main 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 from .cli import cli_main as main
else: else:
from .gui import gui_main as main from .gui import gui_main as main

View file

@ -22,7 +22,7 @@ def exec_container(global_common, args):
# Hack to add colors to the command executing # Hack to add colors to the command executing
if line.startswith(b"\xe2\x80\xa3 "): if line.startswith(b"\xe2\x80\xa3 "):
print( print(
Fore.WHITE + "\u2023 " + Fore.LIGHTCYAN_EX + line.decode()[2:], Fore.WHITE + "\x10 " + Fore.LIGHTCYAN_EX + line.decode()[2:],
end="", end="",
) )
else: else:

View file

@ -9,7 +9,7 @@ import shutil
if platform.system() == "Darwin": if platform.system() == "Darwin":
container_runtime = "/usr/local/bin/docker" container_runtime = "/usr/local/bin/docker"
elif platform.system() == "Windows": 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: else:
container_runtime = shutil.which("docker") container_runtime = shutil.which("docker")
@ -25,7 +25,7 @@ def exec_container(args):
args = [container_runtime] + args args = [container_runtime] + args
args_str = " ".join(pipes.quote(s) for s in args) args_str = " ".join(pipes.quote(s) for s in args)
print("\u2023 " + args_str) # ‣ print("\x10 " + args_str)
sys.stdout.flush() sys.stdout.flush()
with subprocess.Popen( with subprocess.Popen(

View file

@ -18,8 +18,13 @@ class GlobalCommon(object):
def __init__(self): def __init__(self):
# Version # Version
try:
with open(self.get_resource_path("version.txt")) as f: with open(self.get_resource_path("version.txt")) as f:
self.version = f.read().strip() 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 # Initialize terminal colors
colorama.init(autoreset=True) colorama.init(autoreset=True)
@ -409,7 +414,7 @@ class GlobalCommon(object):
def get_dangerzone_container_path(self): def get_dangerzone_container_path(self):
if getattr(sys, "dangerzone_dev", False): if getattr(sys, "dangerzone_dev", False):
# Look for resources directory relative to python file # Look for resources directory relative to python file
return os.path.join( path = os.path.join(
os.path.dirname( os.path.dirname(
os.path.dirname( os.path.dirname(
os.path.abspath(inspect.getfile(inspect.currentframe())) os.path.abspath(inspect.getfile(inspect.currentframe()))
@ -418,6 +423,9 @@ class GlobalCommon(object):
"dev_scripts", "dev_scripts",
"dangerzone-container", "dangerzone-container",
) )
if platform.system() == "Windows":
path = f"{path}.bat"
return path
else: else:
if platform.system() == "Darwin": if platform.system() == "Darwin":
return os.path.join( return os.path.join(
@ -442,7 +450,7 @@ class GlobalCommon(object):
# Execute dangerzone-container # Execute dangerzone-container
args_str = " ".join(pipes.quote(s) for s in args) 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( return subprocess.Popen(
args, args,
startupinfo=self.get_subprocess_startupinfo(), startupinfo=self.get_subprocess_startupinfo(),
@ -469,7 +477,7 @@ class GlobalCommon(object):
) as p: ) as p:
stdout_data, _ = p.communicate() stdout_data, _ = p.communicate()
lines = stdout_data.split(b"\n") 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:]) stdout_data = b"\n".join(lines[1:])
# The user canceled, or permission denied # The user canceled, or permission denied

View file

@ -34,7 +34,7 @@ def is_docker_installed():
def is_docker_ready(global_common): def is_docker_ready(global_common):
# Run `docker image ls` without an error # Run `docker image ls` without an error
with global_common.exec_dangerzone_container(["ls"]) as p: with global_common.exec_dangerzone_container(["ls"]) as p:
p.communicate() outs, errs = p.communicate()
# The user canceled, or permission denied # The user canceled, or permission denied
if p.returncode == 126 or p.returncode == 127: if p.returncode == 126 or p.returncode == 127:
@ -44,6 +44,8 @@ def is_docker_ready(global_common):
if p.returncode == 0: if p.returncode == 0:
return True return True
else: else:
print(outs.decode())
print(errs.decode())
return False return False

View file

@ -0,0 +1,2 @@
set DANGERZONE_MODE=cli
poetry run python .\dev_scripts\dangerzone %*

View file

@ -0,0 +1,2 @@
set DANGERZONE_MODE=container
poetry run python .\dev_scripts\dangerzone %*

View file

@ -0,0 +1,2 @@
set DANGERZONE_MODE=gui
poetry run python .\dev_scripts\dangerzone %*