async process + loggging
parent
24279524c7
commit
a15c9bc220
|
@ -15,7 +15,7 @@ from PIL import Image
|
||||||
from mutagen.oggvorbis import OggVorbis
|
from mutagen.oggvorbis import OggVorbis
|
||||||
from distutils.dir_util import copy_tree
|
from distutils.dir_util import copy_tree
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from widgets import create_logger
|
||||||
|
|
||||||
def find_install_dir():
|
def find_install_dir():
|
||||||
library_folders = Path("C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf")
|
library_folders = Path("C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf")
|
||||||
|
@ -52,22 +52,24 @@ def update(utils_dir: str):
|
||||||
|
|
||||||
|
|
||||||
def download_and_extract(url_source, out_archive, utils_dir="./utils", subdir=""):
|
def download_and_extract(url_source, out_archive, utils_dir="./utils", subdir=""):
|
||||||
logging.info(f"Downloading {url_source}, this may take a while.")
|
logger = create_logger()
|
||||||
|
logger.info(f"Downloading {url_source}, this may take a while.")
|
||||||
|
|
||||||
download_via_requests(url_source, out_archive)
|
download_via_requests(url_source, out_archive)
|
||||||
time.sleep(0.7)
|
time.sleep(0.7)
|
||||||
logging.info("Download complete.")
|
logger.info("Download complete.")
|
||||||
|
|
||||||
logging.info(f"Extracting {out_archive}")
|
logger.info(f"Extracting {out_archive}")
|
||||||
extract = [f"{utils_dir}/7z/7za.exe", "x", out_archive, "-o" f"{utils_dir}{subdir}"]
|
extract = [f"{utils_dir}/7z/7za.exe", "x", out_archive, "-o" f"{utils_dir}{subdir}"]
|
||||||
subprocess.call(extract)
|
subprocess.call(extract)
|
||||||
|
|
||||||
time.sleep(0.7)
|
time.sleep(0.7)
|
||||||
logging.info("Removing " + out_archive)
|
logger.info("Removing " + out_archive)
|
||||||
os.remove(out_archive)
|
os.remove(out_archive)
|
||||||
|
|
||||||
|
|
||||||
def download_ffmpeg(utils_dir: str, clean=False):
|
def download_ffmpeg(utils_dir: str, clean=False):
|
||||||
|
|
||||||
if clean:
|
if clean:
|
||||||
rmfulldir(f"{utils_dir}/ffmpeg-" + get_ffmpeg_version() + "-full_build")
|
rmfulldir(f"{utils_dir}/ffmpeg-" + get_ffmpeg_version() + "-full_build")
|
||||||
|
|
||||||
|
|
|
@ -105,8 +105,6 @@ class OptionsWidget(QWidget):
|
||||||
layout.addWidget(self.console_widget)
|
layout.addWidget(self.console_widget)
|
||||||
layout.addStretch()
|
layout.addStretch()
|
||||||
|
|
||||||
self.setSizePolicy(QSizePolicy.Policy.Maximum, QSizePolicy.Policy.Minimum)
|
|
||||||
|
|
||||||
# def update_label_description(self):
|
# def update_label_description(self):
|
||||||
|
|
||||||
def update_screen_res(self):
|
def update_screen_res(self):
|
||||||
|
@ -126,6 +124,12 @@ class OptionsWidget(QWidget):
|
||||||
"durability": self.cbox_durability.isChecked(),
|
"durability": self.cbox_durability.isChecked(),
|
||||||
"repair": self.cbox_repair.isChecked()}
|
"repair": self.cbox_repair.isChecked()}
|
||||||
|
|
||||||
|
def run_process(self, function, arguments):
|
||||||
|
logger = create_logger()
|
||||||
|
logger.info('Starting pooling')
|
||||||
|
p = multiprocessing.Pool()
|
||||||
|
p.apply_async(function, arguments)
|
||||||
|
|
||||||
|
|
||||||
# TODO: implement random local mod name
|
# TODO: implement random local mod name
|
||||||
|
|
||||||
|
@ -355,7 +359,6 @@ class ValidationWidget(QWidget):
|
||||||
except yaml.scanner.ScannerError as e:
|
except yaml.scanner.ScannerError as e:
|
||||||
logging.error(f"Error applying yaml code:\n\n{str(e)}")
|
logging.error(f"Error applying yaml code:\n\n{str(e)}")
|
||||||
|
|
||||||
|
|
||||||
def load_tapes(self, tapes):
|
def load_tapes(self, tapes):
|
||||||
self.tapes = tapes
|
self.tapes = tapes
|
||||||
|
|
||||||
|
@ -366,7 +369,6 @@ class ValidationWidget(QWidget):
|
||||||
self.jump_spinbox.setValue(0)
|
self.jump_spinbox.setValue(0)
|
||||||
self.jump_spinbox.setMaximum(i)
|
self.jump_spinbox.setMaximum(i)
|
||||||
|
|
||||||
|
|
||||||
def save_tapes(self):
|
def save_tapes(self):
|
||||||
yaml_text = yaml.safe_dump(self.tapes, sort_keys=False, allow_unicode=True).replace("\n-", "\n\n-")
|
yaml_text = yaml.safe_dump(self.tapes, sort_keys=False, allow_unicode=True).replace("\n-", "\n\n-")
|
||||||
self.parent.editor_widget.editor.setPlainText(yaml_text)
|
self.parent.editor_widget.editor.setPlainText(yaml_text)
|
||||||
|
@ -432,18 +434,18 @@ class UpdateWidget(QGroupBox):
|
||||||
self.git_checkbox.setChecked(exists)
|
self.git_checkbox.setChecked(exists)
|
||||||
return exists
|
return exists
|
||||||
|
|
||||||
|
|
||||||
class ConsoleWidget(QGroupBox):
|
class ConsoleWidget(QGroupBox):
|
||||||
def __init__(self, parent: QWidget):
|
def __init__(self, parent: QWidget):
|
||||||
super().__init__("Info")
|
super().__init__("Info")
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|
||||||
self.console = QPlainTextEdit()
|
self.console = QPlainTextEdit(self)
|
||||||
|
|
||||||
layout = QVBoxLayout(self)
|
layout = QVBoxLayout(self)
|
||||||
layout.addWidget(self.console)
|
layout.addWidget(self.console)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class InstallWidget(QGroupBox):
|
class InstallWidget(QGroupBox):
|
||||||
def __init__(self, parent: QWidget):
|
def __init__(self, parent: QWidget):
|
||||||
super().__init__("Install steps")
|
super().__init__("Install steps")
|
||||||
|
@ -518,7 +520,9 @@ class InstallWidget(QGroupBox):
|
||||||
return exists
|
return exists
|
||||||
|
|
||||||
def download_ffmpeg_action(self):
|
def download_ffmpeg_action(self):
|
||||||
download_ffmpeg(self.ffmpeg_dir.directory)
|
|
||||||
|
self.parent.run_process(download_ffmpeg, (self.ffmpeg_dir.directory, ))
|
||||||
|
#download_ffmpeg(self.ffmpeg_dir.directory)
|
||||||
self.does_ffmpeg_exist()
|
self.does_ffmpeg_exist()
|
||||||
|
|
||||||
def are_songs_ready(self):
|
def are_songs_ready(self):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from PySide6.QtCore import QSize, Qt, Slot, QRect, QFileSystemWatcher, Signal, QTime
|
from PySide6.QtCore import QSize, Qt, Slot, QRect, QFileSystemWatcher, Signal, QTime, QObject
|
||||||
from PySide6.QtGui import QIcon, QAction, QShortcut, QKeySequence, QPainter, QColor, QTextFormat, QPixmap, QFontMetrics
|
from PySide6.QtGui import QIcon, QAction, QShortcut, QKeySequence, QPainter, QColor, QTextFormat, QPixmap, QFontMetrics
|
||||||
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QWidget, QLabel, QVBoxLayout, QHBoxLayout, \
|
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QWidget, QLabel, QVBoxLayout, QHBoxLayout, \
|
||||||
QGroupBox, QLineEdit, QCheckBox, QSpinBox, QPlainTextEdit, QSizePolicy, QGridLayout, QTextEdit, QScrollArea, QFrame, \
|
QGroupBox, QLineEdit, QCheckBox, QSpinBox, QPlainTextEdit, QSizePolicy, QGridLayout, QTextEdit, QScrollArea, QFrame, \
|
||||||
|
@ -7,12 +7,31 @@ from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QWidget, Q
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import validators
|
import validators
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import multiprocessing
|
||||||
|
|
||||||
|
from logging.handlers import QueueListener, QueueHandler
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
|
def create_logger():
|
||||||
|
logger = multiprocessing.get_logger()
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
formatter = logging.Formatter('[%(asctime)s| %(levelname)s| %(processName)s] %(message)s')
|
||||||
|
handler = logging.StreamHandler()
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
|
||||||
|
# this bit will make sure you won't have
|
||||||
|
# duplicated messages in the output
|
||||||
|
if not len(logger.handlers):
|
||||||
|
logger.addHandler(handler)
|
||||||
|
return logger
|
||||||
|
|
||||||
|
|
||||||
class LabelWebLink(QLabel):
|
class LabelWebLink(QLabel):
|
||||||
def __init__(self, text):
|
def __init__(self, text):
|
||||||
text = f"<a href=\"{text}\">{text.replace('https://', '')}</a>"
|
text = f"<a href=\"{text}\">{text.replace('https://', '')}</a>"
|
||||||
|
|
Loading…
Reference in New Issue