Remove unused variables; add missing docstrings.

This commit is contained in:
Bastian Kleineidam 2010-04-05 09:37:54 +02:00
parent 97901d89d9
commit 3c67f6a6a0
3 changed files with 17 additions and 16 deletions

View File

@ -266,6 +266,7 @@ def find_encoding_program (program, encoding):
def list_formats (): def list_formats ():
"""Print information about available archive formats to stdout."""
for format in ArchiveFormats: for format in ArchiveFormats:
print format, "files:" print format, "files:"
for command in ArchiveCommands: for command in ArchiveCommands:
@ -276,7 +277,6 @@ def list_formats ():
try: try:
program = find_archive_program(format, command) program = find_archive_program(format, command)
print " %8s: %s" % (command, program), print " %8s: %s" % (command, program),
basename = os.path.basename(program)
if format == 'tar': if format == 'tar':
encs = [x for x in ArchiveEncodings if util.find_program(x)] encs = [x for x in ArchiveEncodings if util.find_program(x)]
if encs: if encs:
@ -335,7 +335,6 @@ def move_outdir_orphan (outdir):
Never overwrite files. Never overwrite files.
Return (True, outfile) if successful, (False, reason) if not.""" Return (True, outfile) if successful, (False, reason) if not."""
entries = os.listdir(outdir) entries = os.listdir(outdir)
reason = ""
if len(entries) == 1: if len(entries) == 1:
src = os.path.join(outdir, entries[0]) src = os.path.join(outdir, entries[0])
dst = os.path.join(os.path.dirname(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 return res
def rmtree_error (func, path, exc): def rmtree_log_error (func, path, exc):
"""Error function for shutil.rmtree(). Raises a PatoolError.""" """Error function for shutil.rmtree(). Raises a PatoolError."""
msg = "Error in %s(%s): %s" % (func.__name__, path, str(exc[1])) 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): def _diff_archives (archive1, archive2):
@ -488,8 +487,8 @@ def _diff_archives (archive1, archive2):
path2 = _handle_archive(archive2, 'extract', outdir=tmpdir2) path2 = _handle_archive(archive2, 'extract', outdir=tmpdir2)
return util.run([diff, "-urN", path1, path2]) return util.run([diff, "-urN", path1, path2])
finally: finally:
shutil.rmtree(tmpdir1, onerror=rmtree_error) shutil.rmtree(tmpdir1, onerror=rmtree_log_error)
shutil.rmtree(tmpdir2, onerror=rmtree_error) shutil.rmtree(tmpdir2, onerror=rmtree_log_error)
def _repack_archive (archive1, archive2): def _repack_archive (archive1, archive2):
@ -501,5 +500,6 @@ def _repack_archive (archive1, archive2):
files = tuple(os.listdir(tmpdir)) files = tuple(os.listdir(tmpdir))
os.chdir(tmpdir) os.chdir(tmpdir)
_handle_archive(archive, 'create', *files) _handle_archive(archive, 'create', *files)
return 0
finally: finally:
shutil.rmtree(tmpdir, onerror=rmtree_error) shutil.rmtree(tmpdir, onerror=rmtree_log_error)

View File

@ -40,6 +40,7 @@ def create_tar (archive, encoding, cmd, *args, **kwargs):
return cmdlist return cmdlist
def add_star_opts (cmdlist, encoding, verbose): def add_star_opts (cmdlist, encoding, verbose):
"""Add default options for the star program."""
# Note that star autodetects encoding compression, but displays a warning # Note that star autodetects encoding compression, but displays a warning
# which we want to avoid. # which we want to avoid.
if encoding == 'gzip': if encoding == 'gzip':

View File

@ -123,7 +123,7 @@ Encoding2Mime = {
'lzip': "application/x-lzip", 'lzip': "application/x-lzip",
'xz': "application/x-xz", '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): def guess_mime_mimedb (filename):
@ -164,7 +164,7 @@ def guess_mime_file_mime (file_prog, filename):
cmd = [file_prog, "--brief", "--mime-type", filename] cmd = [file_prog, "--brief", "--mime-type", filename]
try: try:
mime = backtick(cmd).strip() mime = backtick(cmd).strip()
except OSError, msg: except OSError:
# ignore errors, as file(1) is only a fallback # ignore errors, as file(1) is only a fallback
return mime, encoding return mime, encoding
from patoolib import ArchiveMimetypes from patoolib import ArchiveMimetypes
@ -312,7 +312,6 @@ def log_info (msg, out=sys.stderr):
def log_internal_error (out=sys.stderr): def log_internal_error (out=sys.stderr):
"""Print internal error message to stderr.""" """Print internal error message to stderr."""
print >> out, "patool: internal error" print >> out, "patool: internal error"
etype, value = sys.exc_info()[:2]
traceback.print_exc() traceback.print_exc()
print >> out, "System info:" print >> out, "System info:"
print >> out, "Python %s on %s" % (sys.version, sys.platform) print >> out, "Python %s on %s" % (sys.version, sys.platform)
@ -336,7 +335,8 @@ def find_program (program):
def append_to_path (path, directory): 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: if not os.path.isdir(directory) or directory in path:
return path return path
if not path.endswith(os.pathsep): if not path.endswith(os.pathsep):
@ -357,8 +357,8 @@ def get_nt_7z_dir ():
return "" return ""
def strlist_with_or (list): def strlist_with_or (alist):
"""Return comma separated string, and last entry appended with ' or '.""" """Return comma separated string, and last entry appended with ' or '."""
if len(list) > 1: if len(alist) > 1:
return "%s or %s" % (", ".join(list[:-1]), list[-1]) return "%s or %s" % (", ".join(alist[:-1]), alist[-1])
return ", ".join(list) return ", ".join(alist)