mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 09:52:37 +02:00
Change a bunch of stuff so Windows will work again
This commit is contained in:
parent
ebd3a841dc
commit
3105a2c229
9 changed files with 39 additions and 16 deletions
3
BUILD.md
3
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
|
||||
|
|
|
@ -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":
|
||||
from .container import container_main as main
|
||||
mode = "container"
|
||||
elif basename == "dangerzone-cli" or basename == "dangerzone-cli.exe":
|
||||
mode = "cli"
|
||||
else:
|
||||
mode = "gui"
|
||||
|
||||
if mode == "container":
|
||||
from .container import container_main as main
|
||||
elif mode == "cli":
|
||||
from .cli import cli_main as main
|
||||
else:
|
||||
from .gui import gui_main as main
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -18,8 +18,13 @@ class GlobalCommon(object):
|
|||
|
||||
def __init__(self):
|
||||
# Version
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
2
dev_scripts/dangerzone-cli.bat
Normal file
2
dev_scripts/dangerzone-cli.bat
Normal file
|
@ -0,0 +1,2 @@
|
|||
set DANGERZONE_MODE=cli
|
||||
poetry run python .\dev_scripts\dangerzone %*
|
2
dev_scripts/dangerzone-container.bat
Normal file
2
dev_scripts/dangerzone-container.bat
Normal file
|
@ -0,0 +1,2 @@
|
|||
set DANGERZONE_MODE=container
|
||||
poetry run python .\dev_scripts\dangerzone %*
|
2
dev_scripts/dangerzone.bat
Normal file
2
dev_scripts/dangerzone.bat
Normal file
|
@ -0,0 +1,2 @@
|
|||
set DANGERZONE_MODE=gui
|
||||
poetry run python .\dev_scripts\dangerzone %*
|
Loading…
Reference in a new issue