From 44b7199087b14774005b5a23994595d7e64e1ce2 Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 19 Oct 2023 19:23:05 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix=20=E6=9B=B4=E6=96=B0=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/system.py | 10 +- app/plugins/doubansync/__init__.py | 2 +- .../moviepilotupdatenotify/__init__.py | 177 +++++++++--------- 3 files changed, 96 insertions(+), 93 deletions(-) diff --git a/app/chain/system.py b/app/chain/system.py index 41c49702..82c79d52 100644 --- a/app/chain/system.py +++ b/app/chain/system.py @@ -59,13 +59,11 @@ class SystemChain(ChainBase, metaclass=Singleton): "userid": userid }, self._update_file) + # 更新系统 + if not settings.MOVIEPILOT_AUTO_UPDATE: + os.system("cd / && bash /usr/local/bin/mp_update") # 重启系统 - os.system("bash /usr/local/bin/mp_update") - - if channel and userid: - self.post_message(Notification(channel=channel, - title="暂无新版本!", userid=userid)) - self.remove_cache(self._update_file) + SystemUtils.restart() def version(self, channel: MessageChannel, userid: Union[int, str]): """ diff --git a/app/plugins/doubansync/__init__.py b/app/plugins/doubansync/__init__.py index 19b4e272..12700e4e 100644 --- a/app/plugins/doubansync/__init__.py +++ b/app/plugins/doubansync/__init__.py @@ -450,7 +450,7 @@ class DoubanSync(_PluginBase): url = self._interests_url % user_id results = self.rsshelper.parse(url) if not results: - logger.error(f"未获取到用户 {user_id} 豆瓣RSS数据:{url}") + logger.warn(f"未获取到用户 {user_id} 豆瓣RSS数据:{url}") continue else: logger.info(f"获取到用户 {user_id} 豆瓣RSS数据:{len(results)}") diff --git a/app/plugins/moviepilotupdatenotify/__init__.py b/app/plugins/moviepilotupdatenotify/__init__.py index 8336e0c1..415273cf 100644 --- a/app/plugins/moviepilotupdatenotify/__init__.py +++ b/app/plugins/moviepilotupdatenotify/__init__.py @@ -1,3 +1,5 @@ +import datetime + from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.triggers.cron import CronTrigger @@ -81,18 +83,21 @@ class MoviePilotUpdateNotify(_PluginBase): # 本地版本 local_version = SystemChain().get_local_version() - if release_version == local_version: + if local_version and release_version <= local_version: logger.info(f"当前版本:{local_version} 远程版本:{release_version} 停止运行") return # 推送更新消息 if self._notify: + # 将时间字符串转为datetime对象 + update_time = datetime.datetime.strptime(update_time, "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d %H:%M:%S") self.post_message( mtype=NotificationType.SiteMessage, title="【MoviePilot更新通知】", text=f"{release_version} \n" f"\n" f"{description} \n" + f"\n" f"{update_time}") # 自动更新 @@ -131,91 +136,91 @@ class MoviePilotUpdateNotify(_PluginBase): 拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构 """ return [ - { - 'component': 'VForm', - 'content': [ - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 4 - }, - 'content': [ - { - 'component': 'VSwitch', - 'props': { - 'model': 'enabled', - 'label': '启用插件', - } - } - ] - }, - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 4 - }, - 'content': [ - { - 'component': 'VSwitch', - 'props': { - 'model': 'update', - 'label': '自动更新', - } - } - ] - }, - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 4 - }, - 'content': [ - { - 'component': 'VSwitch', - 'props': { - 'model': 'notify', - 'label': '发送通知', - } - } - ] - } - ] - }, - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12, - }, - 'content': [ - { - 'component': 'VTextField', - 'props': { - 'model': 'cron', - 'label': '检查周期', - 'placeholder': '5位cron表达式' - } - } - ] - }, - ] - } - ] - } - ], { - "enabled": False, - "update": False, - "notify": False, - "cron": "0 9 * * *" - } + { + 'component': 'VForm', + 'content': [ + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'enabled', + 'label': '启用插件', + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'update', + 'label': '自动更新', + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'notify', + 'label': '发送通知', + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VTextField', + 'props': { + 'model': 'cron', + 'label': '检查周期', + 'placeholder': '5位cron表达式' + } + } + ] + }, + ] + } + ] + } + ], { + "enabled": False, + "update": False, + "notify": False, + "cron": "0 9 * * *" + } def get_page(self) -> List[dict]: pass From 3a20946f628e0ba91dd7b77c40812fdb33de9174 Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 19 Oct 2023 20:11:19 +0800 Subject: [PATCH 2/4] fix remove update --- app/chain/system.py | 47 +------------------ app/command.py | 6 --- .../moviepilotupdatenotify/__init__.py | 27 +---------- 3 files changed, 4 insertions(+), 76 deletions(-) diff --git a/app/chain/system.py b/app/chain/system.py index 82c79d52..c8c025f0 100644 --- a/app/chain/system.py +++ b/app/chain/system.py @@ -1,5 +1,4 @@ import json -import os import re from typing import Union @@ -18,7 +17,6 @@ class SystemChain(ChainBase, metaclass=Singleton): """ _restart_file = "__system_restart__" - _update_file = "__system_update__" def remote_clear_cache(self, channel: MessageChannel, userid: Union[int, str]): """ @@ -42,29 +40,6 @@ class SystemChain(ChainBase, metaclass=Singleton): }, self._restart_file) SystemUtils.restart() - def update(self, channel: MessageChannel = None, userid: Union[int, str] = None): - """ - 重启系统 - """ - if not SystemUtils.is_docker(): - logger.error("非Docker版本不支持自动更新!") - return - - if channel and userid: - self.post_message(Notification(channel=channel, - title="系统正在更新,请耐心等候!", userid=userid)) - # 保存重启信息 - self.save_cache({ - "channel": channel.value, - "userid": userid - }, self._update_file) - - # 更新系统 - if not settings.MOVIEPILOT_AUTO_UPDATE: - os.system("cd / && bash /usr/local/bin/mp_update") - # 重启系统 - SystemUtils.restart() - def version(self, channel: MessageChannel, userid: Union[int, str]): """ 查看当前版本、远程版本 @@ -84,12 +59,9 @@ class SystemChain(ChainBase, metaclass=Singleton): 如通过交互命令重启, 重启完发送msg """ - cache_file, action, channel, userid = None, None, None, None # 重启消息 restart_channel = self.load_cache(self._restart_file) if restart_channel: - cache_file = self._restart_file - action = "重启" # 发送重启完成msg if not isinstance(restart_channel, dict): restart_channel = json.loads(restart_channel) @@ -98,21 +70,6 @@ class SystemChain(ChainBase, metaclass=Singleton): channel.value == restart_channel.get('channel')), None) userid = restart_channel.get('userid') - # 更新消息 - update_channel = self.load_cache(self._update_file) - if update_channel: - cache_file = self._update_file - action = "更新" - # 发送重启完成msg - if not isinstance(update_channel, dict): - update_channel = json.loads(update_channel) - channel = next( - (channel for channel in MessageChannel.__members__.values() if - channel.value == update_channel.get('channel')), None) - userid = update_channel.get('userid') - - # 发送消息 - if channel and userid: # 版本号 release_version = self.__get_release_version() local_version = self.get_local_version() @@ -121,9 +78,9 @@ class SystemChain(ChainBase, metaclass=Singleton): else: title = f"当前版本:{local_version},远程版本:{release_version}" self.post_message(Notification(channel=channel, - title=f"系统已{action}完成!{title}", + title=f"系统已重启完成!{title}", userid=userid)) - self.remove_cache(cache_file) + self.remove_cache(self._restart_file) @staticmethod def __get_release_version(): diff --git a/app/command.py b/app/command.py index cbc02442..cdfdd01d 100644 --- a/app/command.py +++ b/app/command.py @@ -149,12 +149,6 @@ class Command(metaclass=Singleton): "description": "当前版本", "category": "管理", "data": {} - }, - "/update": { - "func": SystemChain().update, - "description": "更新系统", - "category": "管理", - "data": {} } } # 汇总插件命令 diff --git a/app/plugins/moviepilotupdatenotify/__init__.py b/app/plugins/moviepilotupdatenotify/__init__.py index 415273cf..0de1be33 100644 --- a/app/plugins/moviepilotupdatenotify/__init__.py +++ b/app/plugins/moviepilotupdatenotify/__init__.py @@ -38,7 +38,6 @@ class MoviePilotUpdateNotify(_PluginBase): _enabled = False # 任务执行间隔 _cron = None - _update = False _notify = False # 定时器 @@ -51,7 +50,6 @@ class MoviePilotUpdateNotify(_PluginBase): if config: self._enabled = config.get("enabled") self._cron = config.get("cron") - self._update = config.get("update") self._notify = config.get("notify") # 加载模块 @@ -100,11 +98,6 @@ class MoviePilotUpdateNotify(_PluginBase): f"\n" f"{update_time}") - # 自动更新 - if self._update: - logger.info("开始执行自动更新…") - SystemChain().update() - @staticmethod def __get_release_version(): """ @@ -146,7 +139,7 @@ class MoviePilotUpdateNotify(_PluginBase): 'component': 'VCol', 'props': { 'cols': 12, - 'md': 4 + 'md': 6 }, 'content': [ { @@ -162,23 +155,7 @@ class MoviePilotUpdateNotify(_PluginBase): 'component': 'VCol', 'props': { 'cols': 12, - 'md': 4 - }, - 'content': [ - { - 'component': 'VSwitch', - 'props': { - 'model': 'update', - 'label': '自动更新', - } - } - ] - }, - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 4 + 'md': 6 }, 'content': [ { From c6a43a5dde57b30e6a4df32c6ca5cbd7daadc28a Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 19 Oct 2023 20:20:09 +0800 Subject: [PATCH 3/4] fix auto restart --- .../moviepilotupdatenotify/__init__.py | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/app/plugins/moviepilotupdatenotify/__init__.py b/app/plugins/moviepilotupdatenotify/__init__.py index 0de1be33..32ae4580 100644 --- a/app/plugins/moviepilotupdatenotify/__init__.py +++ b/app/plugins/moviepilotupdatenotify/__init__.py @@ -10,13 +10,14 @@ from typing import Any, List, Dict, Tuple, Optional from app.log import logger from app.schemas import NotificationType from app.utils.http import RequestUtils +from app.utils.system import SystemUtils class MoviePilotUpdateNotify(_PluginBase): # 插件名称 plugin_name = "MoviePilot更新推送" # 插件描述 - plugin_desc = "MoviePilot推送release更新通知、自动更新。" + plugin_desc = "MoviePilot推送release更新通知、自动重启。" # 插件图标 plugin_icon = "update.png" # 主题色 @@ -38,6 +39,7 @@ class MoviePilotUpdateNotify(_PluginBase): _enabled = False # 任务执行间隔 _cron = None + _restart = False _notify = False # 定时器 @@ -50,6 +52,7 @@ class MoviePilotUpdateNotify(_PluginBase): if config: self._enabled = config.get("enabled") self._cron = config.get("cron") + self._restart = config.get("restart") self._notify = config.get("notify") # 加载模块 @@ -98,6 +101,11 @@ class MoviePilotUpdateNotify(_PluginBase): f"\n" f"{update_time}") + # 自动重启 + if self._restart: + logger.info("开始执行自动重启…") + SystemUtils.restart() + @staticmethod def __get_release_version(): """ @@ -139,7 +147,7 @@ class MoviePilotUpdateNotify(_PluginBase): 'component': 'VCol', 'props': { 'cols': 12, - 'md': 6 + 'md': 4 }, 'content': [ { @@ -155,7 +163,23 @@ class MoviePilotUpdateNotify(_PluginBase): 'component': 'VCol', 'props': { 'cols': 12, - 'md': 6 + 'md': 4 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'restart', + 'label': '自动重启', + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 }, 'content': [ { @@ -194,7 +218,7 @@ class MoviePilotUpdateNotify(_PluginBase): } ], { "enabled": False, - "update": False, + "restart": False, "notify": False, "cron": "0 9 * * *" } From 4bfdf1dede7f3a483d44c3a6698252c5fee1dbf8 Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 19 Oct 2023 20:21:40 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix=20add=20=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moviepilotupdatenotify/__init__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/plugins/moviepilotupdatenotify/__init__.py b/app/plugins/moviepilotupdatenotify/__init__.py index 32ae4580..b2cb81cd 100644 --- a/app/plugins/moviepilotupdatenotify/__init__.py +++ b/app/plugins/moviepilotupdatenotify/__init__.py @@ -213,6 +213,25 @@ class MoviePilotUpdateNotify(_PluginBase): ] }, ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'text': '如要开启自动重启,请确认MOVIEPILOT_AUTO_UPDATE设置为true,重启即更新。' + } + } + ] + } + ] } ] }