summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-04-18 17:34:14 +0100
committerLars Wirzenius <liw@liw.fi>2014-04-18 17:34:14 +0100
commit41ebf219eb658e57f1842cfd1e3388d7071848ec (patch)
tree41a0b9fadcda48118bed98f114544f9974d27126
parent8b6c9e8ca95fb9b988e0fed97548835f0cabc488 (diff)
downloaddistix-41ebf219eb658e57f1842cfd1e3388d7071848ec.tar.gz
Add preliminary "distix set" command
-rw-r--r--distixlib/plugins/set_plugin.py71
-rw-r--r--without-tests1
-rw-r--r--yarns/060-set.yarn20
3 files changed, 92 insertions, 0 deletions
diff --git a/distixlib/plugins/set_plugin.py b/distixlib/plugins/set_plugin.py
new file mode 100644
index 0000000..928713f
--- /dev/null
+++ b/distixlib/plugins/set_plugin.py
@@ -0,0 +1,71 @@
+# Copyright 2014 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# =*= License: GPL-3+ =*=
+
+
+import os
+
+import cliapp
+
+import distixlib
+
+
+class SetPlugin(cliapp.Plugin):
+
+ def enable(self):
+ self.app.add_subcommand(
+ 'set', self.set, arg_synopsis='TICKETID KEY=VALUE...')
+
+ def disable(self):
+ pass
+
+ def set(self, args):
+ '''Set ticket metadata.'''
+
+ ticket_id = self._get_ticket_id(args)
+ metadata = self._load_ticket_metadata(ticket_id)
+ for pair in args[1:]:
+ key, value = self._parse_pair(pair)
+ metadata.add(key, value)
+ self._save_ticket_metadata(ticket_id, metadata)
+
+ def _get_ticket_id(self, args):
+ if self.app.settings['ticket-id-from']:
+ ticket_ids = self._read_ticket_ids_from_file(
+ self.app.settings['ticket-id-from'])
+ return ticket_ids[0]
+ else:
+ return args[0]
+
+ def _read_ticket_ids_from_file(self, filename):
+ with open(filename) as f:
+ return [line.strip() for line in f.readlines()]
+
+ def _load_ticket_metadata(self, ticket_id):
+ filename = self._ticket_metadata_filename(ticket_id)
+ loader = distixlib.MetadataLoader()
+ return loader.load_from_file(filename)
+
+ def _parse_pair(self, pair):
+ return pair.split('=', 1)
+
+ def _save_ticket_metadata(self, ticket_id, metadata):
+ filename = self._ticket_metadata_filename(ticket_id)
+ saver = distixlib.MetadataSaver()
+ saver.save_to_file(filename, metadata)
+
+ def _ticket_metadata_filename(self, ticket_id):
+ return os.path.join('tickets', ticket_id, 'ticket.yaml')
diff --git a/without-tests b/without-tests
index f8e1175..ba6ab5d 100644
--- a/without-tests
+++ b/without-tests
@@ -5,4 +5,5 @@ distixlib/plugins/init_plugin.py
distixlib/plugins/list_plugin.py
distixlib/plugins/metadata_manipulation_plugin.py
distixlib/plugins/new_plugin.py
+distixlib/plugins/set_plugin.py
distixlib/plugins/show_plugin.py
diff --git a/yarns/060-set.yarn b/yarns/060-set.yarn
new file mode 100644
index 0000000..406f3df
--- /dev/null
+++ b/yarns/060-set.yarn
@@ -0,0 +1,20 @@
+Set metadata for ticket
+=======================
+
+This chapter contains scenarios for setting metadata for a ticket.
+
+ SCENARIO set metadata for ticket
+
+ WHEN user attempts to run distix init REPO
+ THEN attempt succeeded
+
+ WHEN user changes working directory to REPO
+ AND user attempts to run distix new new-ticket-title --save-ticket-id=NEW
+ THEN attempt succeeded
+
+ WHEN user attempts to run distix set DUMMYID FOO=BAR --ticket-id-from=NEW
+ THEN attempt succeeded
+
+ WHEN user attempts to run distix show --ticket-id-from=NEW
+ THEN attempt succeeded
+ AND output matches "FOO: BAR"