simplify log download

This commit is contained in:
avollkopf 2024-05-02 12:45:44 +02:00
parent f5c242d7c8
commit 858c71856d
2 changed files with 17 additions and 41 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.4.1.a5"
__version__ = "4.4.1.a6"
__codename__ = "Yeast Starter"

View file

@ -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)