-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[crmsh-4.6] Dev: ui_configure: Add completer for 'configure schema' c…
…ommand (#1678) To complete existing pacemaker-*.rng files under /usr/share/pacemaker directory backport #1677
- Loading branch information
Showing
2 changed files
with
34 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ | |
# Copyright (C) 2013 Kristoffer Gronlund <[email protected]> | ||
# 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 | ||
|
@@ -191,6 +193,23 @@ def ra_agent_for_cpt(cpt): | |
return agent | ||
|
||
|
||
def schema_completer(args): | ||
complete_results = [] | ||
|
||
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')) | ||
|
||
if complete_results: | ||
# Sort files using packaging.version | ||
complete_results.sort(key=lambda x: version.parse(version_pattern.match(x).group(1))) | ||
command.enable_custom_sort_order() | ||
|
||
return complete_results | ||
|
||
|
||
class CompletionHelp(object): | ||
''' | ||
Print some help on whatever last word in the line. | ||
|
@@ -231,9 +250,7 @@ def _prim_params_completer(agent, args): | |
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() | ||
return utils.filter_keys(agent.params(), args) | ||
|
||
|
||
|
@@ -952,6 +969,7 @@ def do_upgrade(self, context, force=None): | |
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: | ||
|