From 8ce3cf5c7c19346a4a9c0102203e9d5add9c40ac Mon Sep 17 00:00:00 2001 From: idziubenko Date: Tue, 10 Aug 2021 13:53:37 +0300 Subject: [PATCH] fixed error messages --- pym/console/application/cert_func.py | 14 ++++++-------- pym/console/application/cert_verify.py | 6 ++---- pym/console/application/cl_client.py | 8 +++----- pym/console/application/function.py | 9 +++++++-- pym/console/application/methods_func.py | 2 -- pym/console/application/pid_information.py | 1 - pym/console/application/sid_func.py | 7 +++---- 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/pym/console/application/cert_func.py b/pym/console/application/cert_func.py index 6446f00..2c6a511 100644 --- a/pym/console/application/cert_func.py +++ b/pym/console/application/cert_func.py @@ -14,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function -from __future__ import absolute_import import os import pwd import sys @@ -24,7 +22,7 @@ import socket import time import urllib.request as urllib2 from urllib.error import URLError -from .function import _print, get_ip_mac_type +from .function import _print, get_ip_mac_type, parse_error import OpenSSL import hashlib from .client_class import HTTPSClientCertTransport @@ -117,7 +115,7 @@ def new_key_req(key, cert_path, server_host_name, private_key_passwd=None, try: pwdObj = pwd.getpwnam(user_name) except KeyError as e: - _print(e) + _print(parse_error(e)) return None os.chown(key, pwdObj.pw_uid, pwdObj.pw_gid) os.chmod(key, 0o600) @@ -132,7 +130,7 @@ def delete_old_cert(client): os.unlink(client.PKEY_FILE) os.unlink(client.PubKEY_FILE) except OSError as e: - _print(e) + _print(parse_error(e)) def client_post_request(cert_path, args): @@ -260,13 +258,13 @@ def client_get_cert(cert_path, args): try: os.unlink(cert_path + 'req_id') except OSError as e: - _print(e) + _print(parse_error(e)) print(_('Certificate saved. Your certificate ID: %s') % req_id) user_name = pwd.getpwuid(os.getuid()).pw_name try: pwdObj = pwd.getpwnam(user_name) except KeyError as e: - _print(e) + _print(parse_error(e)) return None os.chown(cert_file, pwdObj.pw_uid, pwdObj.pw_gid) os.chmod(cert_file, 0o600) @@ -401,7 +399,7 @@ def create_socket(file_path, username): try: os.unlink(file_path) except OSError as e: - _print(e) + _print(parse_error(e)) cmd = ['cl-consoled'] # print cmd diff --git a/pym/console/application/cert_verify.py b/pym/console/application/cert_verify.py index 801c97d..32438c3 100644 --- a/pym/console/application/cert_verify.py +++ b/pym/console/application/cert_verify.py @@ -14,13 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function -from __future__ import absolute_import import os import re import sys import OpenSSL -from .function import _print +from .function import _print, parse_error from calculate.core.datavars import DataVarsCore from calculate.lib.utils.files import readFile @@ -263,7 +261,7 @@ def rm_ca_from_trusted(ca_cert): try: os.unlink(filename) except OSError as e: - _print(e) + _print(parse_error(e)) else: newfile += (line + '\n') else: diff --git a/pym/console/application/cl_client.py b/pym/console/application/cl_client.py index 3c2b5b1..260e4a9 100644 --- a/pym/console/application/cl_client.py +++ b/pym/console/application/cl_client.py @@ -13,8 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function -from __future__ import absolute_import from calculate.core.server.local_call import Display, Methods, has_force_arg from calculate.lib.utils.tools import unpack_single_opts @@ -43,7 +41,7 @@ from calculate.core.datavars import DataVarsCore from .client_class import HTTPSClientCertTransport from .methods_func import call_method, get_method_argparser, parse, get_view from .function import (MessageReceiver, MessageDispatcher, clear, _print, - get_view_params) + get_view_params, parse_error) from calculate.lib.utils.files import makeDirectory, readLinesFile from calculate.lib.cl_lang import setLocalTranslate @@ -310,7 +308,7 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread): mr.analysis(method_result) # analysis(client, client.sid, method_result) except URLError as e: - _print(e) + _print(parse_error(e)) except KeyboardInterrupt: try: print() @@ -327,7 +325,7 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread): print(_("Failed to terminate the process")) mr.analysis(method_result) except Exception as e: - _print(e) + _print(parse_error(e)) try: mess = method_result[0][0] diff --git a/pym/console/application/function.py b/pym/console/application/function.py index 9b49ee6..04a74af 100644 --- a/pym/console/application/function.py +++ b/pym/console/application/function.py @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import time import os import sys @@ -37,6 +36,10 @@ setLocalTranslate('cl_console3', sys.modules[__name__]) def _print(*args): print(" ".join(map(str, args))) +def parse_error(e): + if hasattr(e, "message"): + return e.message + return e # get list of certificate and session id @@ -50,7 +53,7 @@ def clear(): try: os.unlink(filename) except OSError as e: - _print(e) + _print(parse_error(e)) except Exception: print(_("Failed to clear the cache! ")) return 1 @@ -338,3 +341,5 @@ class MessageDispatcher(object): def ask_password(self, message): answer = self.methods.askPassword(message.message, message.id == 2) self.parent.send_message(answer) + + diff --git a/pym/console/application/methods_func.py b/pym/console/application/methods_func.py index 8976301..b4b3d69 100644 --- a/pym/console/application/methods_func.py +++ b/pym/console/application/methods_func.py @@ -14,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# from __future__ import print_function -# from __future__ import absolute_import import argparse import sys from calculate.core.server.api_types import ViewInfoAdapter diff --git a/pym/console/application/pid_information.py b/pym/console/application/pid_information.py index bae8ce9..c70a636 100644 --- a/pym/console/application/pid_information.py +++ b/pym/console/application/pid_information.py @@ -13,7 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function from .function import _print import sys diff --git a/pym/console/application/sid_func.py b/pym/console/application/sid_func.py index e4b4ad0..68f8fa2 100644 --- a/pym/console/application/sid_func.py +++ b/pym/console/application/sid_func.py @@ -13,7 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import os import sys @@ -60,7 +59,7 @@ def client_session_info(client, sid=None): and e[1] == 'Forbidden': print(_("Access forbidden!")) else: - print(e) + _print(parseError(e)) return 1 @@ -74,7 +73,7 @@ def client_session_list(client): and e[1] == 'Forbidden': print(_("Access forbidden!")) else: - print(e) + _print(parseError(e)) return 1 if hasattr(res, 'string'): if res.string: @@ -98,7 +97,7 @@ def session_clean(client): and e[1] == 'Forbidden': print(_("Access forbidden!")) else: - print(e) + _print(parseError(e)) class SessionId():