Files
deskflow/scripts/install_deps.py
Nick Bolton 7984535d38 Refactored core process management and IPC client (#7425)
* Also ignore `command_pre` for Fedora itself

* Improve warning message

* Fixed layout issues on main window

* Restore fusion theme for Windows dark mode

* Further correct main window layout

* Set CWD for launch on Windows to same dir as .env

* Use signals for tray icon instead of callback

* Reduce complexity for setting tray icon

* Further reduce tray icon complexity

* Reduce tray retry time

* Fixed tray not showing on macOS

* Refactor function names

* Move tray icon to lib

* Decouple server connection class

* Move server connection to lib

* Move client config to lib

* Remove redundant forward declarations

* Fixed some namespaces in the new lib

* Move core process code to new class

* Improve member names on new process class

* Remove copy/pasta code

* Move OSX helpers to lib

* Add .mm to lib config

* Fixed copyright

* Improve reliability of log line handling

* Fixed TLS certificate generate bugs

* Remove client list

* Refactor core process handling to fix various problems

* Fixed process/connection status bugs

* Fixed function signature issue on macOS

* Fixed override warnings

* Fixed string format warning

* Save `wasStarted` state and use that instead

* Use only filename in dialog

* Use lambda for simple slot

* Scroll to bottom if at bottome

* Set value based on position before text added and set horizontal scroll too

* Add 1px tollerance for Linux

* Simplify start/stop mutex

* Always stop service on restart

* Increase scroll bottom threshold to 2

* Log warning instead of critical

* Fixed long-standing dir CD-up hack

* Remove include

* Remove include

* Fixed rogue dumbisense includes

* Account for optional distro_like

* Add QAction include to solve incomplete type

* Remove rogue #pragma

* Static cast log value

* Solve event queue delete warning

* Fixed integ test on Windows 10

* Reduce enum verbosity

* Use static instance instead of global

* Make function const

* Use unique_ptr instead of new and delete, and made some functions const

* Fixed smart pointer use

* Fixed variable shadowing

* Fixed wrong use of using

* Fixed missing namespace using

* Simplify TLS error handling

* Improve UX around certificate errors and success

* Decouple app config from core process through interface

* First iteration of core process test

* Mark dtor as override

* Rename attach launch entry

* Add TODO

* Create proxy for process

* Move IPC client to deps

* Fixed warnings

* Reorganize new GUI lib dir structure

* Update includes to reflect new paths

* Reorg GUI tests

* Abstract IPC client

* Refactor about screen

* Fixed .ui warnings

* Remove redundant include

* Fixed typo

* Fixed typos and add spelling

* Fixed misleading function name

* Improve comment

* Improve code coverage for core process

* Remove noisy log line

* Make global const

* Use default dtor

* Use vector instead of new

* Make ctor explicit

* Make ctor explicit (2)

* Use enum class

* Fixed bad enum

* Stub out core tool

* Stub out dir operation

* Extract byte functions

* Add missing return path

* Simplify byte/int functions

* Fix truncation

* Use ctor member assignment

* Fixed segfault in process proxy

* Fixed print warning

* Make function const

* Cleanup header

* Fixed missing name

* Update ChangeLog

* Make more functions const
2024-08-07 15:05:18 +01:00

153 lines
4.3 KiB
Python
Executable File

#!/usr/bin/env python3
import os, sys, argparse, traceback
import lib.env as env
import lib.cmd_utils as cmd_utils
import lib.qt_utils as qt_utils
import lib.github as github
path_env_var = "PATH"
cmake_prefix_env_var = "CMAKE_PREFIX_PATH"
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--pause-on-exit", action="store_true", help="Useful on Windows"
)
parser.add_argument(
"--only-python",
action="store_true",
help="Only install Python dependencies",
)
parser.add_argument(
"--ci-env",
action="store_true",
help="Set if running in CI environment",
)
args = parser.parse_args()
env.ensure_dependencies()
env.ensure_in_venv(__file__, auto_create=True)
env.install_requirements()
error = False
if not args.only_python:
try:
deps = Dependencies(args.ci_env)
deps.install()
except Exception:
traceback.print_exc()
error = True
if args.pause_on_exit:
input("Press enter to continue...")
if error:
sys.exit(1)
class Dependencies:
def __init__(self, ci_env):
from lib.config import Config
self.config = Config()
self.ci_env = ci_env
if self.ci_env:
print("CI environment detected")
def install(self):
"""Installs dependencies for the current platform."""
if env.is_windows():
self.windows()
elif env.is_mac():
self.mac()
elif env.is_linux():
self.linux()
else:
raise RuntimeError(f"Unsupported platform: {os}")
def windows(self):
"""Installs dependencies on Windows."""
import lib.windows as windows
if not windows.is_admin():
windows.relaunch_as_admin(__file__)
sys.exit()
qt = qt_utils.WindowsQt(*self.config.get_qt_config())
qt.install()
if self.ci_env:
github.set_env_var(cmake_prefix_env_var, qt.get_install_dir())
else:
windows.set_env_var(cmake_prefix_env_var, qt.get_install_dir())
choco = windows.WindowsChoco()
if self.ci_env:
choco.config_ci_cache()
edit_config, skip_packages = self.config.get_windows_ci_config()
choco.remove_from_config(edit_config, skip_packages)
command = self.config.get_os_deps_command()
choco.install(command, self.ci_env)
def mac(self):
"""Installs dependencies on macOS."""
import lib.mac as mac
qt = qt_utils.MacQt(*self.config.get_qt_config())
qt.install()
qt_dir = qt.get_install_dir()
qt_bin_dir = os.path.join(qt_dir, "bin")
env_vars_set = 0
if self.ci_env:
github.set_env_var(cmake_prefix_env_var, qt_dir)
github.add_to_path(qt_bin_dir)
else:
env_vars_set += mac.set_env_var(cmake_prefix_env_var, qt_dir)
env_vars_set += mac.set_env_var(path_env_var, qt_bin_dir)
command = self.config.get_os_deps_command()
cmd_utils.run(command, shell=True, print_cmd=True)
if env_vars_set:
print(f"To load env vars, run: source {mac.shell_rc}")
def linux(self):
"""Installs dependencies on Linux."""
import lib.linux as linux
distro, distro_like, _distro_version = env.get_linux_distro()
if not distro:
raise RuntimeError("Unable to detect Linux distro")
command_pre = self.config.get_os_deps_command_pre(
linux_distro=distro, required=False
)
if command_pre:
print("Running dependencies prerequisites command")
check = True
if distro == "fedora" or (distro_like and "fedora" in distro_like):
print(
"Fedora-like detected, "
"ignoring return code on dependencies prerequisites command"
)
# On Fedora-like, dnf update returns code 100 when updates are available.
check = False
linux.run_command(command_pre, check)
command = self.config.get_os_deps_command(linux_distro=distro)
print("Running dependencies command")
linux.run_command(command, check=True)
if __name__ == "__main__":
main()