diff options
-rw-r--r-- | distixlib/plugins/list_plugin.py | 62 | ||||
-rw-r--r-- | distixlib/plugins/new_plugin.py | 68 | ||||
-rw-r--r-- | without-tests | 2 | ||||
-rw-r--r-- | yarns/040-new.yarn | 9 | ||||
-rw-r--r-- | yarns/900-implements.yarn | 12 |
5 files changed, 147 insertions, 6 deletions
diff --git a/distixlib/plugins/list_plugin.py b/distixlib/plugins/list_plugin.py new file mode 100644 index 0000000..3af5986 --- /dev/null +++ b/distixlib/plugins/list_plugin.py @@ -0,0 +1,62 @@ +# 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 glob +import os + +import cliapp + +import distixlib + + +class ListPlugin(cliapp.Plugin): + + def enable(self): + self.app.add_subcommand( + 'list', self.list, arg_synopsis='') + + def disable(self): + pass + + def list(self, args): + '''List tickets.''' + + for ticket_dir in self._find_ticket_dirs(): + filename = os.path.join(ticket_dir, 'ticket.yaml') + metadata = self._load_metadata(filename) + self._list_ticket(metadata) + + def _find_ticket_dirs(self): + return glob.glob('tickets/*') + + def _load_metadata(self, filename): + with open(filename) as f: + text = f.read() + serialiser = distixlib.MetadataSerialiser() + return serialiser.deserialise(text) + + def _list_ticket(self, metadata): + ticket_id = '0123456' # FIXME: This is not known yet + title = self._get_first_metadata_value(metadata, 'title') + self.app.output.write( + '{ticket_id} {title}'.format(ticket_id=ticket_id, title=title)) + + def _get_first_metadata_value(self, metadata, key): + if key not in metadata: + return '' + return metadata.get_all_values(key)[0] diff --git a/distixlib/plugins/new_plugin.py b/distixlib/plugins/new_plugin.py new file mode 100644 index 0000000..1bf20de --- /dev/null +++ b/distixlib/plugins/new_plugin.py @@ -0,0 +1,68 @@ +# 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 uuid + +import cliapp + +import distixlib + + +class NewTicketPlugin(cliapp.Plugin): + + def enable(self): + self.app.add_subcommand( + 'new', self.new_ticket, arg_synopsis='TITLE') + + def disable(self): + pass + + def new_ticket(self, args): + '''Create a new ticket.''' + + title = args[0] + ticket_id = self._invent_ticket_id() + filenames = self._create_ticket(ticket_id, title) + self._commit_changes(filenames) + + def _invent_ticket_id(self): + return uuid.uuid4().hex + + def _create_ticket(self, ticket_id, title): + dirname = os.path.join('tickets', ticket_id) + filename = os.path.join(dirname, 'ticket.yaml') + os.makedirs(dirname) + metadata = self._create_ticket_metadata(dirname, title) + self._save_metadata(metadata, filename) + return [filename] + + def _create_ticket_metadata(self, dirname, title): + metadata = distixlib.Metadata() + metadata.add('title', title) + return metadata + + def _save_metadata(self, metadata, filename): + serialiser = distixlib.MetadataSerialiser() + text = serialiser.serialise(metadata) + with open(filename, 'w') as f: + f.write(text) + + def _commit_changes(self, filenames): + cliapp.runcmd(['git', 'add'] + filenames, stdout=None, stderr=None) + cliapp.runcmd(['git', 'commit', '-m', 'distix new ticket']) diff --git a/without-tests b/without-tests index bd29200..e918d15 100644 --- a/without-tests +++ b/without-tests @@ -2,4 +2,6 @@ setup.py distixlib/app.py distixlib/__init__.py distixlib/plugins/init_plugin.py +distixlib/plugins/list_plugin.py distixlib/plugins/metadata_manipulation_plugin.py +distixlib/plugins/new_plugin.py diff --git a/yarns/040-new.yarn b/yarns/040-new.yarn index e02dd32..566bc9b 100644 --- a/yarns/040-new.yarn +++ b/yarns/040-new.yarn @@ -5,6 +5,11 @@ This chapter has scenarios for creating new tickets. SCENARIO create new ticket WHEN user attempts to run distix init REPO - AND user changes working directory to REPO - AND user attempts to run distix new "A new ticket" THEN attempt succeeded + WHEN user changes working directory to REPO + AND user attempts to run distix new new-ticket-title + THEN attempt succeeded + + WHEN user attempts to run distix list + THEN attempt succeeded + AND output matches "^[0-9a-f]{7} new-ticket-title$" diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn index fde41d8..8de6d7a 100644 --- a/yarns/900-implements.yarn +++ b/yarns/900-implements.yarn @@ -24,14 +24,14 @@ be, and changing there when running various commands. IMPLEMENTS WHEN user attempts to run distix (.*) cd "$DATADIR" - cd "$(cat cwd || echo .)" rm -f attempt.exit attempt.stdout attempt.stderr + cd "$(cat cwd || echo .)" if "$SRCDIR/distix" --no-default-config $MATCH_1 \ - > attempt.stdout 2> $DATADIR/attempt.stderr + > "$DATADIR/attempt.stdout" 2> "$DATADIR/attempt.stderr" then - echo 0 > attempt.exit + echo 0 > "$DATADIR/attempt.exit" else - echo "$?" > attempt.exit + echo "$?" > "$DATADIR/attempt.exit" fi We also need steps for inspecting the results of attempting to run @@ -51,6 +51,10 @@ distix. printf "$MATCH_1" > "$DATADIR/temp-stdout" diff -u "$DATADIR/temp-stdout" "$DATADIR/attempt.stdout" + IMPLEMENTS THEN output matches "(.*)" + cat "$DATADIR/attempt.stdout" + grep -P -e "$MATCH_1" "$DATADIR/attempt.stdout" + IMPLEMENTS THEN attempt failed cat "$DATADIR/attempt.exit" # helps debugging scenarios if grep -Fx 0 "$DATADIR/attempt.exit" |