Remove unused variables; add missing docstrings.
This commit is contained in:
parent
97901d89d9
commit
3c67f6a6a0
|
@ -266,6 +266,7 @@ def find_encoding_program (program, encoding):
|
|||
|
||||
|
||||
def list_formats ():
|
||||
"""Print information about available archive formats to stdout."""
|
||||
for format in ArchiveFormats:
|
||||
print format, "files:"
|
||||
for command in ArchiveCommands:
|
||||
|
@ -276,7 +277,6 @@ def list_formats ():
|
|||
try:
|
||||
program = find_archive_program(format, command)
|
||||
print " %8s: %s" % (command, program),
|
||||
basename = os.path.basename(program)
|
||||
if format == 'tar':
|
||||
encs = [x for x in ArchiveEncodings if util.find_program(x)]
|
||||
if encs:
|
||||
|
@ -324,7 +324,7 @@ def parse_config (archive, format, encoding, command, **kwargs):
|
|||
config[key] = value
|
||||
program = os.path.basename(config['program'])
|
||||
if encoding and not find_encoding_program(program, encoding):
|
||||
msg = "cannot %s archive `%s': encoding `%s' not supported by %s" %\
|
||||
msg = "cannot %s archive `%s': encoding `%s' not supported by %s" % \
|
||||
(command, archive, encoding, program)
|
||||
raise util.PatoolError(msg)
|
||||
return config
|
||||
|
@ -335,7 +335,6 @@ def move_outdir_orphan (outdir):
|
|||
Never overwrite files.
|
||||
Return (True, outfile) if successful, (False, reason) if not."""
|
||||
entries = os.listdir(outdir)
|
||||
reason = ""
|
||||
if len(entries) == 1:
|
||||
src = os.path.join(outdir, entries[0])
|
||||
dst = os.path.join(os.path.dirname(outdir), entries[0])
|
||||
|
@ -470,10 +469,10 @@ def handle_archive (archive, command, *args, **kwargs):
|
|||
return res
|
||||
|
||||
|
||||
def rmtree_error (func, path, exc):
|
||||
def rmtree_log_error (func, path, exc):
|
||||
"""Error function for shutil.rmtree(). Raises a PatoolError."""
|
||||
msg = "Error in %s(%s): %s" % (func.__name__, path, str(exc[1]))
|
||||
raise util.PatoolError(msg)
|
||||
util.log_error(msg)
|
||||
|
||||
|
||||
def _diff_archives (archive1, archive2):
|
||||
|
@ -488,8 +487,8 @@ def _diff_archives (archive1, archive2):
|
|||
path2 = _handle_archive(archive2, 'extract', outdir=tmpdir2)
|
||||
return util.run([diff, "-urN", path1, path2])
|
||||
finally:
|
||||
shutil.rmtree(tmpdir1, onerror=rmtree_error)
|
||||
shutil.rmtree(tmpdir2, onerror=rmtree_error)
|
||||
shutil.rmtree(tmpdir1, onerror=rmtree_log_error)
|
||||
shutil.rmtree(tmpdir2, onerror=rmtree_log_error)
|
||||
|
||||
|
||||
def _repack_archive (archive1, archive2):
|
||||
|
@ -501,5 +500,6 @@ def _repack_archive (archive1, archive2):
|
|||
files = tuple(os.listdir(tmpdir))
|
||||
os.chdir(tmpdir)
|
||||
_handle_archive(archive, 'create', *files)
|
||||
return 0
|
||||
finally:
|
||||
shutil.rmtree(tmpdir, onerror=rmtree_error)
|
||||
shutil.rmtree(tmpdir, onerror=rmtree_log_error)
|
||||
|
|
|
@ -40,6 +40,7 @@ def create_tar (archive, encoding, cmd, *args, **kwargs):
|
|||
return cmdlist
|
||||
|
||||
def add_star_opts (cmdlist, encoding, verbose):
|
||||
"""Add default options for the star program."""
|
||||
# Note that star autodetects encoding compression, but displays a warning
|
||||
# which we want to avoid.
|
||||
if encoding == 'gzip':
|
||||
|
|
|
@ -123,7 +123,7 @@ Encoding2Mime = {
|
|||
'lzip': "application/x-lzip",
|
||||
'xz': "application/x-xz",
|
||||
}
|
||||
Mime2Encoding = dict([(value, key) for key, value in Encoding2Mime.items()])
|
||||
Mime2Encoding = dict([(_val, _key) for _key, _val in Encoding2Mime.items()])
|
||||
|
||||
|
||||
def guess_mime_mimedb (filename):
|
||||
|
@ -164,7 +164,7 @@ def guess_mime_file_mime (file_prog, filename):
|
|||
cmd = [file_prog, "--brief", "--mime-type", filename]
|
||||
try:
|
||||
mime = backtick(cmd).strip()
|
||||
except OSError, msg:
|
||||
except OSError:
|
||||
# ignore errors, as file(1) is only a fallback
|
||||
return mime, encoding
|
||||
from patoolib import ArchiveMimetypes
|
||||
|
@ -312,7 +312,6 @@ def log_info (msg, out=sys.stderr):
|
|||
def log_internal_error (out=sys.stderr):
|
||||
"""Print internal error message to stderr."""
|
||||
print >> out, "patool: internal error"
|
||||
etype, value = sys.exc_info()[:2]
|
||||
traceback.print_exc()
|
||||
print >> out, "System info:"
|
||||
print >> out, "Python %s on %s" % (sys.version, sys.platform)
|
||||
|
@ -336,7 +335,8 @@ def find_program (program):
|
|||
|
||||
|
||||
def append_to_path (path, directory):
|
||||
"""Add a directory to the PATH env variable, if it is a valid directory."""
|
||||
"""Add a directory to the PATH environment variable, if it is a valid
|
||||
directory."""
|
||||
if not os.path.isdir(directory) or directory in path:
|
||||
return path
|
||||
if not path.endswith(os.pathsep):
|
||||
|
@ -357,8 +357,8 @@ def get_nt_7z_dir ():
|
|||
return ""
|
||||
|
||||
|
||||
def strlist_with_or (list):
|
||||
def strlist_with_or (alist):
|
||||
"""Return comma separated string, and last entry appended with ' or '."""
|
||||
if len(list) > 1:
|
||||
return "%s or %s" % (", ".join(list[:-1]), list[-1])
|
||||
return ", ".join(list)
|
||||
if len(alist) > 1:
|
||||
return "%s or %s" % (", ".join(alist[:-1]), alist[-1])
|
||||
return ", ".join(alist)
|
||||
|
|
Loading…
Reference in New Issue