aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/command
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2024-01-19 03:07:54 +0100
committerMatěj Cepl <mcepl@cepl.eu>2024-01-21 21:57:15 +0100
commitb638466e6a6ada7478758cf740c89650d0f70f59 (patch)
treef34979881a12818ba46a4b74a7a7096e737e441a /libbe/command
parentb11b63156666589ec9749fa318fe7ecd9d1f136d (diff)
downloadbugseverywhere-b638466e6a6ada7478758cf740c89650d0f70f59.tar.gz
WIP plenty of clean-ups and porting to Python 3.
Diffstat (limited to 'libbe/command')
-rw-r--r--libbe/command/base.py10
-rw-r--r--libbe/command/comment.py4
-rw-r--r--libbe/command/import_xml.py6
-rw-r--r--libbe/command/list.py37
-rw-r--r--libbe/command/merge.py6
-rw-r--r--libbe/command/new.py8
-rw-r--r--libbe/command/remove.py4
-rw-r--r--libbe/command/subscribe.py4
-rw-r--r--libbe/command/tag.py10
-rw-r--r--libbe/command/target.py4
10 files changed, 47 insertions, 46 deletions
diff --git a/libbe/command/base.py b/libbe/command/base.py
index efba1b2..269141f 100644
--- a/libbe/command/base.py
+++ b/libbe/command/base.py
@@ -75,7 +75,7 @@ def get_command(command_name):
>>> try:
... get_command('asdf')
... except UnknownCommand, e:
- ... print e
+ ... print(e)
Unknown command 'asdf'
(No module named asdf)
>>> repr(get_command('list')).startswith("<module 'libbe.command.list' from ")
@@ -254,7 +254,7 @@ class Command (object):
"""One-line command description here.
>>> c = Command()
- >>> print c.help()
+ >>> print(c.help())
usage: be command [options]
<BLANKLINE>
Options:
@@ -415,7 +415,7 @@ class Command (object):
... c._check_restricted_access(s, os.path.expanduser('~/.ssh/id_rsa'))
... except UserError, e:
... assert str(e).startswith('file access restricted!'), str(e)
- ... print 'we got the expected error'
+ ... print('we got the expected error')
we got the expected error
>>> c._check_restricted_access(s, os.path.expanduser('~/x'))
>>> c._check_restricted_access(s, os.path.expanduser('~/x/y'))
@@ -527,7 +527,7 @@ class StorageCallbacks (object):
def get_unconnected_storage(self):
"""
Callback for use by commands that need it.
-
+
The returned Storage instance is may actually be connected,
but commands that make use of the returned value should only
make use of non-connected Storage methods. This is mainly
@@ -595,7 +595,7 @@ class UserInterface (object):
if self.io is not None:
self.io.setup_command(command)
if self.storage_callbacks is not None:
- self.storage_callbacks.setup_command(command)
+ self.storage_callbacks.setup_command(command)
command.restrict_file_access = self.restrict_file_access
command._get_user_id = self._get_user_id
diff --git a/libbe/command/comment.py b/libbe/command/comment.py
index e110c81..bfd24fe 100644
--- a/libbe/command/comment.py
+++ b/libbe/command/comment.py
@@ -56,7 +56,7 @@ class Comment (libbe.command.Command):
>>> comment = bug.comment_root[0]
>>> comment.id.storage() == comment.uuid
True
- >>> print comment.body
+ >>> print(comment.body)
This is a comment about a
<BLANKLINE>
>>> comment.author
@@ -84,7 +84,7 @@ class Comment (libbe.command.Command):
>>> bug = bd.bug_from_uuid('b')
>>> bug.load_comments(load_full=False)
>>> comment = bug.comment_root[0]
- >>> print comment.body
+ >>> print(comment.body)
I like cheese
<BLANKLINE>
>>> ui.cleanup()
diff --git a/libbe/command/import_xml.py b/libbe/command/import_xml.py
index 8699e70..391b2ed 100644
--- a/libbe/command/import_xml.py
+++ b/libbe/command/import_xml.py
@@ -62,7 +62,7 @@ class Import_XML (libbe.command.Command):
>>> bug = bd.bug_from_uuid('a')
>>> bug.load_comments(load_full=False)
>>> comment = bug.comment_root[0]
- >>> print comment.body
+ >>> print(comment.body)
This is a comment about a
<BLANKLINE>
>>> comment.time <= int(time.time())
@@ -183,7 +183,7 @@ class Import_XML (libbe.command.Command):
if be_xml.tag != 'be-xml':
raise libbe.util.utility.InvalidXML(
'import-xml', be_xml, 'root element must be <be-xml>')
- for child in be_xml.getchildren():
+ for child in be_xml:
if child.tag == 'bugdir':
new = libbe.bugdir.BugDir(storage=None)
new.from_xml(child, preserve_uuids=params['preserve-uuids'])
@@ -197,7 +197,7 @@ class Import_XML (libbe.command.Command):
new.from_xml(child, preserve_uuids=params['preserve-uuids'])
root_comments.append(new)
elif child.tag == 'version':
- for gchild in child.getchildren():
+ for gchild in child:
if child.tag in ['tag', 'nick', 'revision', 'revision-id']:
text = xml.sax.saxutils.unescape(child.text)
text = text.decode('unicode_escape').strip()
diff --git a/libbe/command/list.py b/libbe/command/list.py
index 6d4fcd8..41e1bed 100644
--- a/libbe/command/list.py
+++ b/libbe/command/list.py
@@ -32,9 +32,10 @@ import libbe.command.tag
import libbe.command.target
import libbe.command.util
-# get a list of * for cmp_*() comparing two bugs.
-AVAILABLE_CMPS = [fn[4:] for fn in dir(libbe.bug) if fn[:4] == 'cmp_']
-AVAILABLE_CMPS.remove('attr') # a cmp_* template.
+# get a list of * for idx_*() comparing two bugs.
+AVAILABLE_IDXS = [fn[4:] for fn in dir(libbe.bug) if fn[:4] == 'idx_']
+AVAILABLE_IDXS.remove('attr') # a idx_* template.
+
class List (libbe.command.Command):
"""List bugs
@@ -94,10 +95,10 @@ class List (libbe.command.Command):
libbe.command.Option(name='sort', short_name='S',
help='Adjust bug-sort criteria with comma-separated list '
'SORT. e.g. "--sort creator,time". '
- 'Available criteria: %s' % ','.join(AVAILABLE_CMPS),
+ 'Available criteria: %s' % ','.join(AVAILABLE_IDXS),
arg=libbe.command.Argument(
name='sort', metavar='SORT', default=None,
- completion_callback=libbe.command.util.Completer(AVAILABLE_CMPS))),
+ completion_callback=libbe.command.util.Completer(AVAILABLE_IDXS))),
libbe.command.Option(name='tags', short_name='t',
help='Add TAGS: field to standard listing format.'),
libbe.command.Option(name='ids', short_name='i',
@@ -106,7 +107,7 @@ class List (libbe.command.Command):
help='Dump output in XML format'),
])
# parser.add_option("-S", "--sort", metavar="SORT-BY", dest="sort_by",
-# help="Adjust bug-sort criteria with comma-separated list SORT-BY. e.g. \"--sort creator,time\". Available criteria: %s" % ','.join(AVAILABLE_CMPS), default=None)
+# help="Adjust bug-sort criteria with comma-separated list SORT-BY. e.g. \"--sort creator,time\". Available criteria: %s" % ','.join(AVAILABLE_IDXS), default=None)
# # boolean options. All but ids and xml are special cases of long forms
# ("w", "wishlist", "List bugs with 'wishlist' severity"),
# ("A", "active", "List all active bugs"),
@@ -129,20 +130,20 @@ class List (libbe.command.Command):
bugdirs = self._get_bugdirs()
writeable = storage.writeable
storage.writeable = False
- cmp_list, status, severity, assigned, extra_strings_regexps = \
+ idx_list, status, severity, assigned, extra_strings_regexps = \
self._parse_params(bugdirs, params)
filter = Filter(status, severity, assigned,
extra_strings_regexps=extra_strings_regexps)
bugs = list(itertools.chain(*list(
[bugdir.bug_from_uuid(uuid) for uuid in bugdir.uuids()]
for bugdir in list(bugdirs.values()))))
- bugs = [b for b in bugs if list(filter(bugdirs, b)) == True]
+ bugs = [b for b in bugs if list(filter(bugdirs, b))]
self.result = bugs
- if len(bugs) == 0 and params['xml'] == False:
+ if len(bugs) == 0 and not params['xml']:
print('No matching bugs found', file=self.stdout)
# sort bugs
- bugs = self._sort_bugs(bugs, cmp_list)
+ bugs = self._sort_bugs(bugs, idx_list)
# print list of bugs
if params['ids'] == True:
@@ -157,10 +158,10 @@ class List (libbe.command.Command):
cmp_list = []
if params['sort'] != None:
for cmp in params['sort'].split(','):
- if cmp not in AVAILABLE_CMPS:
+ if cmp not in AVAILABLE_IDXS:
raise libbe.command.UserError(
'Invalid sort on "%s".\nValid sorts:\n %s'
- % (cmp, '\n '.join(AVAILABLE_CMPS)))
+ % (cmp, '\n '.join(AVAILABLE_IDXS)))
cmp_list.append(getattr(libbe.bug, 'cmp_%s' % cmp))
status = parse_status(params['status'])
severity = parse_severity(params['severity'],
@@ -184,12 +185,12 @@ class List (libbe.command.Command):
for x in params['extra-strings'].split(',')]
return (cmp_list, status, severity, assigned, extra_strings_regexps)
- def _sort_bugs(self, bugs, cmp_list=None):
- if cmp_list is None:
- cmp_list = []
- cmp_list.extend(libbe.bug.DEFAULT_CMP_FULL_CMP_LIST)
- cmp_fn = libbe.bug.BugCompoundComparator(cmp_list=cmp_list)
- bugs.sort(cmp_fn)
+ def _sort_bugs(self, bugs, idx_list=None):
+ if idx_list is None:
+ idx_list = []
+ idx_list.extend(libbe.bug.DEFAULT_IDX_FULL_IDX_LIST)
+ # MCEPL idx_fn = libbe.bug.BugCompoundComparator(idx_list=idx_list)
+ bugs.sort(idx_fn)
return bugs
def _list_bugs(self, bugs, show_tags=False, xml=False):
diff --git a/libbe/command/merge.py b/libbe/command/merge.py
index cf9eb91..4ee67cf 100644
--- a/libbe/command/merge.py
+++ b/libbe/command/merge.py
@@ -60,7 +60,7 @@ class Merge (libbe.command.Command):
... cmp=libbe.comment.cmp_time)
>>> mergeA = a_comments[0]
>>> mergeA.time = 3
- >>> print a.string(show_comments=True)
+ >>> print(a.string(show_comments=True))
... # doctest: +ELLIPSIS, +REPORT_UDIFF
ID : a
Short name : abc/a
@@ -107,7 +107,7 @@ class Merge (libbe.command.Command):
... libbe.comment.cmp_time)
>>> mergeB = b_comments[0]
>>> mergeB.time = 3
- >>> print b.string(show_comments=True)
+ >>> print(b.string(show_comments=True))
... # doctest: +ELLIPSIS, +REPORT_UDIFF
ID : b
Short name : abc/b
@@ -136,7 +136,7 @@ class Merge (libbe.command.Command):
Date: ...
<BLANKLINE>
Merged into bug #abc/a#
- >>> print b.status
+ >>> print(b.status)
closed
>>> ui.cleanup()
>>> bd.cleanup()
diff --git a/libbe/command/new.py b/libbe/command/new.py
index b9a3147..4a0288b 100644
--- a/libbe/command/new.py
+++ b/libbe/command/new.py
@@ -51,7 +51,7 @@ class New (libbe.command.Command):
>>> libbe.util.id.uuid_gen = uuid_gen
>>> bd.flush_reload()
>>> bug = bd.bug_from_uuid('X')
- >>> print bug.summary
+ >>> print(bug.summary)
this is a test
>>> bug.creator
u'Fran\\xe7ois'
@@ -59,11 +59,11 @@ class New (libbe.command.Command):
u'Fran\\xe7ois'
>>> bug.time <= int(time.time())
True
- >>> print bug.severity
+ >>> print(bug.severity)
minor
- >>> print bug.status
+ >>> print(bug.status)
open
- >>> print bug.assigned
+ >>> print(bug.assigned)
None
>>> ui.cleanup()
>>> bd.cleanup()
diff --git a/libbe/command/remove.py b/libbe/command/remove.py
index 2ca2699..4f7ca5e 100644
--- a/libbe/command/remove.py
+++ b/libbe/command/remove.py
@@ -37,7 +37,7 @@ class Remove (libbe.command.Command):
>>> ui.storage_callbacks.set_storage(bd.storage)
>>> cmd = Remove(ui=ui)
- >>> print bd.bug_from_uuid('b').status
+ >>> print(bd.bug_from_uuid('b').status)
closed
>>> ret = ui.run(cmd, args=['/b'])
Removed bug abc/b
@@ -45,7 +45,7 @@ class Remove (libbe.command.Command):
>>> try:
... bd.bug_from_uuid('b')
... except libbe.bugdir.NoBugMatches:
- ... print 'Bug not found'
+ ... print('Bug not found')
Bug not found
>>> ui.cleanup()
>>> bd.cleanup()
diff --git a/libbe/command/subscribe.py b/libbe/command/subscribe.py
index 8541970..45cd0dd 100644
--- a/libbe/command/subscribe.py
+++ b/libbe/command/subscribe.py
@@ -45,14 +45,14 @@ class Subscribe (libbe.command.Command):
>>> cmd = Subscribe(ui=ui)
>>> a = bd.bug_from_uuid('a')
- >>> print a.extra_strings
+ >>> print(a.extra_strings)
[]
>>> ret = ui.run(cmd, {'subscriber':'John Doe <j@doe.com>'}, ['/a']) # doctest: +NORMALIZE_WHITESPACE
Subscriptions for abc/a:
John Doe <j@doe.com> all *
>>> bd.flush_reload()
>>> a = bd.bug_from_uuid('a')
- >>> print a.extra_strings
+ >>> print(a.extra_strings)
['SUBSCRIBE:John Doe <j@doe.com>\\tall\\t*']
>>> ret = ui.run(cmd, {'subscriber':'Jane Doe <J@doe.com>', 'servers':'a.com,b.net'}, ['/a']) # doctest: +NORMALIZE_WHITESPACE
Subscriptions for abc/a:
diff --git a/libbe/command/tag.py b/libbe/command/tag.py
index 3b11e99..51e2abe 100644
--- a/libbe/command/tag.py
+++ b/libbe/command/tag.py
@@ -40,14 +40,14 @@ class Tag (libbe.command.Command):
>>> cmd = Tag(ui=ui)
>>> a = bd.bug_from_uuid('a')
- >>> print a.extra_strings
+ >>> print(a.extra_strings)
[]
>>> ret = ui.run(cmd, args=['/a', 'GUI'])
Tags for abc/a:
GUI
>>> bd.flush_reload()
>>> a = bd.bug_from_uuid('a')
- >>> print a.extra_strings
+ >>> print(a.extra_strings)
['%(tag_tag)sGUI']
>>> ret = ui.run(cmd, args=['/a', 'later'])
Tags for abc/a:
@@ -67,15 +67,15 @@ class Tag (libbe.command.Command):
later
>>> bd.flush_reload()
>>> a = bd.bug_from_uuid('a')
- >>> print a.extra_strings
+ >>> print(a.extra_strings)
['%(tag_tag)sAlphabetically first', '%(tag_tag)sGUI', '%(tag_tag)slater']
>>> a.extra_strings = []
- >>> print a.extra_strings
+ >>> print(a.extra_strings)
[]
>>> ret = ui.run(cmd, args=['/a'])
>>> bd.flush_reload()
>>> a = bd.bug_from_uuid('a')
- >>> print a.extra_strings
+ >>> print(a.extra_strings)
[]
>>> ret = ui.run(cmd, args=['/a', 'Alphabetically first'])
Tags for abc/a:
diff --git a/libbe/command/target.py b/libbe/command/target.py
index 0886fbf..b13647e 100644
--- a/libbe/command/target.py
+++ b/libbe/command/target.py
@@ -50,9 +50,9 @@ class Target (libbe.command.Command):
>>> output = ui.io.get_stdout().strip()
>>> bd.flush_reload()
>>> target = bd.bug_from_uuid(output)
- >>> print target.summary
+ >>> print(target.summary)
tomorrow
- >>> print target.severity
+ >>> print(target.severity)
target
>>> ui.io.stdout = sys.stdout