diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 875186b..134dd57 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.4.1.a3" +__version__ = "4.4.1.a6" __codename__ = "Yeast Starter" diff --git a/cbpi/controller/system_controller.py b/cbpi/controller/system_controller.py index ebf6f42..ae8a346 100644 --- a/cbpi/controller/system_controller.py +++ b/cbpi/controller/system_controller.py @@ -15,6 +15,14 @@ import zipfile import socket import importlib from tabulate import tabulate +from datetime import datetime, timedelta + +try: + from systemd import journal + systemd_available=True +except Exception: + logger.warning("Failed to load systemd library. logfile download not available") + systemd_available=False class SystemController: @@ -77,19 +85,29 @@ class SystemController: fullkettlename = pathlib.Path(os.path.join(".",kettlename)) output_filename="cbpi4_log.zip" + result=[] + if systemd_available: + j = journal.Reader() + if logtime == "b": + j.this_boot() + else: + since = datetime.now() - timedelta(hours=int(logtime)) + j.seek_realtime(since) + j.add_match(_SYSTEMD_UNIT="craftbeerpi.service") - if logtime == "b": - os.system('journalctl -b -u craftbeerpi.service --output cat > {}'.format(fullname)) - else: - os.system('journalctl --since \"{} hours ago\" -u craftbeerpi.service --output cat > {}'.format(logtime, fullname)) + for entry in j: + result.append(entry['MESSAGE']) + try: + with open(fullname, 'w') as f: + for line in result: + f.write(f"{line}\n") + except Exception as e: + logging.error(e) plugins = await self.plugins_list() - with open(fullpluginname, 'w') as f: f.write(plugins) - #os.system('echo "{}" >> {}'.format(plugins,fullpluginname)) - try: actors = self.cbpi.actor.get_state() json.dump(actors['data'],open(fullactorname,'w'),indent=4, sort_keys=True) diff --git a/setup.py b/setup.py index fab42ac..c6cafe3 100644 --- a/setup.py +++ b/setup.py @@ -64,7 +64,8 @@ setup(name='cbpi4', 'importlib_metadata', 'numpy==1.26.4', 'pandas==2.2.2'] + ( - ['rpi-lgpio'] if raspberrypi else [] ), + ['rpi-lgpio'] if raspberrypi else [] ) + ( + ['systemd-python'] if localsystem == "Linux" else [] ), dependency_links=[ 'https://testpypi.python.org/pypi',