Skip to content

Commit

Permalink
Simplify string formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kentzo committed Aug 4, 2015
1 parent 0c3b93d commit a0758bd
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions git-archive-all
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class GitArchiver(object):
try:
self.run_shell("[ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1", main_repo_abspath)
except Exception as e:
raise ValueError("Not a git repository (or any of the parent directories).".format(path=main_repo_abspath))
raise ValueError("Not a git repository (or any of the parent directories).")

main_repo_abspath = path.abspath(self.read_git_shell('git rev-parse --show-toplevel', main_repo_abspath).rstrip())

Expand Down Expand Up @@ -94,7 +94,7 @@ class GitArchiver(object):
if output_format is None:
file_name, file_ext = path.splitext(output_path)
output_format = file_ext[len(extsep):].lower()
self.LOG.debug("Output format is not explicitly set, determined format is {0}.".format(output_format))
self.LOG.debug("Output format is not explicitly set, determined format is {}.".format(output_format))

if not dry_run:
if output_format == 'zip':
Expand All @@ -116,19 +116,19 @@ class GitArchiver(object):
elif output_format == 'txz':
t_mode = 'w:xz'
else:
t_mode = 'w:{0}'.format(output_format)
t_mode = 'w:{}'.format(output_format)

archive = tarfile.open(path.abspath(output_path), t_mode)
add_file = lambda file_path, arcname: archive.add(file_path, arcname)
else:
raise RuntimeError("Unknown format: {0}".format(output_format))
raise RuntimeError("Unknown format: {}".format(output_format))

def archiver(file_path, arcname):
self.LOG.debug("Compressing {0} => {1}...".format(file_path, arcname))
self.LOG.debug("Compressing {} => {}...".format(file_path, arcname))
add_file(file_path, arcname)
else:
archive = None
archiver = lambda file_path, arcname: self.LOG.info("{0} => {1}".format(file_path, arcname))
archiver = lambda file_path, arcname: self.LOG.info("{} => {}".format(file_path, arcname))

self.archive_all_files(archiver)

Expand Down Expand Up @@ -225,7 +225,7 @@ class GitArchiver(object):
patterns = exclude_patterns[key]
for p in patterns:
if fnmatch(file_name, p) or fnmatch(repo_file_path, p):
self.LOG.debug("Exclude pattern matched {pattern}: {path}".format(pattern=p, path=repo_file_path))
self.LOG.debug("Exclude pattern matched {}: {}".format(p, repo_file_path))
is_excluded = True

if not len(components):
Expand Down Expand Up @@ -322,7 +322,7 @@ class GitArchiver(object):
raise ValueError("abspath MUST be absoulte path.")

if not path.commonprefix([repo_abspath, abspath]):
raise ValueError("abspath (\"{0}\") MUST have common prefix with repo_abspath (\"{1}\")".format(abspath, repo_abspath))
raise ValueError("abspath (\"{}\") MUST have common prefix with repo_abspath (\"{}\")".format(abspath, repo_abspath))

components = []

Expand Down Expand Up @@ -423,7 +423,7 @@ if __name__ == '__main__':
from optparse import OptionParser

parser = OptionParser(usage="usage: %prog [-v] [--prefix PREFIX] [--no-exclude] [--force-submodules] [--extra EXTRA1 [EXTRA2]] [--dry-run] OUTPUT_FILE",
version="%prog {version}".format(version=__version__))
version="%prog {}".format(__version__))

parser.add_option('--prefix',
type='string',
Expand Down Expand Up @@ -489,6 +489,6 @@ if __name__ == '__main__':
options.extra)
archiver.create(output_file_path, options.dry_run)
except Exception as e:
parser.exit(2, "{0}\n".format(e))
parser.exit(2, "{}\n".format(e))

sys.exit(0)

0 comments on commit a0758bd

Please sign in to comment.