blob: 7a82e269bebd7f454063963bb1e56fd0ccb7f7e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# 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):
_commit_msg = 'set key/value pair in ticket'
def enable(self):
self.app.add_subcommand(
'set', self.set, arg_synopsis='TICKETID KEY=VALUE...')
def set(self, args):
'''Set ticket metadata.'''
repo = distixlib.Repository('.')
repo.require_clean_working_tree()
ticket_id = distixlib.get_ticket_ids(self.app.settings, [args[0]])[0]
ticket_store = repo.open_ticket_store(distixlib.tickets_dir_name)
ticket = ticket_store.get_ticket(ticket_id)
for pair in args[1:]:
key, value = self._parse_pair(pair)
ticket.add_metadata_key_value_pair(key, value)
filenames = ticket_store.save_changes()
repo.commit_changes(filenames, self._commit_msg)
def _parse_pair(self, pair):
return pair.split('=', 1)
|