(Python)linux命令unrr出现问题,我一辈子都搞不懂为什么
因此,最近我在这里发了一条帖子,内容是关于需要一个脚本的帮助,该脚本可以自动为我提取(Python)linux命令unrr出现问题,我一辈子都搞不懂为什么,python,linux,unrar,Python,Linux,Unrar,因此,最近我在这里发了一条帖子,内容是关于需要一个脚本的帮助,该脚本可以自动为我提取.rar文件和.zip文件,而无需用户交互。在人们的各种帮助下,我做到了这一点: import os import re from subprocess import check_call from os.path import join rx = '(.*zip$)|(.*rar$)|(.*r00$)' path = "/mnt/externa/Torrents/completed/test" for ro
.rar
文件和.zip
文件,而无需用户交互。在人们的各种帮助下,我做到了这一点:
import os
import re
from subprocess import check_call
from os.path import join
rx = '(.*zip$)|(.*rar$)|(.*r00$)'
path = "/mnt/externa/Torrents/completed/test"
for root, dirs, files in os.walk(path):
if not any(f.endswith(".mkv") for f in files):
found_r = False
for file in files:
pth = join(root, file)
try:
if file.endswith(".zip"):
print("Unzipping ",file, "...")
check_call(["unzip", pth, "-d", root])
found_zip = True
elif not found_r and file.endswith((".rar",".r00")):
check_call(["unrar","e","-o-", pth, root])
found_r = True
break
except ValueError:
print ("OOps! That did not work")
我第一次在.rar文件上运行此脚本时,它工作得非常出色,它会将文件提取到正确的目录中,但如果我再次运行它,它会打印一个错误:
Extracting from /mnt/externa/Torrents/completed/test/A.Film/Subs/A.Film.subs.rar
No files to extract
Traceback (most recent call last):
File "unrarscript.py", line 20, in <module>
check_call(["unrar","e","-o-", pth, root])
File "/usr/lib/python2.7/subprocess.py", line 541, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['unrar', 'e', '-o-', '/mnt/externa/Torrents/completed/test/A.Film/Subs/A.Film.subs.rar', '/mnt/externa/Torrents/completed/test/A.Film/Subs']' returned non-zero exit status 10
从/mnt/externa/Torrents/completed/test/A.Film/Subs/A.Film.Subs.rar中提取
没有要提取的文件
回溯(最近一次呼叫最后一次):
文件“unrarscript.py”,第20行,在
检查调用([“unrr”、“e”、“-o-”、pth、root])
文件“/usr/lib/python2.7/subprocess.py”,第541行,在check_调用中
引发被调用的进程错误(retcode,cmd)
subprocess.CalledProcessError:命令“['unrr'、'e'、'-o-'、'/mnt/externa/Torrents/completed/test/A.Film/Subs/A.Film.Subs.rar'、'/mnt/externa/Torrents/completed/test/A.Film/Subs']”返回非零退出状态10
所以我尝试了Try/exception,但我认为我做得不对,有人能帮我完成这个脚本吗?当UNAR返回一个不同于零的错误代码时,
check\u调用
引发CalledProcessError
异常
您的错误消息显示:
返回非零退出状态10
Rar.txt
包含以下错误代码列表:(可在WinRAR安装文件夹中找到)
我看到您在试图覆盖文件时使用-o-
来“跳过现有文件”。如果打包文件已经存在,将返回错误代码10。如果立即重新运行脚本,则引发此错误是正常的
C:\>unrar e -o- testfile.rar
UNRAR 5.30 freeware Copyright (c) 1993-2015 Alexander Roshal
Extracting from testfile.rar
No files to extract
C:\>echo %errorlevel%
10
您可能可以这样做来处理它:
except CalledProcessError as cpe:
if cpe.returncode == 10:
print("File not overwritten")
else:
print("Some other error")
我看到你试图提取vobsubs。vobubs rar中的.sub rar也很有可能具有相同的文件名。当UNAR返回不同于零的错误代码时,
检查调用
引发被调用的进程错误
异常
您的错误消息显示:
返回非零退出状态10
Rar.txt
包含以下错误代码列表:(可在WinRAR安装文件夹中找到)
我看到您在试图覆盖文件时使用-o-
来“跳过现有文件”。如果打包文件已经存在,将返回错误代码10。如果立即重新运行脚本,则引发此错误是正常的
C:\>unrar e -o- testfile.rar
UNRAR 5.30 freeware Copyright (c) 1993-2015 Alexander Roshal
Extracting from testfile.rar
No files to extract
C:\>echo %errorlevel%
10
您可能可以这样做来处理它:
except CalledProcessError as cpe:
if cpe.returncode == 10:
print("File not overwritten")
else:
print("Some other error")
我看到你试图提取vobsubs。vobubs rar中的.sub rar也有可能具有相同的文件名。文件是否存在?“没有要提取的文件”似乎unrar找不到是的,文件在那里。文件在那里吗?“没有要提取的文件”似乎unrar找不到它是的,文件在那里。