@@ -44,22 +44,17 @@ def log(self, msg, topic=None):
4444 msg = msg
4545 )
4646
47- def require_true (self , case : Any , msg : str , is_param_validation = True ):
47+ def require_param (self , case : Any , msg : str ):
4848 """
49- 独立于ExceptionTool的一套异常抛出体系
50-
49+ 专门用于校验参数的方法,会抛出特定异常,由option拦截根据策略进行处理
5150
5251 :param case: 条件
5352 :param msg: 报错信息
54- :param is_param_validation: True 表示 调用本方法是用于校验参数,则会抛出特定异常(PluginValidationException)
5553 """
5654 if case :
5755 return
5856
59- if is_param_validation :
60- raise PluginValidationException (self , msg )
61- else :
62- ExceptionTool .raises (msg )
57+ raise PluginValidationException (self , msg )
6358
6459 def warning_lib_not_install (self , lib : str ):
6560 msg = (f'插件`{ self .plugin_key } `依赖库: { lib } ,请先安装{ lib } 再使用。'
@@ -94,6 +89,11 @@ def execute_cmd(self, cmd):
9489 """
9590 return os .system (cmd )
9691
92+ # noinspection PyMethodMayBeStatic
93+ def execute_multi_line_cmd (self , cmd : str ):
94+ import subprocess
95+ subprocess .run (cmd , shell = True , check = True )
96+
9797
9898class JmLoginPlugin (JmOptionPlugin ):
9999 """
@@ -106,10 +106,10 @@ def invoke(self,
106106 password : str ,
107107 impl = None ,
108108 ) -> None :
109- self .require_true (username , '用户名不能为空' )
110- self .require_true (password , '密码不能为空' )
109+ self .require_param (username , '用户名不能为空' )
110+ self .require_param (password , '密码不能为空' )
111111
112- client = self .option .new_jm_client (impl = impl )
112+ client = self .option .build_jm_client (impl = impl )
113113 client .login (username , password )
114114
115115 cookies = dict (client ['cookies' ])
@@ -459,7 +459,7 @@ def invoke(self,
459459 album = None ,
460460 downloader = None ,
461461 ) -> None :
462- self .require_true (msg_from and msg_to and password , '发件人、收件人、授权码都不能为空' )
462+ self .require_param (msg_from and msg_to and password , '发件人、收件人、授权码都不能为空' )
463463
464464 from common import EmailConfig
465465 econfig = EmailConfig (msg_from , msg_to , password )
@@ -551,7 +551,7 @@ def invoke(self,
551551 zip_password = None ,
552552 delete_original_file = False ,
553553 ):
554- self .save_dir = os .path .abspath (save_dir if save_dir is not None else os .getcwd () + '/export/' )
554+ self .save_dir = os .path .abspath (save_dir if save_dir is not None else ( os .getcwd () + '/export/' ) )
555555 self .zip_enable = zip_enable
556556 self .zip_filepath = os .path .abspath (zip_filepath )
557557 self .zip_password = zip_password
@@ -564,7 +564,7 @@ def invoke(self,
564564 self .main ()
565565
566566 def main (self ):
567- cl = self .option .new_jm_client ( impl = JmApiClient )
567+ cl = self .option .build_jm_client ( )
568568 # noinspection PyAttributeOutsideInit
569569 self .cl = cl
570570 page = cl .favorite_folder ()
@@ -584,7 +584,7 @@ def main(self):
584584 return
585585
586586 # 压缩导出的文件
587- self .require_true (self .zip_filepath , '如果开启zip,请指定zip_filepath参数(压缩文件保存路径)' )
587+ self .require_param (self .zip_filepath , '如果开启zip,请指定zip_filepath参数(压缩文件保存路径)' )
588588
589589 if self .zip_password is None :
590590 self .zip_folder_without_password (self .files , self .zip_filepath )
@@ -650,12 +650,16 @@ def zip_folder_without_password(self, files, zip_path):
650650 zipf .write (file , arcname = of_file_name (file ))
651651
652652 def zip_with_password (self ):
653- os .chdir (self .save_dir )
654- cmd = f'7z a "{ self .zip_filepath } " "{ self .save_dir } " -p{ self .zip_password } -mhe=on'
655- self .require_true (
656- 0 == self .execute_cmd (cmd ),
657- '加密压缩文件失败'
658- )
653+ # 构造shell命令
654+ cmd_list = f'''
655+ cd { self .save_dir }
656+ 7z a "{ self .zip_filepath } " "./" -p{ self .zip_password } -mhe=on > "../7z_output.txt"
657+
658+ '''
659+ self .log (f'运行命令: { cmd_list } ' )
660+
661+ # 执行
662+ self .execute_multi_line_cmd (cmd_list )
659663
660664
661665class ConvertJpgToPdfPlugin (JmOptionPlugin ):
@@ -726,11 +730,10 @@ def generate_cmd():
726730 self .log (f'Execute Command: [{ cmd } ]' )
727731 code = self .execute_cmd (cmd )
728732
729- self .require_true (
733+ ExceptionTool .require_true (
730734 code == 0 ,
731735 'jpg图片合并为pdf失败!'
732736 '请确认你是否安装了magick,安装网站: [http://www.imagemagick.org/]' ,
733- False ,
734737 )
735738
736739 self .log (f'Convert Successfully: JM{ photo .id } → { pdf_filepath } ' )
0 commit comments