From 858c71856da9ec61e92a730011fc8300fea4cdee Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 2 May 2024 12:45:44 +0200 Subject: [PATCH] simplify log download --- cbpi/__init__.py | 2 +- cbpi/controller/system_controller.py | 56 ++++++++-------------------- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 9c63548..134dd57 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.4.1.a5" +__version__ = "4.4.1.a6" __codename__ = "Yeast Starter" diff --git a/cbpi/controller/system_controller.py b/cbpi/controller/system_controller.py index ed13271..7f45365 100644 --- a/cbpi/controller/system_controller.py +++ b/cbpi/controller/system_controller.py @@ -144,53 +144,29 @@ class SystemController: fullkettlename = pathlib.Path(os.path.join(".",kettlename)) output_filename="cbpi4_log.zip" - - if logtime == "b": - if systemd_available: - #os.system('journalctl -b -u craftbeerpi.service --output cat > {}'.format(fullname)) - b = journal.Reader() - b.add_match(_TRANSPORT="kernel") - result=[] - for entry in b: - message=entry['MESSAGE'] - if message.find("Booting") != -1: - result.append(entry['__REALTIME_TIMESTAMP']) - j = journal.Reader() - j.add_match(_SYSTEMD_UNIT="craftbeerpi.service") - j.seek_realtime(result[-1]) - result=[] - 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) - - else: - if systemd_available: - result=[] - #os.system('journalctl --since \"{} hours ago\" -u craftbeerpi.service --output cat > {}'.format(logtime, fullname)) - j = journal.Reader() - j.add_match(_SYSTEMD_UNIT="craftbeerpi.service") + 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) - 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) + j.add_match(_SYSTEMD_UNIT="craftbeerpi.service") + + 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)