Skip to content

Commit fb2d11f

Browse files
committed
feat: add BSD support
1 parent 7bb2498 commit fb2d11f

File tree

2 files changed

+67
-28
lines changed

2 files changed

+67
-28
lines changed

ou_dedetai/system.py

+12
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,18 @@ def get_package_manager() -> PackageManager | None:
520520
)
521521
logos_9_packages = ""
522522
incompatible_packages = "" # appimagelauncher handled separately
523+
elif shutil.which('pkg') is not None: # freebsd ghostbsd
524+
install_command = ["pkg", "-y", "install"] # noqa: E501
525+
download_command = ["pkg", "fetch", "-d"] # noqa: E501
526+
remove_command = ["pkg", "-y", "delete"] # noqa: E501
527+
query_command = ["pkg", "info"]
528+
query_prefix = ''
529+
packages = (
530+
"cabextract 7-zip samba416 " # wine
531+
"wget gsed gnugrep gawk curl " # other
532+
) # noqa: E501
533+
logos_9_packages = "" # FIXME: Missing Logos 9 Packages
534+
incompatible_packages = "" # appimagelauncher handled separately
523535
elif os_name == "org.freedesktop.platform":
524536
# Flatpak
525537
# Dependencies are managed by the flatpak

ou_dedetai/utils.py

+55-28
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import os
88
import queue
99
import sqlite3
10-
import inotify.adapters # type: ignore
1110
import psutil
1211
import re
1312
import shutil
@@ -17,6 +16,7 @@
1716
import sys
1817
import tarfile
1918
import time
19+
import threading
2020
from ou_dedetai.app import App
2121
from packaging.version import Version
2222
from pathlib import Path
@@ -27,6 +27,10 @@
2727
from . import system
2828
from . import wine
2929

30+
if sys.platform.startswith("linux"):
31+
import inotify.adapters # type: ignore
32+
elif sys.platform.startswith(("darwin", "freebsd", "dragonfly", "netbsd", "openbsd")):
33+
import select
3034

3135
def get_calling_function_name():
3236
if 'inspect' in sys.modules:
@@ -659,10 +663,6 @@ def watch_db(path: str, sql_statements: list[str]):
659663
660664
This function may run infinitely, spawn it on it's own thread
661665
"""
662-
# Silence inotify logs
663-
logging.getLogger('inotify').setLevel(logging.CRITICAL)
664-
i = inotify.adapters.Inotify()
665-
i.add_watch(path)
666666

667667
def execute_sql(cur):
668668
# logging.debug(f"Executing SQL against {path}: {sql_statements}")
@@ -679,30 +679,57 @@ def execute_sql(cur):
679679

680680
# Execute once before we start the loop
681681
execute_sql(cur)
682-
swallow_one = True
683-
684-
# Keep track of if we've added -wal and -shm are added yet
685-
# They may not exist when we start
686-
watching_wal_and_shm = False
687-
for event in i.event_gen(yield_nones=False):
688-
(_, type_names, _, _) = event
689-
# These files may not exist when it's executes for the first time
690-
if (
691-
not watching_wal_and_shm
692-
and Path(path + "-wal").exists()
693-
and Path(path + "-shm").exists()
694-
):
695-
i.add_watch(path + "-wal")
696-
i.add_watch(path + "-shm")
697-
watching_wal_and_shm = True
698-
699-
if 'IN_MODIFY' in type_names or 'IN_CLOSE_WRITE' in type_names:
700-
# Check to make sure that we aren't responding to our own write
701-
if swallow_one:
702-
swallow_one = False
703-
continue
704-
execute_sql(cur)
682+
if sys.platform.startswith("linux"):
683+
def monitor_inotify():
684+
"""Monitor file changes using inotify."""
685+
logging.getLogger('inotify').setLevel(logging.CRITICAL)
686+
i = inotify.adapters.Inotify()
687+
i.add_watch(path)
688+
705689
swallow_one = True
690+
691+
# Keep track of if we've added -wal and -shm are added yet
692+
# They may not exist when we start
693+
watching_wal_and_shm = False
694+
for event in i.event_gen(yield_nones=False):
695+
(_, type_names, _, _) = event
696+
# These files may not exist when it's executes for the first time
697+
if (
698+
not watching_wal_and_shm
699+
and Path(path + "-wal").exists()
700+
and Path(path + "-shm").exists()
701+
):
702+
i.add_watch(path + "-wal")
703+
i.add_watch(path + "-shm")
704+
watching_wal_and_shm = True
705+
706+
if 'IN_MODIFY' in type_names or 'IN_CLOSE_WRITE' in type_names:
707+
# Check to make sure that we aren't responding to our own write
708+
if swallow_one:
709+
swallow_one = False
710+
continue
711+
execute_sql(cur)
712+
swallow_one = True
713+
714+
monitor_inotify()
715+
716+
elif sys.platform.startswith(("darwin", "freebsd", "dragonfly", "netbsd", "openbsd")):
717+
def monitor_kqueue():
718+
"""Monitor file changes using kqueue."""
719+
kq = select.kqueue()
720+
fd = open(path, "rb") # Open file to track
721+
kevent = select.kevent(fd.fileno(), filter=select.KQ_FILTER_VNODE,
722+
flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE,
723+
fflags=select.KQ_NOTE_WRITE | select.KQ_NOTE_EXTEND)
724+
kq.control([kevent], 0, 0)
725+
726+
while True:
727+
events = kq.control(None, 1) # Block until event occurs
728+
if events:
729+
execute_sql()
730+
731+
monitor_kqueue()
732+
706733
# Shouldn't be possible to get here, but on the off-chance it happens,
707734
# we'd like to know and cleanup
708735
logging.debug(f"Stopped watching {path}")

0 commit comments

Comments
 (0)