summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-08-04 18:50:04 +0100
committerLars Wirzenius <liw@liw.fi>2014-08-04 18:51:17 +0100
commit13aad69bcb3027e5d1b28ef8c1b316767e8b0b10 (patch)
tree1043f24510757b5b84b4d60d68756352519efd51
parent4e04397d0449bdb479a07cfa5371160c5ea49a51 (diff)
downloaddistix-13aad69bcb3027e5d1b28ef8c1b316767e8b0b10.tar.gz
Refactor: Move get_ticket_ids to util.py
-rw-r--r--distixlib/__init__.py1
-rw-r--r--distixlib/plugins/reply_plugin.py14
-rw-r--r--distixlib/plugins/set_plugin.py14
-rw-r--r--distixlib/plugins/show_plugin.py13
-rw-r--r--distixlib/util.py29
-rw-r--r--without-tests1
6 files changed, 34 insertions, 38 deletions
diff --git a/distixlib/__init__.py b/distixlib/__init__.py
index 0de8289..7a8c695 100644
--- a/distixlib/__init__.py
+++ b/distixlib/__init__.py
@@ -38,6 +38,7 @@ from .ticket_store import (
TicketNotInStoreError)
from .repo import Repository
from .git import Git
+from .util import get_ticket_ids
# Export only the explicitly imported symbols.
diff --git a/distixlib/plugins/reply_plugin.py b/distixlib/plugins/reply_plugin.py
index fa1a2f9..b0ac25a 100644
--- a/distixlib/plugins/reply_plugin.py
+++ b/distixlib/plugins/reply_plugin.py
@@ -47,7 +47,7 @@ class ReplyPlugin(cliapp.Plugin):
repo = distixlib.Repository('.')
ticket_store = repo.open_ticket_store(distixlib.tickets_dir_name)
- ticket_id = self._get_ticket_id(args)
+ ticket_id = distixlib.get_ticket_ids(self.app.settings, args)[0]
ticket = ticket_store.get_ticket(ticket_id)
message_body = self._get_message_body()
@@ -57,18 +57,6 @@ class ReplyPlugin(cliapp.Plugin):
filenames = ticket_store.save_changes()
repo.commit_changes(filenames, self._commit_msg)
- 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 _get_message_body(self):
return self.app.settings['message']
diff --git a/distixlib/plugins/set_plugin.py b/distixlib/plugins/set_plugin.py
index 743b9f3..ce10c7f 100644
--- a/distixlib/plugins/set_plugin.py
+++ b/distixlib/plugins/set_plugin.py
@@ -35,7 +35,7 @@ class SetPlugin(cliapp.Plugin):
'''Set ticket metadata.'''
repo = distixlib.Repository('.')
- ticket_id = self._get_ticket_id(args)
+ ticket_id = distixlib.get_ticket_ids(self.app.settings, args)[0]
ticket_store = repo.open_ticket_store(distixlib.tickets_dir_name)
ticket = ticket_store.get_ticket(ticket_id)
for pair in args[1:]:
@@ -44,17 +44,5 @@ class SetPlugin(cliapp.Plugin):
filenames = ticket_store.save_changes()
repo.commit_changes(filenames, self._commit_msg)
- 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 _parse_pair(self, pair):
return pair.split('=', 1)
diff --git a/distixlib/plugins/show_plugin.py b/distixlib/plugins/show_plugin.py
index 48b327b..6fa3e95 100644
--- a/distixlib/plugins/show_plugin.py
+++ b/distixlib/plugins/show_plugin.py
@@ -50,7 +50,7 @@ class ShowTicketPlugin(cliapp.Plugin):
'''Show existing tickets.'''
template = self._load_template()
- ticket_ids = self._get_ticket_ids(args)
+ ticket_ids = distixlib.get_ticket_ids(self.app.settings, args)
for ticket_id in ticket_ids:
ticket = self._load_ticket(ticket_id)
self._show_ticket(template, ticket)
@@ -58,17 +58,6 @@ class ShowTicketPlugin(cliapp.Plugin):
def _load_template(self):
return bottle.SimpleTemplate(self._template)
- def _get_ticket_ids(self, args):
- if self.app.settings['ticket-id-from']:
- return self._read_ticket_ids_from_file(
- self.app.settings['ticket-id-from'])
- else:
- return args
-
- def _read_ticket_ids_from_file(self, filename):
- with open(filename) as f:
- return [line.strip() for line in f.readlines()]
-
def _load_ticket(self, ticket_id):
repo = distixlib.Repository('.')
ticket_store = repo.open_ticket_store(distixlib.tickets_dir_name)
diff --git a/distixlib/util.py b/distixlib/util.py
new file mode 100644
index 0000000..9c0ae12
--- /dev/null
+++ b/distixlib/util.py
@@ -0,0 +1,29 @@
+# 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+ =*=
+
+
+def get_ticket_ids(settings, args):
+ filename = settings['ticket-id-from']
+ if filename:
+ return _read_ticket_ids_from_file(filename)
+ else:
+ return args
+
+
+def _read_ticket_ids_from_file(filename):
+ with open(filename) as f:
+ return [line.strip() for line in f.readlines()]
diff --git a/without-tests b/without-tests
index e5f4e7e..f2d9ac9 100644
--- a/without-tests
+++ b/without-tests
@@ -13,3 +13,4 @@ distixlib/plugins/show_plugin.py
distixlib/constants.py
distixlib/git.py
distixlib/version.py
+distixlib/util.py