From 0b8cfd5e2e543e186b827f93497a0e77b6bdd4ce Mon Sep 17 00:00:00 2001 From: Edoardo Putti Date: Sat, 29 Oct 2016 22:30:56 +0200 Subject: [PATCH] draft for sign_request completion with all possibilities --- ca_shell.py | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/ca_shell.py b/ca_shell.py index 3012905..2d7dbf6 100755 --- a/ca_shell.py +++ b/ca_shell.py @@ -116,44 +116,22 @@ class CAManagerShell(cmd.Cmd, object): # print available requests print("Available request") print_available_requests(self.ca_manager) - - elif argc == 1: - ca_type = None - ca_id = argv[0] - try: - ca_type = self.ca_manager.ca[ca_id].ca_type - except Exception as e: - print ("Error: %s"%e) - return - # print available requests - print("Available request for CA %s (type %s)" % (ca_id, ca_type)) - print_available_requests(self.ca_manager, ca_type) - - print("==================") - print("usage: sign_request autority request") else: authority_id, request_id = argv[0], argv[1] sign_request(self.ca_manager, request_id, authority_id) def complete_sign_request(self, text, line, begidx, endidx): - results = '' - #too much magic - argc = len(( "%send" % line ).split() ) - - if argc == 2: - results = [a[0] for a in self.ca_manager.ca if a[0].startswith(text)] - elif argc == 3: - ca_type = None - try: - ca_id = line.split()[1] - ca_type = self.ca_manager.ca[ca_id].ca_type - except Exception as e: - print ("Error: %s"%e) - return - - results = [a for a in self.ca_manager.request[ca_type] if str(a).startswith(text)] - return results + + ca_results = [ + a for a in self.ca_manager.ca if a.ca_id.startswith(text) + ] + + req_result = [ + a for a in self.ca_manager.request if a.req_id.startswith(text) + ] + + return ' '.join(results) def complete(self, text, state): results = super().complete(text, state)