mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-24 18:40:03 +08:00
Merge pull request #253 from ZhangTianrong/3.0-dev
Fix resetting logfile w/o releasing handler and late ensuring of data dir existence
This commit is contained in:
@@ -4,10 +4,9 @@ import uvicorn
|
||||
|
||||
from module.api import router
|
||||
from module.conf import settings, setup_logger
|
||||
from module.core import reset_log
|
||||
|
||||
log_level = logging.DEBUG if settings.log.debug_enable else logging.INFO
|
||||
setup_logger(log_level)
|
||||
setup_logger(log_level, reset=True)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -21,10 +20,8 @@ uvicorn_logging_config = {
|
||||
},
|
||||
}}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not os.path.isdir("data"):
|
||||
os.mkdir("data")
|
||||
reset_log()
|
||||
uvicorn.run(
|
||||
router, host="0.0.0.0", port=settings.program.webui_port,
|
||||
log_config=uvicorn_logging_config,
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
LOG_PATH = "data/log.txt"
|
||||
|
||||
|
||||
def setup_logger(level: int = logging.INFO):
|
||||
def setup_logger(level: int = logging.INFO, reset: bool = False):
|
||||
if not os.path.isdir("data"):
|
||||
os.mkdir("data")
|
||||
if reset and os.path.isfile(LOG_PATH):
|
||||
os.remove(LOG_PATH)
|
||||
logging.addLevelName(logging.DEBUG, "DEBUG:")
|
||||
logging.addLevelName(logging.INFO, "INFO:")
|
||||
logging.addLevelName(logging.WARNING, "WARNING:")
|
||||
|
||||
@@ -17,11 +17,6 @@ logger = logging.getLogger(__name__)
|
||||
stop_event = threading.Event()
|
||||
|
||||
|
||||
def reset_log():
|
||||
if os.path.isfile(LOG_PATH):
|
||||
os.remove(LOG_PATH)
|
||||
|
||||
|
||||
def rss_loop(stop_event):
|
||||
rss_analyser = RSSAnalyser()
|
||||
rss_link = settings.rss_link()
|
||||
|
||||
@@ -125,17 +125,18 @@ class Renamer(DownloadClient):
|
||||
torrent_path=media_path,
|
||||
season=season,
|
||||
)
|
||||
new_path = self.gen_path(ep, bangumi_name, method=method)
|
||||
if media_path != new_path:
|
||||
renamed = self.rename_torrent_file(
|
||||
_hash=_hash, old_path=media_path, new_path=new_path
|
||||
)
|
||||
if not renamed:
|
||||
logger.warning(f"{media_path} rename failed")
|
||||
# Delete bad torrent.
|
||||
if settings.bangumi_manage.remove_bad_torrent:
|
||||
self.delete_torrent(_hash)
|
||||
break
|
||||
if ep:
|
||||
new_path = self.gen_path(ep, bangumi_name, method=method)
|
||||
if media_path != new_path:
|
||||
renamed = self.rename_torrent_file(
|
||||
_hash=_hash, old_path=media_path, new_path=new_path
|
||||
)
|
||||
if not renamed:
|
||||
logger.warning(f"{media_path} rename failed")
|
||||
# Delete bad torrent.
|
||||
if settings.bangumi_manage.remove_bad_torrent:
|
||||
self.delete_torrent(_hash)
|
||||
break
|
||||
|
||||
def rename_subtitles(
|
||||
self,
|
||||
@@ -154,13 +155,14 @@ class Renamer(DownloadClient):
|
||||
season=season,
|
||||
file_type="subtitle",
|
||||
)
|
||||
new_path = self.gen_path(sub, bangumi_name, method=method)
|
||||
if subtitle_path != new_path:
|
||||
renamed = self.rename_torrent_file(
|
||||
_hash=_hash, old_path=subtitle_path, new_path=new_path
|
||||
)
|
||||
if not renamed:
|
||||
logger.warning(f"{subtitle_path} rename failed")
|
||||
if sub:
|
||||
new_path = self.gen_path(sub, bangumi_name, method=method)
|
||||
if subtitle_path != new_path:
|
||||
renamed = self.rename_torrent_file(
|
||||
_hash=_hash, old_path=subtitle_path, new_path=new_path
|
||||
)
|
||||
if not renamed:
|
||||
logger.warning(f"{subtitle_path} rename failed")
|
||||
|
||||
@staticmethod
|
||||
def get_season_info(save_path: str, download_path: str):
|
||||
|
||||
Reference in New Issue
Block a user