summaryrefslogtreecommitdiff
path: root/buildscripts/make_archive.py
diff options
context:
space:
mode:
Diffstat (limited to 'buildscripts/make_archive.py')
-rwxr-xr-xbuildscripts/make_archive.py53
1 files changed, 31 insertions, 22 deletions
diff --git a/buildscripts/make_archive.py b/buildscripts/make_archive.py
index f3537cebc25..a2681a0efdc 100755
--- a/buildscripts/make_archive.py
+++ b/buildscripts/make_archive.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-'''Helper script for constructing an archive (zip or tar) from a list of files.
+"""Helper script for constructing an archive (zip or tar) from a list of files.
The output format (tar, tgz, zip) is determined from the file name, unless the user specifies
--format on the command line.
@@ -10,8 +10,8 @@ directory in the archive, perhaps mongodb-2.0.2/src/mongo.
Usage:
-make_archive.py -o <output-file> [--format (tar|tgz|zip)] \
- [--transform match1=replacement1 [--transform match2=replacement2 [...]]] \
+make_archive.py -o <output-file> [--format (tar|tgz|zip)] \\
+ [--transform match1=replacement1 [--transform match2=replacement2 [...]]] \\
<input file 1> [...]
If the input file names start with "@", the file is expected to contain a list of
@@ -23,7 +23,7 @@ match1, it is never compared against match2 or later. Matches are just python s
comparisons.
For a detailed usage example, see src/SConscript.client or src/mongo/SConscript.
-'''
+"""
import optparse
import os
@@ -36,6 +36,7 @@ from subprocess import (Popen, PIPE, STDOUT)
def main(argv):
+ """Execute Main program."""
args = []
for arg in argv[1:]:
if arg.startswith("@"):
@@ -49,23 +50,24 @@ def main(argv):
opts = parse_options(args)
if opts.archive_format in ('tar', 'tgz'):
make_tar_archive(opts)
- elif opts.archive_format in ('zip'):
+ elif opts.archive_format == 'zip':
make_zip_archive(opts)
else:
raise ValueError('Unsupported archive format "%s"' % opts.archive_format)
-def delete_directory(dir):
- '''Recursively deletes a directory and its contents.
- '''
+def delete_directory(directory):
+ """Recursively deletes a directory and its contents."""
try:
- shutil.rmtree(dir)
- except Exception:
+ shutil.rmtree(directory)
+ except Exception: # pylint: disable=broad-except
pass
def make_tar_archive(opts):
- '''Given the parsed options, generates the 'opt.output_filename'
+ """Generate tar archive.
+
+ Given the parsed options, generates the 'opt.output_filename'
tarball containing all the files in 'opt.input_filename' renamed
according to the mappings in 'opts.transformations'.
@@ -77,9 +79,9 @@ def make_tar_archive(opts):
required by 'opts.transformations'. Once the tarball has been
created, all temporary directory structures created for the
purposes of compressing, are removed.
- '''
+ """
tar_options = "cvf"
- if opts.archive_format is 'tgz':
+ if opts.archive_format == 'tgz':
tar_options += "z"
# clean and create a temp directory to copy files to
@@ -112,13 +114,15 @@ def make_tar_archive(opts):
def make_zip_archive(opts):
- '''Given the parsed options, generates the 'opt.output_filename'
+ """Generate the zip archive.
+
+ Given the parsed options, generates the 'opt.output_filename'
zipfile containing all the files in 'opt.input_filename' renamed
according to the mappings in 'opts.transformations'.
All files in 'opt.output_filename' are renamed before being
written into the zipfile.
- '''
+ """
archive = open_zip_archive_for_write(opts.output_filename)
try:
for input_filename in opts.input_filenames:
@@ -129,6 +133,7 @@ def make_zip_archive(opts):
def parse_options(args):
+ """Parse program options."""
parser = optparse.OptionParser()
parser.add_option('-o', dest='output_filename', default=None,
help='Name of the archive to output.', metavar='FILE')
@@ -166,30 +171,34 @@ def parse_options(args):
xform.replace(os.path.altsep or os.path.sep, os.path.sep).split('=', 1)
for xform in opts.transformations
]
- except Exception, e:
- parser.error(e)
+ except Exception, err: # pylint: disable=broad-except
+ parser.error(err)
return opts
def open_zip_archive_for_write(filename):
- '''Open a zip archive for writing and return it.
- '''
+ """Open a zip archive for writing and return it."""
# Infuriatingly, Zipfile calls the "add" method "write", but they're otherwise identical,
# for our purposes. WrappedZipFile is a minimal adapter class.
class WrappedZipFile(zipfile.ZipFile):
+ """WrappedZipFile class."""
+
def add(self, filename, arcname):
+ """Add filename to zip."""
return self.write(filename, arcname)
return WrappedZipFile(filename, 'w', zipfile.ZIP_DEFLATED)
def get_preferred_filename(input_filename, transformations):
- '''Does a prefix subsitution on 'input_filename' for the
+ """Return preferred filename.
+
+ Perform a prefix subsitution on 'input_filename' for the
first matching transformation in 'transformations' and
- returns the substituted string
- '''
+ returns the substituted string.
+ """
for match, replace in transformations:
match_lower = match.lower()
input_filename_lower = input_filename.lower()