summaryrefslogtreecommitdiff
path: root/morph
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-02-28 15:41:19 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-02-28 15:41:19 +0000
commita9bbeaa63ccbe6fa3328d494dd74a1927fce06f8 (patch)
treedbb5c9af4de56bdf9b5eb6ad917a48401eab62ea /morph
parentf91580c2aa50c9a2ebfbe7677987f073ca4a07f4 (diff)
downloadmorph-a9bbeaa63ccbe6fa3328d494dd74a1927fce06f8.tar.gz
Simplify iterating over build triplets from the command line
Diffstat (limited to 'morph')
-rwxr-xr-xmorph39
1 files changed, 15 insertions, 24 deletions
diff --git a/morph b/morph
index 551af5a7..c099f3bf 100755
--- a/morph
+++ b/morph
@@ -101,6 +101,17 @@ class Morph(cliapp.Application):
'build work to',
metavar='HOSTNAME')
+ def _itertriplets(self, args):
+ '''Generate repo, ref, filename triples from args.'''
+
+ if (len(args) % 3) != 0:
+ raise cliapp.AppException('Argument list must have full triplets')
+
+ while args:
+ assert len(args) >= 2, args
+ yield args[0], args[1], args[2]
+ args = args[3:]
+
def cmd_build(self, args):
'''Build a binary from a morphology.
@@ -120,7 +131,7 @@ class Morph(cliapp.Application):
os.mkdir(self.settings['cachedir'])
ret = []
- while len(args) >= 3:
+ for repo, ref, filename in self._itertriplets(args):
tempdir = morphlib.tempdir.Tempdir(self.settings['tempdir'])
morph_loader = MorphologyLoader(self.settings)
source_manager = morphlib.sourcemanager.SourceManager(self,
@@ -135,9 +146,6 @@ class Morph(cliapp.Application):
for bin in self.settings['staging-filler']:
morphlib.bins.unpack_binary(bin, staging, ex)
- repo, ref, filename = args[:3]
- args = args[3:]
-
# derive a build order from the dependency graph
graph = BuildDependencyGraph(source_manager, morph_loader,
repo, ref, filename)
@@ -151,9 +159,6 @@ class Morph(cliapp.Application):
tempdir.remove()
- if args:
- raise cliapp.AppException('Extra args on command line: %s' % args)
-
def cmd_show_dependencies(self, args):
'''Dumps the dependency tree of all input morphologies.'''
@@ -161,11 +166,7 @@ class Morph(cliapp.Application):
source_manager = morphlib.sourcemanager.SourceManager(self,
update=not self.settings['no-git-update'])
- while len(args) >= 3:
- # read the build tuple from the command line
- repo, ref, filename = args[:3]
- args = args[3:]
-
+ for repo, ref, filename in self._itertriplets(args):
# create a dependency graph for the morphology
graph = BuildDependencyGraph(source_manager, morph_loader,
repo, ref, filename)
@@ -197,11 +198,8 @@ class Morph(cliapp.Application):
morph_loader = MorphologyLoader(self.settings)
source_manager = morphlib.sourcemanager.SourceManager(self)
- while len(args) >= 3:
- # read the build tuple from the command line
- repo, ref, filename = args[:3]
- args = args[3:]
+ for repo, ref, filename in self._itertriplets(args):
# resolve the dependency graph, which will implicitly
# clone all repositories needed to build the blob
graph = BuildDependencyGraph(source_manager, morph_loader,
@@ -335,11 +333,7 @@ class Morph(cliapp.Application):
result = []
- while len(args) >= 3:
- # read the build tuple from the command line
- repo, ref, filename = args[:3]
- args = args[3:]
-
+ for repo, ref, filename in self._itertriplets(args):
# derive a build order from the dependency graph
graph = BuildDependencyGraph(source_manager, morph_loader,
repo, ref, filename)
@@ -353,9 +347,6 @@ class Morph(cliapp.Application):
tempdir.remove()
- if args:
- raise cliapp.AppException('Extra args on command line: %s' % args)
-
def msg(self, msg):
'''Show a message to the user about what is going on.'''
logging.debug(msg)