refactoring: LOGS_PATH constant renamed to LOGS_DIR and moved to 'api' module

This commit is contained in:
Vinicius Moreira
2021-11-24 11:08:26 -03:00
parent 83cc7cc134
commit 63dd4963cf
4 changed files with 13 additions and 12 deletions

View File

@@ -3,4 +3,3 @@ __app_name__ = 'bauh'
import os
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
LOGS_PATH = '/tmp/{}/logs'.format(__app_name__)

View File

@@ -9,3 +9,4 @@ CONFIG_PATH = '{}/.config/bauh'.format(str(Path.home()))
USER_THEMES_PATH = '{}/.local/share/bauh/themes'.format(str(Path.home()))
DESKTOP_ENTRIES_DIR = '{}/.local/share/applications'.format(str(Path.home()))
TEMP_DIR = f'/tmp/{__app_name__}@{getuser()}'
LOGS_DIR = f'{TEMP_DIR}/logs'

View File

@@ -12,7 +12,7 @@ from PyQt5.QtCore import QThread, pyqtSignal, QObject
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QWidget
from bauh import LOGS_PATH
from bauh.api import user
from bauh.api.abstract.cache import MemoryCache
from bauh.api.abstract.controller import SoftwareManager, UpgradeRequirement, UpgradeRequirements, SoftwareAction
from bauh.api.abstract.handler import ProcessWatcher
@@ -20,7 +20,7 @@ from bauh.api.abstract.model import PackageStatus, SoftwarePackage, CustomSoftwa
from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOption, TextComponent, \
FormComponent, ViewComponent
from bauh.api.exception import NoInternetException
from bauh.api import user
from bauh.api.paths import LOGS_DIR
from bauh.commons.html import bold
from bauh.commons.internet import InternetChecker
from bauh.commons.system import get_human_size_str, ProcessHandler, SimpleProcess
@@ -200,8 +200,8 @@ class AsyncAction(QThread, ProcessWatcher):
class UpgradeSelected(AsyncAction):
LOGS_DIR = '{}/upgrade'.format(LOGS_PATH)
SUMMARY_FILE = LOGS_DIR + '/{}_summary.txt'
UPGRADE_LOGS_DIR = f'{LOGS_DIR}/upgrade'
SUMMARY_FILE = UPGRADE_LOGS_DIR + '/{}_summary.txt'
def __init__(self, manager: SoftwareManager, internet_checker: InternetChecker, i18n: I18n, pkgs: List[PackageView] = None):
super(UpgradeSelected, self).__init__()
@@ -330,7 +330,7 @@ class UpgradeSelected(AsyncAction):
def _write_summary_log(self, upgrade_id: str, requirements: UpgradeRequirements):
try:
Path(self.LOGS_DIR).mkdir(parents=True, exist_ok=True)
Path(self.UPGRADE_LOGS_DIR).mkdir(parents=True, exist_ok=True)
summary_text = StringIO()
summary_text.write('Upgrade summary ( id: {} )'.format(upgrade_id))

View File

@@ -11,14 +11,14 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QCheckBox, QHeaderView, QToolB
QLabel, QPlainTextEdit, QProgressBar, QPushButton, QComboBox, QApplication, QListView, QSizePolicy, \
QMenu, QHBoxLayout
from bauh import LOGS_PATH
from bauh.api import user
from bauh.api.abstract.cache import MemoryCache
from bauh.api.abstract.context import ApplicationContext
from bauh.api.abstract.controller import SoftwareManager, SoftwareAction
from bauh.api.abstract.model import SoftwarePackage
from bauh.api.abstract.view import MessageType
from bauh.api.http import HttpClient
from bauh.api import user
from bauh.api.paths import LOGS_DIR
from bauh.commons.html import bold
from bauh.context import set_theme
from bauh.stylesheet import read_all_themes_metadata, ThemeMetadata
@@ -1106,8 +1106,8 @@ class ManageWindow(QWidget):
if output:
try:
Path(UpgradeSelected.LOGS_DIR).mkdir(parents=True, exist_ok=True)
logs_path = '{}/{}.log'.format(UpgradeSelected.LOGS_DIR, res['id'])
Path(UpgradeSelected.UPGRADE_LOGS_DIR).mkdir(parents=True, exist_ok=True)
logs_path = '{}/{}.log'.format(UpgradeSelected.UPGRADE_LOGS_DIR, res['id'])
with open(logs_path, 'w+') as f:
f.write(output)
@@ -1339,11 +1339,12 @@ class ManageWindow(QWidget):
console_output = self.textarea_details.toPlainText()
if console_output:
log_path = '{}/install/{}/{}'.format(LOGS_PATH, res['pkg'].model.get_type(), res['pkg'].model.name)
log_path = f"{LOGS_DIR}/install/{res['pkg'].model.get_type()}/{res['pkg'].model.name}"
try:
Path(log_path).mkdir(parents=True, exist_ok=True)
log_file = log_path + '/{}.log'.format(int(time.time()))
log_file = f'{log_path}/{int(time.time())}.log'
with open(log_file, 'w+') as f:
f.write(console_output)