diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2012-07-31 12:52:12 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2012-08-01 13:12:03 +0000 |
commit | 0032ccbd60f202ec76d9b738cddc8bdbf9f54133 (patch) | |
tree | cd398ab063be0bdab20b91cbd2420ad4981de813 /morphlib/bins.py | |
parent | 93a3d28ee51cc301cd79ff8bfabb2010defda09b (diff) | |
download | morph-0032ccbd60f202ec76d9b738cddc8bdbf9f54133.tar.gz |
python scripts: pep8ize codebase
This was done with the aid of the pep8 script, available by running
`easy_install pep8`.
It may be worth making this part of ./check, but that will require
putting pep8 into the development tools stratum.
This should be easy, given pep8 has no external dependencies.
Diffstat (limited to 'morphlib/bins.py')
-rw-r--r-- | morphlib/bins.py | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/morphlib/bins.py b/morphlib/bins.py index 3c6c1bad..ec750db1 100644 --- a/morphlib/bins.py +++ b/morphlib/bins.py @@ -1,14 +1,14 @@ # Copyright (C) 2011-2012 Codethink Limited -# +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -31,24 +31,24 @@ import tarfile def create_chunk(rootdir, f, regexps, dump_memory_profile=None): '''Create a chunk from the contents of a directory. - + Only files and directories that match at least one of the regular expressions are accepted. The regular expressions are implicitly - anchored to the beginning of the string, but not the end. The + anchored to the beginning of the string, but not the end. The filenames are relative to rootdir. - + ``f`` is an open file handle, to which the tar file is written. - + ''' - dump_memory_profile = dump_memory_profile or (lambda msg: None ) - + dump_memory_profile = dump_memory_profile or (lambda msg: None) + # This timestamp is used to normalize the mtime for every file in # chunk artifact. This is useful to avoid problems from smallish # clock skew. It needs to be recent enough, however, that GNU tar # does not complain about an implausibly old timestamp. normalized_timestamp = 683074800 - + def mkrel(filename): assert filename.startswith(rootdir) if filename == rootdir: @@ -65,8 +65,8 @@ def create_chunk(rootdir, f, regexps, dump_memory_profile=None): filename = os.path.dirname(filename) yield filename - logging.debug('Creating chunk file %s from %s with regexps %s' % - (getattr(f, 'name', 'UNNAMED'), rootdir, regexps)) + logging.debug('Creating chunk file %s from %s with regexps %s' % + (getattr(f, 'name', 'UNNAMED'), rootdir, regexps)) dump_memory_profile('at beginning of create_chunk') compiled = [re.compile(x) for x in regexps] @@ -85,7 +85,7 @@ def create_chunk(rootdir, f, regexps, dump_memory_profile=None): logging.debug('regexp MISMATCH: %s' % filename) dump_memory_profile('after walking') - include = sorted(include) # get dirs before contents + include = sorted(include) # get dirs before contents tar = tarfile.open(fileobj=f, mode='w:gz') for filename in include: # Normalize mtime for everything. @@ -109,15 +109,15 @@ def create_chunk(rootdir, f, regexps, dump_memory_profile=None): dump_memory_profile('after removing in create_chunks') -def unpack_binary_from_file(f, dirname): # pragma: no cover +def unpack_binary_from_file(f, dirname): # pragma: no cover '''Unpack a binary into a directory. - + The directory must exist already. - + ''' tf = tarfile.open(fileobj=f) - + # This is evil, but necessary. For some reason Python's system # call wrappers (os.mknod and such) do not (always?) set the # filename attribute of the OSError exception they raise. We @@ -125,34 +125,34 @@ def unpack_binary_from_file(f, dirname): # pragma: no cover # for the relevant methods to add things. The wrapper further # ignores EEXIST errors, since we do not (currently!) care about # overwriting files. - - def follow_symlink(path): # pragma: no cover + + def follow_symlink(path): # pragma: no cover try: return os.stat(path) except OSError: return None - - def prepare_extract(tarinfo, targetpath): # pragma: no cover + + def prepare_extract(tarinfo, targetpath): # pragma: no cover '''Prepare to extract a tar file member onto targetpath? - + If the target already exist, and we can live with it or remove it, we do so. Otherwise, raise an error. - + It's OK to extract if: * the target does not exist - * the member is a directory a directory and the + * the member is a directory a directory and the target is a directory or a symlink to a directory (just extract, no need to remove) * the member is not a directory, and the target is not a directory or a symlink to a directory (remove target, then extract) - + ''' try: existing = os.lstat(targetpath) except OSError: - return True # target does not exist + return True # target does not exist if tarinfo.isdir(): if stat.S_ISDIR(existing.st_mode): @@ -174,7 +174,7 @@ def unpack_binary_from_file(f, dirname): # pragma: no cover return False def monkey_patcher(real): - def make_something(tarinfo, targetpath): # pragma: no cover + def make_something(tarinfo, targetpath): # pragma: no cover prepare_extract(tarinfo, targetpath) try: return real(tarinfo, targetpath) @@ -197,6 +197,7 @@ def unpack_binary_from_file(f, dirname): # pragma: no cover tf.extractall(path=dirname) tf.close + def unpack_binary(filename, dirname): f = open(filename, "rb") unpack_binary_from_file(f, dirname) |