@@ -243,6 +243,30 @@ def install_plugin(self, repo:str):
243243 logger .error ("Failed to install plugin, {}" .format (e ))
244244 return False , "安装插件失败," + str (e )
245245
246+ def update_plugin (self , name :str ):
247+ try :
248+ import common .package_manager as pkgmgr
249+ pkgmgr .check_dulwich ()
250+ except Exception as e :
251+ logger .error ("Failed to install plugin, {}" .format (e ))
252+ return False , "无法导入dulwich,更新插件失败"
253+ from dulwich import porcelain
254+ name = name .upper ()
255+ if name not in self .plugins :
256+ return False , "插件不存在"
257+ if name in ["HELLO" ,"GODCMD" ,"ROLE" ,"TOOL" ,"BDUNIT" ,"BANWORDS" ,"FINISH" ,"DUNGEON" ]:
258+ return False , "预置插件无法更新,请更新主程序仓库"
259+ dirname = self .plugins [name ].path
260+ try :
261+ porcelain .pull (dirname , "origin" )
262+ if os .path .exists (os .path .join (dirname ,"requirements.txt" )):
263+ logger .info ("detect requirements.txt,installing..." )
264+ pkgmgr .install_requirements (os .path .join (dirname ,"requirements.txt" ))
265+ return True , "更新插件成功,请重新运行程序"
266+ except Exception as e :
267+ logger .error ("Failed to update plugin, {}" .format (e ))
268+ return False , "更新插件失败," + str (e )
269+
246270 def uninstall_plugin (self , name :str ):
247271 name = name .upper ()
248272 if name not in self .plugins :
0 commit comments