diff options
-rw-r--r-- | distixlib/ticket_store.py | 37 | ||||
-rw-r--r-- | yarns/900-implements.yarn | 6 |
2 files changed, 23 insertions, 20 deletions
diff --git a/distixlib/ticket_store.py b/distixlib/ticket_store.py index 4179952..73f7257 100644 --- a/distixlib/ticket_store.py +++ b/distixlib/ticket_store.py @@ -69,28 +69,34 @@ class TicketStore(object): ticket.make_clean() self._dirty = False - def get_ticket(self, ticket_id): + def get_ticket(self, ticket_id_or_prefix): '''Return a distixlib.Ticket for an existing ticket in the store.''' - if ticket_id not in self._ticket_cache: - ticket = self._get_ticket_from_disk(ticket_id) - self._ticket_cache.put(ticket) - + ticket_id = self._find_ticket_id_from_prefix(ticket_id_or_prefix) + assert ticket_id in self._ticket_cache return self._ticket_cache.get(ticket_id) - def _get_ticket_from_disk(self, ticket_id): - ticket_dir = self._get_directory_from_ticket_id(ticket_id) - if not os.path.exists(ticket_dir): - raise distixlib.TicketNotInStoreError( - ticket_id=ticket_id, dirname=self._dirname) - return self._load_ticket(ticket_dir) + def _find_ticket_id_from_prefix(self, prefix): + cached_ids = self._ticket_cache.keys() + matches = self._find_ticket_ids_matching_prefix(cached_ids, prefix) + if len(matches) == 1: + return matches[0] + + tickets = self.get_tickets() + ticket_ids = [t.get_ticket_id() for t in tickets] + matches = self._find_ticket_ids_matching_prefix(ticket_ids, prefix) + if len(matches) == 1: + return matches[0] + + raise TicketNotInStoreError(ticket_id=prefix) + + def _find_ticket_ids_matching_prefix(self, ticket_ids, prefix): + prefix = prefix.lower() + return [tid for tid in ticket_ids if tid.lower().startswith(prefix)] def _load_ticket(self, ticket_dir): return self._loader.load_from_directory(ticket_dir) - def _get_directory_from_ticket_id(self, ticket_id): - return os.path.join(self._dirname, ticket_id) - def get_tickets(self): '''Return all the tickets in a store.''' @@ -172,6 +178,9 @@ class _TicketCache(object): def __init__(self): self._known_tickets = {} + def keys(self): + return self._known_tickets.keys() + def put(self, ticket): self._known_tickets[ticket.get_ticket_id()] = ticket diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn index a84f7c8..da62298 100644 --- a/yarns/900-implements.yarn +++ b/yarns/900-implements.yarn @@ -60,13 +60,7 @@ b echo 0 > "$DATADIR/attempt.exit" else echo "$?" > "$DATADIR/attempt.exit" - echo ============= distix stdout - cat "$DATADIR/attempt.stdout" - echo ============= distix stderr - cat "$DATADIR/attempt.stderr" - echo ============= distix output end fi - exit 1 IMPLEMENTS WHEN user sets all tickets in (\S+) to (\S+) cd "$DATADIR/$MATCH_1" |