summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-10-17 21:15:51 +0100
committerLars Wirzenius <liw@liw.fi>2011-10-17 21:15:51 +0100
commite8c7864240d0707d3c6d937ff8a3aad3d3e30305 (patch)
tree4613e4c46a3c8428f69120a1641170b0ff7e01a3
parenta7d16bcc787fbce9e6ef431dead91a54bf8a50ca (diff)
downloadmorph-e8c7864240d0707d3c6d937ff8a3aad3d3e30305.tar.gz
Move code to get morphology text from git into morphlib.git.
-rw-r--r--morphlib/builder.py51
-rw-r--r--morphlib/git.py38
2 files changed, 47 insertions, 42 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py
index b697337b..c6a6bb69 100644
--- a/morphlib/builder.py
+++ b/morphlib/builder.py
@@ -25,22 +25,6 @@ import urlparse
import morphlib
-class NoMorphs(Exception):
-
- def __init__(self, repo, ref):
- Exception.__init__(self,
- 'Cannot find any morpologies at %s:%s' %
- (repo, ref))
-
-
-class TooManyMorphs(Exception):
-
- def __init__(self, repo, ref, morphs):
- Exception.__init__(self,
- 'Too many morphologies at %s:%s: %s' %
- (repo, ref, ', '.join(morphs)))
-
-
class Builder(object):
'''Build binary objects for Baserock.
@@ -176,31 +160,6 @@ class Builder(object):
}
return self.cachedir.name(dict_key)
- def get_morph_from_git(self, repo, ref):
- '''Return a morphology from a git repository.'''
- # FIXME: This implementation assume a local repo.
-
- path = self.get_repo_dir(repo)
- ex = morphlib.execute.Execute(path, self.msg)
- out = ex.runv(['git', 'ls-tree', '--name-only', '-z', ref])
- names = [x for x in out.split('\0') if x]
- morphs = [x for x in names if x.endswith('.morph')]
- if len(morphs) == 0:
- raise NoMorphs(repo, ref)
- if len(morphs) > 1:
- raise TooManyMorphs(repo, ref, morphs)
- out = ex.runv(['git', 'cat-file', 'blob', '%s:%s' % (ref, morphs[0])])
-
- f = StringIO.StringIO(out)
- f.name = morphs[0]
- morph = morphlib.morphology.Morphology(f,
- self.settings['git-base-url'])
- return morph
-
- def get_repo_dir(self, repo):
- scheme, netlock, path, params, query, frag = urlparse.urlparse(repo)
- return path
-
def prepare_binary_metadata(self, morph, **kwargs):
'''Add metadata to a binary about to be built.'''
@@ -220,6 +179,16 @@ class Builder(object):
json.dump(meta, f, indent=4)
f.write('\n')
+
+ def get_morph_from_git(self, repo, ref):
+ morph_name, morph_text = morphlib.git.get_morph_text(repo, ref)
+ f = StringIO.StringIO(morph_text)
+ f.name = morph_name
+ morph = morphlib.morphology.Morphology(f,
+ self.settings['git-base-url'])
+ return morph
+
+
def build_system(self, morph):
'''Build a system image.'''
diff --git a/morphlib/git.py b/morphlib/git.py
index f3403e2b..69f8752e 100644
--- a/morphlib/git.py
+++ b/morphlib/git.py
@@ -21,6 +21,22 @@ import urlparse
import morphlib
+class NoMorphs(Exception):
+
+ def __init__(self, repo, ref):
+ Exception.__init__(self,
+ 'Cannot find any morpologies at %s:%s' %
+ (repo, ref))
+
+
+class TooManyMorphs(Exception):
+
+ def __init__(self, repo, ref, morphs):
+ Exception.__init__(self,
+ 'Too many morphologies at %s:%s: %s' %
+ (repo, ref, ', '.join(morphs)))
+
+
def export_sources(repo, ref, tar_filename):
'''Export the contents of a specific commit into a compressed tarball.'''
ex = morphlib.execute.Execute('.', msg=logging.debug)
@@ -32,7 +48,7 @@ def export_sources(repo, ref, tar_filename):
def get_commit_id(repo, ref):
'''Return the full SHA-1 commit id for a repo+ref.'''
- # FIXME: This assume repo is a file:/// URL.
+ # FIXME: This assumes repo is a file:/// URL.
scheme, netlock, path, params, query, frag = urlparse.urlparse(repo)
assert scheme == 'file'
@@ -40,3 +56,23 @@ def get_commit_id(repo, ref):
out = ex.runv(['git', 'rev-list', '-n1', ref])
return out.strip()
+
+def get_morph_text(repo, ref):
+ '''Return a morphology from a git repository.'''
+ # FIXME: This implementation assumes a local repo.
+
+ scheme, netlock, path, params, query, frag = urlparse.urlparse(repo)
+ assert scheme == 'file'
+
+ ex = morphlib.execute.Execute(path, msg=logging.debug)
+ out = ex.runv(['git', 'ls-tree', '--name-only', '-z', ref])
+ names = [x for x in out.split('\0') if x]
+ morphs = [x for x in names if x.endswith('.morph')]
+ if len(morphs) == 0:
+ raise NoMorphs(repo, ref)
+ if len(morphs) > 1:
+ raise TooManyMorphs(repo, ref, morphs)
+ out = ex.runv(['git', 'cat-file', 'blob', '%s:%s' % (ref, morphs[0])])
+
+ return morphs[0], out
+