diff options
author | Sam Thursfield <sam@afuera.me.uk> | 2014-10-27 17:15:55 +0000 |
---|---|---|
committer | Sam Thursfield <sam@afuera.me.uk> | 2014-10-27 17:17:38 +0000 |
commit | a0c24350042082fe3e1195f8f6160da363c94843 (patch) | |
tree | 4db8e1be44b2d3106e33723fbe8c81777451ef5e /distbuild/protocol.py | |
parent | 71fbade1fdb5e0d578b9f0ec06d44b69951b8af8 (diff) | |
download | morph-a0c24350042082fe3e1195f8f6160da363c94843.tar.gz |
Fix distbuild to allow passing a commit instead of a named ref to be built
The recent changes to the BuildCommand.build() function caused distbuild
to break, because I didn't make the same change to the
InitiatorBuildCommand.build() function but did change how it was called.
This commit adds the ability to have optional fields in distbuild
messages. This is used to add an optional 'original_ref' field, which
will get passed to `morph serialise-artifact` by new distbuild
controllers, and will be ignored by older ones.
Diffstat (limited to 'distbuild/protocol.py')
-rw-r--r-- | distbuild/protocol.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/distbuild/protocol.py b/distbuild/protocol.py index d5dfe2b7..ffce1fe7 100644 --- a/distbuild/protocol.py +++ b/distbuild/protocol.py @@ -19,7 +19,7 @@ '''Construct protocol message objects (dicts).''' -_types = { +_required_fields = { 'build-request': [ 'id', 'repo', @@ -84,15 +84,26 @@ _types = { } +_optional_fields = { + 'build-request': [ + 'original_ref' + ] +} + + def message(message_type, **kwargs): - assert message_type in _types - required_fields = _types[message_type] + known_types = _required_fields.keys() + assert message_type in known_types + + required_fields = _required_fields[message_type] + optional_fields = _optional_fields.get(message_type, []) for name in required_fields: assert name in kwargs, 'field %s is required' % name for name in kwargs: - assert name in required_fields, 'field %s is not allowed' % name + assert (name in required_fields or name in optional_fields), \ + 'field %s is not allowed' % name msg = dict(kwargs) msg['type'] = message_type |