summaryrefslogtreecommitdiff
path: root/morphlib/morphologyfactory.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-04-20 10:12:56 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-04-20 11:25:03 +0000
commitb75fec924f2082d5a5a13421ecec0e866e3c011c (patch)
tree8be007c4de78674cbb3223ec2c4a637fe753885a /morphlib/morphologyfactory.py
parent9ee4e4c57624cfee21d3bcc132f780bff04a59c4 (diff)
downloadmorph-b75fec924f2082d5a5a13421ecec0e866e3c011c.tar.gz
morphologyfactory: work without RemoteRepoCache
There are cases where we would not need a remote cache, so it should be able to operate without one.
Diffstat (limited to 'morphlib/morphologyfactory.py')
-rw-r--r--morphlib/morphologyfactory.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py
index 5e3bf7f2..e7ee9323 100644
--- a/morphlib/morphologyfactory.py
+++ b/morphlib/morphologyfactory.py
@@ -27,10 +27,16 @@ class AutodetectError(MorphologyFactoryError):
"Failed to determine the build system of repo %s at "
"ref %s" % (repo_name, ref))
+class NotcachedError(MorphologyFactoryError):
+ def __init__(self, repo_name):
+ MorphologyFactoryError.__init__(self,
+ "Repository %s is not cached locally and there is no "
+ "remote cache specified" % repo_name)
+
class MorphologyFactory(object):
'''An way of creating morphologies which will provide a default'''
- def __init__(self, local_repo_cache, remote_repo_cache):
+ def __init__(self, local_repo_cache, remote_repo_cache=None):
self._lrc = local_repo_cache
self._rrc = remote_repo_cache
@@ -45,18 +51,27 @@ class MorphologyFactory(object):
if self._lrc.has_repo(reponame):
repo = self._lrc.get_repo(reponame)
return repo.cat(sha1, filename)
- else:
+ elif self._rrc is not None:
return self._rrc.cat_file(reponame, sha1, filename)
+ else:
+ raise NotcachedError(reponame)
def _autodetect_text(self, reponame, sha1, filename):
if self._lrc.has_repo(reponame):
repo = self._lrc.get_repo(reponame)
files = repo.list_files(sha1)
- else:
+ elif self._rrc is not None:
files = self._rrc.list_files(reponame, sha1)
+ else:
+ raise NotcachedError(reponame)
bs = morphlib.buildsystem.detect_build_system(lambda x: x in files)
if bs is None:
raise AutodetectError(reponame, sha1)
+ # TODO consider changing how morphs are located to be by morph
+ # name rather than filename, it would save creating a
+ # filename only to strip it back to its morph name again
+ # and would allow future changes like morphologies being
+ # stored as git metadata instead of as a file in the repo
assert filename.endswith('.morph')
morph_name = filename[:-len('.morph')]
morph_text = bs.get_morphology_text(morph_name)