42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import os
|
|
import re
|
|
|
|
def strip_quotes(s):
|
|
"""去掉首尾的引号"""
|
|
s = s.strip()
|
|
if len(s) >= 2 and s[0] == s[-1] and s[0] in ('"', "'"):
|
|
return s[1:-1]
|
|
return s
|
|
|
|
# 测试用例
|
|
test_cases = [
|
|
('"D:\\桌面\\server-icon.png">d:/桌面/源码/1.bmp', 'test'),
|
|
('D:\\桌面\\server-icon.png>.jpg', 'test'),
|
|
('"D:\\桌面\\server-icon.png">.jpg', 'test'),
|
|
]
|
|
|
|
for image_arg, text in test_cases:
|
|
print(f'原始输入: {image_arg!r}')
|
|
|
|
# 第一步:去引号
|
|
image_arg = strip_quotes(image_arg)
|
|
text = strip_quotes(text)
|
|
print(f' 去引号后: {image_arg!r}')
|
|
|
|
# 第二步:分割 >
|
|
output_spec = None
|
|
if '>' in image_arg:
|
|
parts = image_arg.rsplit('>', 1)
|
|
image_arg = parts[0].strip()
|
|
output_spec = parts[1].strip()
|
|
else:
|
|
image_arg = image_arg.strip()
|
|
|
|
# 第三步:再次去引号(关键修复)
|
|
image_arg = strip_quotes(image_arg)
|
|
|
|
print(f' 最终 input_path: {image_arg!r}')
|
|
print(f' 文件存在: {os.path.isfile(image_arg)}')
|
|
print(f' output_spec: {output_spec!r}')
|
|
print()
|