Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev: ui_configure: Add completer for 'configure schema' command #1677

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions crmsh/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,7 @@
'''
ret = []
if self.completer is not None:
if sort_completion_inst is not None and sort_completion_inst.value == 0:
# Restore the original value of rl_sort_completion_matches
# before calling the completer again
sort_completion_inst.value = orig_sort_completion_value
disable_custom_sort_order()

Check warning on line 538 in crmsh/command.py

View check run for this annotation

Codecov / codecov/patch

crmsh/command.py#L538

Added line #L538 was not covered by tests
specs = inspect.getfullargspec(self.completer)
if 'context' in specs.args:
ret = self.completer([self.name] + args, context)
Expand Down Expand Up @@ -566,6 +563,18 @@
": Expected method with signature " + repr(expected))


def enable_custom_sort_order():
if sort_completion_inst is not None:
sort_completion_inst.value = 0

Check warning on line 568 in crmsh/command.py

View check run for this annotation

Codecov / codecov/patch

crmsh/command.py#L567-L568

Added lines #L567 - L568 were not covered by tests


def disable_custom_sort_order():
if sort_completion_inst is not None and sort_completion_inst.value == 0:

Check warning on line 572 in crmsh/command.py

View check run for this annotation

Codecov / codecov/patch

crmsh/command.py#L572

Added line #L572 was not covered by tests
# Restore the original value of rl_sort_completion_matches
# before calling the completer again
sort_completion_inst.value = orig_sort_completion_value

Check warning on line 575 in crmsh/command.py

View check run for this annotation

Codecov / codecov/patch

crmsh/command.py#L575

Added line #L575 was not covered by tests


readline_path = ctypes.util.find_library('readline')
sort_completion_inst = None
if readline_path:
Expand Down
24 changes: 21 additions & 3 deletions crmsh/ui_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# Copyright (C) 2013 Kristoffer Gronlund <kgronlund@suse.com>
# See COPYING for license information.

import os
import re
import time
from packaging import version
from . import command
from . import completers as compl
from . import config
Expand Down Expand Up @@ -191,6 +193,23 @@
return agent


def schema_completer(args):
complete_results = []

Check warning on line 197 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L197

Added line #L197 was not covered by tests

directory = '/usr/share/pacemaker/'
version_pattern = re.compile(r'^pacemaker-(\d+\.\d+)')
for filename in os.listdir(directory):
if version_pattern.match(filename):
complete_results.append(filename.strip('.rng'))

Check warning on line 203 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L199-L203

Added lines #L199 - L203 were not covered by tests

if complete_results:

Check warning on line 205 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L205

Added line #L205 was not covered by tests
# Sort files using packaging.version
complete_results.sort(key=lambda x: version.parse(version_pattern.match(x).group(1)))
command.enable_custom_sort_order()

Check warning on line 208 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L207-L208

Added lines #L207 - L208 were not covered by tests

return complete_results

Check warning on line 210 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L210

Added line #L210 was not covered by tests


class CompletionHelp(object):
'''
Print some help on whatever last word in the line.
Expand Down Expand Up @@ -231,9 +250,7 @@
return []
elif '=' in completing:
return []
if command.sort_completion_inst is not None:
# Set the value to 0 to use the costum sort order
command.sort_completion_inst.value = 0
command.enable_custom_sort_order()

Check warning on line 253 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L253

Added line #L253 was not covered by tests
return utils.filter_keys(agent.params(), args)


Expand Down Expand Up @@ -958,6 +975,7 @@
return cib_factory.upgrade_validate_with(force=config.core.force or force)

@command.skill_level('administrator')
@command.completers(schema_completer)
def do_schema(self, context, schema_st=None):
"usage: schema [<schema>]"
if not schema_st:
Expand Down