Skip to content

Commit

Permalink
Merge pull request #398 from kubilus1/guilogs
Browse files Browse the repository at this point in the history
Show logs in config UI.  Adjust how we kick off execution
  • Loading branch information
kubilus1 authored Sep 28, 2023
2 parents 5690d7f + 7637edd commit 77b3cd2
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 200 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ _autoortho_win.exe: autoortho/.version
--include-data-file=./autoortho/aoimage/*.dll=aoimage/ \
--include-data-dir=./autoortho/imgs=imgs \
--onefile \
--disable-console \
./autoortho/__main__.py -o autoortho_win.exe

__main__.dist: autoortho/.version
Expand All @@ -61,6 +62,7 @@ __main__.dist: autoortho/.version
--include-data-file=./autoortho/aoimage/*.dll=aoimage/ \
--include-data-dir=./autoortho/imgs=imgs \
--standalone \
--disable-console \
./autoortho/__main__.py -o autoortho_win.exe

win_exe: AutoOrtho_win_$(VERSION).exe
Expand Down
2 changes: 1 addition & 1 deletion autoortho/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setuplogs():
maxBytes=10485760,
backupCount=5
),
logging.StreamHandler()
logging.StreamHandler() if sys.stdout is not None else logging.NullHandler()
]
)
log = logging.getLogger(__name__)
Expand Down
251 changes: 144 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,88 +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
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)
cfgui.setup()

stats.stop()
flighttrack.ft.stop()

log.info("AutoOrtho exit.")


if __name__ == '__main__':
main()
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 77b3cd2

Please sign in to comment.