1 From 1da7b980d05706c8d4e9bcb0d12965258a4fc709 Mon Sep 17 00:00:00 2001
2 From: Scott Murray <scott.murray@konsulko.com>
3 Date: Thu, 6 Oct 2022 16:07:00 -0400
4 Subject: [PATCH] kuksa_viss_client: Update cmd2 completer usage
6 Update cmd2 usage to avoid using internal methods and fix breakage
7 with newer versions of the cmd2 module.
9 Upstream-Status: pending
11 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
13 kuksa_viss_client/__main__.py | 26 +++++++++++++-------------
14 1 file changed, 13 insertions(+), 13 deletions(-)
16 diff --git a/kuksa_viss_client/__main__.py b/kuksa_viss_client/__main__.py
17 index 5e595f8..e5798b8 100755
18 --- a/kuksa_viss_client/__main__.py
19 +++ b/kuksa_viss_client/__main__.py
20 @@ -23,7 +23,7 @@ from typing import Dict, List
21 import queue, time, os, threading
22 from pygments import highlight, lexers, formatters
23 from cmd2 import Cmd, with_argparser, with_category, Cmd2ArgumentParser, CompletionItem
24 -from cmd2.utils import CompletionError, basic_complete
25 +from cmd2.exceptions import CompletionError
26 import functools, subprocess
27 DEFAULT_SERVER_ADDR = "127.0.0.1"
28 DEFAULT_SERVER_PORT = 8090
29 @@ -103,7 +103,7 @@ class TestClient(Cmd):
30 if 'children' in child:
31 self.pathCompletionItems.append(CompletionItem(prefix + key+seperator, "Children of branch "+prefix+key))
33 - return basic_complete(text, line, begidx, endidx, self.pathCompletionItems)
34 + return Cmd.basic_complete(self, text, line, begidx, endidx, self.pathCompletionItems)
36 def subscribeCallback(self, path, attr, resp):
37 self.subscribeFileDesc[(path,attr)].write(resp + "\n")
38 @@ -113,7 +113,7 @@ class TestClient(Cmd):
39 self.pathCompletionItems = []
40 for id in self.subscribeIdToPath.keys():
41 self.pathCompletionItems.append(CompletionItem(id))
42 - return basic_complete(text, line, begidx, endidx, self.pathCompletionItems)
43 + return Cmd.basic_complete(self, text, line, begidx, endidx, self.pathCompletionItems)
45 COMM_SETUP_COMMANDS = "Communication Set-up Commands"
46 VISS_COMMANDS = "Kuksa Interaction Commands"
47 @@ -126,45 +126,45 @@ class TestClient(Cmd):
48 ap_authorize = argparse.ArgumentParser()
49 tokenfile_completer_method = functools.partial(Cmd.path_complete,
50 path_filter=lambda path: (os.path.isdir(path) or path.endswith(".token")))
51 - ap_authorize.add_argument('Token', help='JWT(or the file storing the token) for authorizing the client.', completer_method=tokenfile_completer_method)
52 + ap_authorize.add_argument('Token', help='JWT(or the file storing the token) for authorizing the client.', completer=tokenfile_completer_method)
53 ap_setServerAddr = argparse.ArgumentParser()
54 ap_setServerAddr.add_argument('IP', help='VISS Server IP Address', default=DEFAULT_SERVER_ADDR)
55 ap_setServerAddr.add_argument('Port', type=int, help='VISS Server Port', default=DEFAULT_SERVER_PORT)
56 ap_setServerAddr.add_argument('-p', "--protocol", help='VISS Server Communication Protocol (ws or grpc)', default=DEFAULT_SERVER_PROTOCOL)
58 ap_setValue = argparse.ArgumentParser()
59 - ap_setValue.add_argument("Path", help="Path to be set", completer_method=path_completer)
60 + ap_setValue.add_argument("Path", help="Path to be set", completer=path_completer)
61 ap_setValue.add_argument("Value", help="Value to be set")
62 ap_setValue.add_argument("-a", "--attribute", help="Attribute to be set", default="value")
64 ap_getValue = argparse.ArgumentParser()
65 - ap_getValue.add_argument("Path", help="Path to be read", completer_method=path_completer)
66 + ap_getValue.add_argument("Path", help="Path to be read", completer=path_completer)
67 ap_getValue.add_argument("-a", "--attribute", help="Attribute to be get", default="value")
69 ap_setTargetValue = argparse.ArgumentParser()
70 - ap_setTargetValue.add_argument("Path", help="Path whose target value to be set", completer_method=path_completer)
71 + ap_setTargetValue.add_argument("Path", help="Path whose target value to be set", completer=path_completer)
72 ap_setTargetValue.add_argument("Value", help="Value to be set")
74 ap_getTargetValue = argparse.ArgumentParser()
75 - ap_getTargetValue.add_argument("Path", help="Path whose target value to be read", completer_method=path_completer)
76 + ap_getTargetValue.add_argument("Path", help="Path whose target value to be read", completer=path_completer)
78 ap_subscribe = argparse.ArgumentParser()
79 - ap_subscribe.add_argument("Path", help="Path to be subscribed", completer_method=path_completer)
80 + ap_subscribe.add_argument("Path", help="Path to be subscribed", completer=path_completer)
81 ap_subscribe.add_argument("-a", "--attribute", help="Attribute to be subscribed", default="value")
83 ap_unsubscribe = argparse.ArgumentParser()
84 - ap_unsubscribe.add_argument("SubscribeId", help="Corresponding subscription Id", completer_method=subscriptionIdCompleter)
85 + ap_unsubscribe.add_argument("SubscribeId", help="Corresponding subscription Id", completer=subscriptionIdCompleter)
87 ap_getMetaData = argparse.ArgumentParser()
88 - ap_getMetaData.add_argument("Path", help="Path whose metadata is to be read", completer_method=path_completer)
89 + ap_getMetaData.add_argument("Path", help="Path whose metadata is to be read", completer=path_completer)
90 ap_updateMetaData = argparse.ArgumentParser()
91 - ap_updateMetaData.add_argument("Path", help="Path whose MetaData is to update", completer_method=path_completer)
92 + ap_updateMetaData.add_argument("Path", help="Path whose MetaData is to update", completer=path_completer)
93 ap_updateMetaData.add_argument("Json", help="MetaData to update. Note, only attributes can be update, if update children or the whole vss tree, use `updateVSSTree` instead.")
95 ap_updateVSSTree = argparse.ArgumentParser()
96 jsonfile_completer_method = functools.partial(Cmd.path_complete,
97 path_filter=lambda path: (os.path.isdir(path) or path.endswith(".json")))
98 - ap_updateVSSTree.add_argument("Json", help="Json tree to update VSS", completer_method=jsonfile_completer_method)
99 + ap_updateVSSTree.add_argument("Json", help="Json tree to update VSS", completer=jsonfile_completer_method)