another test on log export

This commit is contained in:
avollkopf 2024-01-12 17:57:34 +01:00
parent 0dfabde7b3
commit b642bab351
2 changed files with 28 additions and 27 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.3.2.a1" __version__ = "4.3.2.a2"
__codename__ = "Winter Storm" __codename__ = "Winter Storm"

View file

@ -1,11 +1,8 @@
import logging import logging
import os import os
import importlib, importlib_metadata
#from importlib_metadata import metadata
import pkgutil
import shutil import shutil
import pkgutil
import psutil import psutil
from tabulate import tabulate
import pathlib import pathlib
import json import json
import aiohttp import aiohttp
@ -16,6 +13,8 @@ from cbpi.api.config import ConfigType
from cbpi.api import * from cbpi.api import *
import zipfile import zipfile
import socket import socket
import importlib
from tabulate import tabulate
class SystemController: class SystemController:
@ -45,6 +44,26 @@ class SystemController:
dir_name = pathlib.Path(self.cbpi.config_folder.get_file_path('')) dir_name = pathlib.Path(self.cbpi.config_folder.get_file_path(''))
shutil.make_archive(output_filename, 'zip', dir_name) shutil.make_archive(output_filename, 'zip', dir_name)
async def plugins_list(self):
result = []
discovered_plugins = {
name: importlib.import_module(name)
for finder, name, ispkg
in pkgutil.iter_modules()
if name.startswith('cbpi') and len(name) > 4
}
for key, module in discovered_plugins.items():
from importlib.metadata import version
try:
from importlib.metadata import (distribution, metadata,
version)
meta = metadata(key)
result.append(dict(Name=meta["Name"], Version=meta["Version"], Author=meta["Author"], Homepage=meta["Home-page"], Summary=meta["Summary"]))
except Exception as e:
print(e)
return tabulate(result, headers="keys")
async def downloadlog(self, logtime): async def downloadlog(self, logtime):
filename = "cbpi4.log" filename = "cbpi4.log"
fullname = pathlib.Path(os.path.join(".",filename)) fullname = pathlib.Path(os.path.join(".",filename))
@ -64,11 +83,12 @@ class SystemController:
else: else:
os.system('journalctl --since \"{} hours ago\" -u craftbeerpi.service --output cat > {}'.format(logtime, fullname)) os.system('journalctl --since \"{} hours ago\" -u craftbeerpi.service --output cat > {}'.format(logtime, fullname))
plugins=self.plugins_list() plugins = await self.plugins_list()
with open(fullpluginname) as f:
with open(fullpluginname, 'w') as f:
f.write(plugins) f.write(plugins)
#os.system('cbpi plugins > {}'.format(fullpluginname)) #os.system('echo "{}" >> {}'.format(plugins,fullpluginname))
try: try:
actors = self.cbpi.actor.get_state() actors = self.cbpi.actor.get_state()
@ -113,25 +133,6 @@ class SystemController:
for filename in filenames: for filename in filenames:
shutil.chown(os.path.join(dirpath, filename), owner, group) shutil.chown(os.path.join(dirpath, filename), owner, group)
def plugins_list(self):
result = []
discovered_plugins = {
name: importlib.import_module(name)
for finder, name, ispkg
in pkgutil.iter_modules()
if name.startswith('cbpi') and len(name) > 4
}
for key, module in discovered_plugins.items():
try:
meta = importlib_metadata.metadata(key)
result.append(dict(Name=meta["Name"], Version=meta["Version"], Author=meta["Author"], Homepage=meta["Home-page"], Summary=meta["Summary"]))
except Exception as e:
print(e)
#print(tabulate(result, headers="keys"))
return tabulate(result, headers="keys")
async def restoreConfig(self, data): async def restoreConfig(self, data):
fileData = data['File'] fileData = data['File']
filename = fileData.filename filename = fileData.filename