summaryrefslogtreecommitdiff
path: root/morphlib/builder.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-03-01 15:02:16 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-03-02 17:13:29 +0000
commit697e822049919139781a1d393068ab237c7ed441 (patch)
tree95f4ff1d33593dc3bee043919428f9db5b577bc7 /morphlib/builder.py
parent4ce8550592aea90db883a199de9264e279c4dda2 (diff)
downloadmorph-697e822049919139781a1d393068ab237c7ed441.tar.gz
Simplify how files are created in the cache directory
The "cache prefix" concept is not immediately clear, and it's generally speaking best to centralize the construction of filenames in the cache to the CacheDir class anyway. Also, use SaveFile for writing the log file, instead of writing it to a temporary file and then copying, which is unnecessary I/O.
Diffstat (limited to 'morphlib/builder.py')
-rw-r--r--morphlib/builder.py17
1 files changed, 6 insertions, 11 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py
index ed7b4378..d1a7fbde 100644
--- a/morphlib/builder.py
+++ b/morphlib/builder.py
@@ -154,8 +154,7 @@ class BlobBuilder(object): # pragma: no cover
self.settings = None
self.real_msg = None
self.cachedir = None
- self.cache_basename = None
- self.cache_prefix = None
+ self.cache_key = None
self.tempdir = None
self.factory = None
self.logfile = None
@@ -184,7 +183,7 @@ class BlobBuilder(object): # pragma: no cover
return builds.items()
def filename(self, name):
- return '%s.%s.%s' % (self.cache_prefix,
+ return '%s.%s.%s' % (self.cachedir.name(self.cache_key),
self.blob.morph.kind,
name)
@@ -211,7 +210,7 @@ class BlobBuilder(object): # pragma: no cover
def write_cache_metadata(self, meta):
self.msg('Writing metadata to the cache')
- with self.cachedir.open(self.cache_basename + '.meta') as f:
+ with self.cachedir.open(self.cache_key, suffix='.meta') as f:
json.dump(meta, f, indent=4)
f.write('\n')
@@ -228,14 +227,11 @@ class BlobBuilder(object): # pragma: no cover
self.write_cache_metadata(meta)
def prepare_logfile(self):
- filename = self.tempdir.join('%s.log' % self.blob.morph.name)
- self.logfile = open(filename, 'w+', 0)
+ self.logfile = self.cachedir.open(self.cache_key, suffix='.log',
+ mode='w+', buffering=0)
def save_logfile(self):
self.logfile.close()
- filename = '%s.log' % self.cache_prefix
- self.msg('Saving build log to %s' % filename)
- shutil.copyfile(self.logfile.name, filename)
class ChunkBuilder(BlobBuilder): # pragma: no cover
@@ -761,8 +757,7 @@ class Builder(object): # pragma: no cover
builder.settings = self.settings
builder.real_msg = self.msg
builder.cachedir = self.cachedir
- builder.cache_prefix = self.cachedir.name(cache_id)
- builder.cache_basename = os.path.basename(builder.cache_prefix)
+ builder.cache_key = cache_id
builder.tempdir = self.tempdir
builder.factory = self.factory
builder.dump_memory_profile = self.dump_memory_profile