Skip to content

Commit

Permalink
简单构建输出信息分离与记录,文件处理信息输入log.txt文件,结果信息输入result.txt。查阅result.txt内容,对照log…
Browse files Browse the repository at this point in the history
….txt检查epub文件错误或程序错误。
  • Loading branch information
cnwxi committed Aug 28, 2024
1 parent aec31cf commit bdf68dc
Show file tree
Hide file tree
Showing 9 changed files with 1,312 additions and 992 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
version:
description: 'Release version'
required: true
default: '2024.08.28.v2'
default: '2024.08.28.v1'
body:
description: 'Release body text'
required: true
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build
dist
test
epub_tool.spec
epub_tool.spec
log.txt
result.txt
67 changes: 40 additions & 27 deletions epub_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,69 @@


def prepare_args():
parser = argparse.ArgumentParser(description='Epub Tool')
parser.add_argument('-i', help='input file/folder')
parser.add_argument('-e', action='store_true', help='encrypt epub file')
parser.add_argument('-d', action='store_true', help='decrypt epub file')
parser.add_argument('-r', action='store_true', help='reformat epub file')
parser = argparse.ArgumentParser(description="Epub Tool")
parser.add_argument("-i", help="input file/folder")
parser.add_argument("-e", action="store_true", help="encrypt epub file")
parser.add_argument("-d", action="store_true", help="decrypt epub file")
parser.add_argument("-r", action="store_true", help="reformat epub file")
return parser.parse_args()


def check_args(args):
if not args.i:
print('Please specify the input file/folder')
print("Please specify the input file/folder")
sys.exit(1)
# 判断输入文件是否为文件夹
if os.path.isdir(args.i):
file_list = []
for root, dirs, files in os.walk(args.i):
for file in files:
if file.endswith('.epub'):
if file.endswith(".epub"):
file_list.append(os.path.join(root, file))
args.i = file_list
else:
args.i = [args.i]
for i in args.i:
if not os.path.exists(i):
print('Input file does not exist')
print("Input file does not exist")
sys.exit(1)
return args


def main():
prepare_args()
args = prepare_args()
args = check_args(args)
if args.e:
func=encrypt_run
elif args.d:
func=decrypt_run
elif args.r:
func=reformat_run
else:
print('Please specify the operation')
sys.exit(1)
tmp_run_result = []
for file in args.i:
if func(file) == 0:
tmp_run_result.append(f'{file} Success')
log_file = "log.txt"
with open(log_file, "w",encoding='utf-8') as f:
sys.stdout = f
args = prepare_args()

args = check_args(args)

if args.e:
func = encrypt_run
elif args.d:
func = decrypt_run
elif args.r:
func = reformat_run
else:
tmp_run_result.append(f'{file} Fail')
print('\nResult:')
print("Please specify the operation")
sys.exit(1)
tmp_run_result = []
for file in args.i:
try:
func(file)
except Exception as e:
tmp_run_result.append(f"process {file} Fail: {e}")
else:
tmp_run_result.append(f"process {file} Success")
sys.stdout = sys.__stdout__
print("Result:")
for result in tmp_run_result:
print(result)
with open("result.txt", "w",encoding='utf-8') as f:
for result in tmp_run_result:
f.write(result + "\n")


if __name__ == '__main__':
main()
if __name__ == "__main__":
main()
Binary file modified utils/__pycache__/decrypt_epub.cpython-312.pyc
Binary file not shown.
Binary file modified utils/__pycache__/encrypt_epub.cpython-312.pyc
Binary file not shown.
Binary file modified utils/__pycache__/reformat_epub.cpython-312.pyc
Binary file not shown.
Loading

0 comments on commit bdf68dc

Please sign in to comment.