Skip to content

Commit

Permalink
Show logs in config UI. Adjust how we kick off execution
Browse files Browse the repository at this point in the history
  • Loading branch information
kubilus1 committed Sep 23, 2023
1 parent 5690d7f commit e3f0b9e
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 178 deletions.
255 changes: 148 additions & 107 deletions autoortho/autoortho.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,62 +148,131 @@ def diagnose(CFG):
log.warning("Please review logs and setup.")
log.warning("***************")
log.warning("***************")
return False
else:
log.info(" Diagnostics done. All checks passed")
return True
log.info("------------------------------------\n\n")

def run(root, mountpoint, threading=True):
global RUNNING

if threading:
log.info("Running in multi-threaded mode.")
nothreads = False
else:
log.info("Running in single-threaded mode.")
nothreads = True

root = os.path.expanduser(root)

try:
if platform.system() == 'Windows':
systemtype, libpath = winsetup.find_win_libs()
with setupmount(mountpoint, systemtype) as mount:
log.info(f"AutoOrtho: root: {root} mountpoint: {mount}")
import autoortho_fuse
from refuse import high
high._libfuse = ctypes.CDLL(libpath)
autoortho_fuse.run(
autoortho_fuse.AutoOrtho(root),
mount,
nothreads
)
else:
with setupmount(mountpoint, "Linux-FUSE") as mount:
log.info("Running in FUSE mode.")
log.info(f"AutoOrtho: root: {root} mountpoint: {mount}")
import autoortho_fuse
autoortho_fuse.run(
autoortho_fuse.AutoOrtho(root),
mount,
nothreads

class AOMount:
mounts_running = False

def __init__(self, cfg):
self.cfg = cfg
self.mount_threads = []

def mount_sceneries(self, blocking=True):
self.mounts_running = True
for scenery in self.cfg.scenery_mounts:
t = threading.Thread(
target=self.domount,
daemon=False,
args=(
scenery.get('root'),
scenery.get('mount'),
self.cfg.fuse.threading
)
)
t.start()
self.mount_threads.append(t)

if not blocking:
log.info("Running mounts in non-blocking mode.")
time.sleep(1)
diagnose(self.cfg)
return

except Exception as err:
log.error(f"Exception detected when running FUSE mount: {err}. Exiting...")
RUNNING = False
time.sleep(5)
try:
def handle_sigterm(sig, frame):
raise(SystemExit)

signal.signal(signal.SIGTERM, handle_sigterm)

time.sleep(1)
# Check things out
diagnose(self.cfg)

while self.mounts_running:
time.sleep(1)

except (KeyboardInterrupt, SystemExit) as err:
self.running = False
log.info(f"Exiting due to {err}")
finally:
log.info("Shutting down ...")
self.unmount_sceneries()

def unmount(mountpoint):
mounted = True
while mounted:
print(f"Shutting down {mountpoint}")
print("Send poison pill ...")
mounted = os.path.isfile(os.path.join(
mountpoint,
".poison"
))
time.sleep(0.5)

def unmount_sceneries(self):
log.info("Unmounting ...")
self.mounts_running = False
for scenery in self.cfg.scenery_mounts:
self.unmount(scenery.get('mount'))

log.info("Wait on threads...")
for t in self.mount_threads:
t.join(5)
log.info(f"Thread {t.ident} exited.")
log.info("Unmount complete")


def domount(self, root, mountpoint, threading=True):

if threading:
log.info("Running in multi-threaded mode.")
nothreads = False
else:
log.info("Running in single-threaded mode.")
nothreads = True

root = os.path.expanduser(root)

try:
if platform.system() == 'Windows':
systemtype, libpath = winsetup.find_win_libs()
with setupmount(mountpoint, systemtype) as mount:
log.info(f"AutoOrtho: root: {root} mountpoint: {mount}")
import autoortho_fuse
from refuse import high
high._libfuse = ctypes.CDLL(libpath)
autoortho_fuse.run(
autoortho_fuse.AutoOrtho(root),
mount,
nothreads
)
else:
with setupmount(mountpoint, "Linux-FUSE") as mount:
log.info("Running in FUSE mode.")
log.info(f"AutoOrtho: root: {root} mountpoint: {mount}")
import autoortho_fuse
autoortho_fuse.run(
autoortho_fuse.AutoOrtho(root),
mount,
nothreads
)

except Exception as err:
log.error(f"Exception detected when running FUSE mount: {err}. Exiting...")
time.sleep(5)

def unmount(self, mountpoint):
mounted = True
while mounted:
print(f"Shutting down {mountpoint}")
print("Send poison pill ...")
mounted = os.path.isfile(os.path.join(
mountpoint,
".poison"
))
time.sleep(0.5)


class AOMountUI(config_ui.ConfigUI, AOMount):
def __init__(self, *args, **kwargs):
self.mount_threads = []
super().__init__(*args, **kwargs)


def main():
Expand Down Expand Up @@ -240,84 +309,56 @@ def main():
args = parser.parse_args()

CFG = aoconfig.CFG
cfgui = config_ui.ConfigUI(CFG)
if (not CFG.ready) or args.configure or (CFG.general.showconfig and not args.headless):
cfgui.setup(headless = args.headless)

if not args.root or not args.mountpoint:
cfgui.verify()
if args.configure or (CFG.general.showconfig and not args.headless):
# Show cfgui at start
run_headless = False
#cfgui = config_ui.ConfigUI(CFG)
## Block until 'Run' button hit unless headless
#cfgui.setup(headless = args.headless)
#cfgui.verify()
else:
root = args.root
mountpoint = args.mountpoint
print("root:", root)
print("mountpoint:", mountpoint)

# Don't show cfgui
run_headless = True

stats = aostats.AOStats()

if not CFG.scenery_mounts:
log.warning(f"No installed sceneries detected. Exiting.")
sys.exit(0)

#if CFG.cache.clean_on_start:
# aoconfig.clean_cache(CFG.paths.cache_dir, int(float(CFG.cache.file_cache_size)))

import flighttrack
ftrack = threading.Thread(
target=flighttrack.run,
daemon=True
)

# Start helper threads
ftrack.start()

stats.start()

global RUNNING
RUNNING = True
do_threads = True
if do_threads:
mount_threads = []
for scenery in CFG.scenery_mounts:
t = threading.Thread(
target=run,
daemon=False,
args=(
scenery.get('root'),
scenery.get('mount'),
CFG.fuse.threading
)
)
t.start()
mount_threads.append(t)

try:
def handle_sigterm(sig, frame):
raise(SystemExit)

signal.signal(signal.SIGTERM, handle_sigterm)

time.sleep(1)
# Check things out
diagnose(CFG)

while RUNNING:
time.sleep(1)
except (KeyboardInterrupt, SystemExit):
RUNNING = False
pass
finally:
log.info("Shutting down ...")
for scenery in CFG.scenery_mounts:
unmount(scenery.get('mount'))
for t in mount_threads:
t.join(5)
print(f"Thread {t.ident} exited.")
else:
scenery = CFG.scenery_mounts[0]
run(
scenery.get('root'),
scenery.get('mount'),
# Run things
if args.root and args.mountpoint:
# Just mount specific requested dirs
root = args.root
mountpoint = args.mountpoint
print("root:", root)
print("mountpoint:", mountpoint)
aom = AOMount(CFG)
aom.domount(
root,
mountpoint,
CFG.fuse.threading
)
elif run_headless:
log.info("Running headless")
aom = AOMount(CFG)
aom.mount_sceneries()
else:
log.info("Running CFG UI")
cfgui = AOMountUI(CFG)
# Block until 'Run' button hit unless headless
cfgui.setup()


stats.stop()
flighttrack.ft.stop()
Expand Down
4 changes: 2 additions & 2 deletions autoortho/autoortho_fuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def getattr(self, path, fh=None):

@lru_cache
def readdir(self, path, fh):
log.info(f"READDIR: {path} {fh}")
#log.info(f"READDIR: {path} {fh}")
if path in ["/textures"]:
return ['.', '..', '.AOISWORKING', '24832_12416_BI16.dds']
elif path in ["/terrain"]:
Expand Down Expand Up @@ -264,7 +264,7 @@ def mkdir(self, path, mode):

@lru_cache
def statfs(self, path):
log.info(f"STATFS: {path}")
#log.info(f"STATFS: {path}")
full_path = self._full_path(path)
if platform.system() == 'Windows':
stats = {
Expand Down
Loading

0 comments on commit e3f0b9e

Please sign in to comment.