summaryrefslogtreecommitdiff
path: root/morphlib/bins.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-10-09 09:54:24 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-10-09 13:12:39 +0000
commit9a906c35aefe1e4a6d7ea9b4fb0ca6233728f497 (patch)
tree19529f9d43c71fe90f2c71dcee6f7c6d77ae8aa0 /morphlib/bins.py
parentd723fa5efdd546ac823f97a0fe3f346510fe43d4 (diff)
downloadmorph-9a906c35aefe1e4a6d7ea9b4fb0ca6233728f497.tar.gz
Use standard library function for relative paths
os.path.relpath does approximately the same as mkrel, with the exception of asserting.
Diffstat (limited to 'morphlib/bins.py')
-rw-r--r--morphlib/bins.py12
1 files changed, 3 insertions, 9 deletions
diff --git a/morphlib/bins.py b/morphlib/bins.py
index 00b0c2fc..71483172 100644
--- a/morphlib/bins.py
+++ b/morphlib/bins.py
@@ -49,13 +49,6 @@ def create_chunk(rootdir, f, regexps, dump_memory_profile=None):
# does not complain about an implausibly old timestamp.
normalized_timestamp = 683074800
- def mkrel(filename):
- assert filename.startswith(rootdir)
- if filename == rootdir:
- return '.'
- assert filename.startswith(rootdir + '/')
- return filename[len(rootdir + '/'):]
-
def matches(filename):
return any(x.match(filename) for x in compiled)
@@ -76,7 +69,7 @@ def create_chunk(rootdir, f, regexps, dump_memory_profile=None):
subdirsymlinks = [x for x in subdirpaths if os.path.islink(x)]
filenames = [os.path.join(dirname, x) for x in basenames]
for filename in [dirname] + subdirsymlinks + filenames:
- if matches(mkrel(filename)):
+ if matches(os.path.relpath(filename, rootdir)):
for name in names_to_root(filename):
if name not in include:
logging.debug('regexp match: %s' % name)
@@ -89,7 +82,8 @@ def create_chunk(rootdir, f, regexps, dump_memory_profile=None):
tar = tarfile.open(fileobj=f, mode='w:gz')
for filename in include:
# Normalize mtime for everything.
- tarinfo = tar.gettarinfo(filename, arcname=mkrel(filename))
+ tarinfo = tar.gettarinfo(filename,
+ arcname=os.path.relpath(filename, rootdir))
tarinfo.ctime = normalized_timestamp
tarinfo.mtime = normalized_timestamp
if tarinfo.isreg():