Check that archive exists before handling it.

This commit is contained in:
Bastian Kleineidam 2010-03-06 14:38:51 +01:00
parent 0ad54e0f0f
commit 9ee4f65b90
1 changed files with 11 additions and 5 deletions

16
patool
View File

@ -20,6 +20,7 @@ patool [extract|list|create|formats] [sub-command-options] <command-args>
import sys
if not hasattr(sys, "version_info") or sys.version_info < (2, 4, 0, "final", 0):
raise SystemExit("This program requires Python 2.4 or later.")
import os
from patoolib import handle_archive, list_formats, baker
# parameter help and short options
@ -32,11 +33,16 @@ shortopts = {"verbose": "v"}
def handle_multi_archive(archives, cmd, **kwargs):
"""Handle a multi-archive command."""
res = 0
for archive in archives:
newres = handle_archive(archive, cmd, **kwargs)
# return error if one of the archives could not be extracted
if newres:
res = newres
archives = [x for x in archives if os.path.exists(x)]
if archives:
for archive in archives:
newres = handle_archive(archive, cmd, **kwargs)
# return error if one of the archives could not be extracted
if newres:
res = newres
else:
print >>sys.stderr, "patool error: none of the given archive files exist"
res = 1
return res