From 940b125820d20acd045a1913565c9ebef8a2dc24 Mon Sep 17 00:00:00 2001 From: idziubenko Date: Tue, 13 Jul 2021 10:27:37 +0300 Subject: [PATCH] added more py3 related changes --- .gitignore | 6 ++++++ bin/cl-core_py3 | 21 +++++++++++++++++++++ pym/core/client/cert_info.py | 4 ++-- pym/core/client/client_class.py | 6 +++--- pym/core/core_main.py | 3 +-- pym/core/result_viewer.py | 6 +++--- pym/core/server/admin.py | 2 +- pym/core/server/cert_cmd.py | 3 +-- pym/core/server/cl_server.py | 8 +++++--- pym/core/server/client_class.py | 2 +- pym/core/server/func.py | 4 ++-- pym/core/server/local_call.py | 9 ++++++++- pym/core/server/methods_func.py | 6 +++--- pym/core/set_vars.py | 4 ++-- 14 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 .gitignore create mode 100644 bin/cl-core_py3 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35ea017 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +revert_changes_to_vmachine +push_to_vmachine* +.vscode +*.pyc +*.pyo +*.bak \ No newline at end of file diff --git a/bin/cl-core_py3 b/bin/cl-core_py3 new file mode 100644 index 0000000..070c337 --- /dev/null +++ b/bin/cl-core_py3 @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright 2012-2016 Mir Calculate. http://www.calculate-linux.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +import calculate.core.core_main as core_main + +if __name__ == '__main__': + core_main.core_main() diff --git a/pym/core/client/cert_info.py b/pym/core/client/cert_info.py index 4916f92..a55ef5b 100644 --- a/pym/core/client/cert_info.py +++ b/pym/core/client/cert_info.py @@ -22,8 +22,8 @@ import logging from calculate.console.application.client_class import Client_suds import os import sys -# import urllib2 import urllib.request as urllib2 +from urllib.error import URLError from calculate.core.datavars import DataVarsCore from calculate.core.client.function import clear from calculate.consolegui.application.client_class import ( @@ -81,7 +81,7 @@ def get_certifactions_for_host(host, use_dbus=False): client.wsdl.services[0].setlocation(url) server_host_name = client.service.get_server_host_name() del client - except (urllib2.URLError, TransportError) as e: + except (URLError, TransportError) as e: log.debug(_('Failed to connect', ) + _(': ') + str(e)) return [] except KeyboardInterrupt: diff --git a/pym/core/client/client_class.py b/pym/core/client/client_class.py index 36eef79..30fb7b8 100644 --- a/pym/core/client/client_class.py +++ b/pym/core/client/client_class.py @@ -16,13 +16,13 @@ from __future__ import print_function from __future__ import absolute_import -import urllib2 as u2 +import urllib.request as u2 import os import sys import calculate.contrib from suds.transport.http import HttpTransport -import httplib #http.client in python3 -from httplib import HTTPConnection +import httplib.client #http.client in python3 +from httplib.client import HTTPConnection import socket import ssl import hashlib diff --git a/pym/core/core_main.py b/pym/core/core_main.py index ffed785..f85ce19 100644 --- a/pym/core/core_main.py +++ b/pym/core/core_main.py @@ -17,8 +17,7 @@ # from server.cl_server import main # print(main) -from __future__ import print_function -from __future__ import absolute_import +from importlib import reload def core_main(): import sys diff --git a/pym/core/result_viewer.py b/pym/core/result_viewer.py index 3b994d5..2b7b99d 100644 --- a/pym/core/result_viewer.py +++ b/pym/core/result_viewer.py @@ -261,7 +261,7 @@ class TaskState(object): i_value, i_comment = 0, 1 answerByChar = map(lambda x: x[i_value][firstletter], answers) - if filter(lambda x: answerByChar.count(x) > 1, answerByChar): + if list(filter(lambda x: answerByChar.count(x) > 1, answerByChar)): use_getch = False sa = slice(0, None) else: @@ -287,8 +287,8 @@ class TaskState(object): printer("\n") raise KeyboardInterrupt ask = ask.lower() - like_answers = filter(lambda x: x[i_value].startswith(ask), - answers) + like_answers = list(filter(lambda x: x[i_value].startswith(ask), + answers)) if not like_answers: self.state.printERROR(_('The answer is uncertain')) continue diff --git a/pym/core/server/admin.py b/pym/core/server/admin.py index 3dceed6..a6caea1 100644 --- a/pym/core/server/admin.py +++ b/pym/core/server/admin.py @@ -21,7 +21,7 @@ from calculate.lib.utils.text import _u8 import re from os import path from calculate.lib.cl_lang import getLazyLocalTranslate, setLocalTranslate -from collections import MutableMapping +from collections.abc import MutableMapping _ = lambda x: x setLocalTranslate('cl_core3', sys.modules[__name__]) diff --git a/pym/core/server/cert_cmd.py b/pym/core/server/cert_cmd.py index b7fc968..145f051 100644 --- a/pym/core/server/cert_cmd.py +++ b/pym/core/server/cert_cmd.py @@ -29,7 +29,6 @@ from calculate.lib.utils import ip as ip from calculate.core.datavars import DataVarsCore from calculate.lib.utils.files import readFile from calculate.lib.utils.text import _u8 -# import urllib2 as u2 import urllib.request as u2 if hasattr(u2, "ssl"): @@ -176,7 +175,7 @@ def check_server_certificate(cert, key, cert_path, args, port, auto=False): import calculate.contrib from suds.client import Client from .client_class import HTTPSClientsCertTransport - from urllib2 import URLError + from urllib.error import URLError try: client = Client(url, transport=HTTPSClientsCertTransport( diff --git a/pym/core/server/cl_server.py b/pym/core/server/cl_server.py index daab782..3a207f8 100644 --- a/pym/core/server/cl_server.py +++ b/pym/core/server/cl_server.py @@ -46,7 +46,9 @@ _('No module named %s') @clearDataVars def main(*args, **keywords): _args = list(unpack_single_opts(sys.argv[1:])) - if os.path.basename(sys.argv[0]) != 'cl-core': + #TODO change back + # if os.path.basename(sys.argv[0]) != 'cl-core': + if False: parser = cert_cmd.parse(full=False) args, unknown_args = parser.parse_known_args(_args) args.method = '_temp_' @@ -139,7 +141,7 @@ def main(*args, **keywords): except IOError: pass - from urllib2 import URLError + from urllib.error import URLError from traceback import print_exc @@ -208,7 +210,7 @@ def main(*args, **keywords): serv_certbase, certbase, data_path) return 0 except BaseException as e: - from urllib2 import URLError + from urllib.error import URLError if isinstance(e, URLError) and log_filename: if file_logger: diff --git a/pym/core/server/client_class.py b/pym/core/server/client_class.py index 0296d19..80cb9e6 100644 --- a/pym/core/server/client_class.py +++ b/pym/core/server/client_class.py @@ -15,7 +15,7 @@ # limitations under the License. from __future__ import print_function -import urllib2 as u2 +import urllib.request as u2 import os import sys import calculate.contrib diff --git a/pym/core/server/func.py b/pym/core/server/func.py index 9366daf..9f4b9ab 100644 --- a/pym/core/server/func.py +++ b/pym/core/server/func.py @@ -76,8 +76,8 @@ class CommonMethods(MethodsInterface): i_orig, i_data = 0, 1 i_mime, i_cfgname = 0, 1 cfg_files = getCfgFiles(prefix=prefix).items() - info = filter(lambda x: (filesApply is None or - x[i_data][0][i_cfgname] in filesApply), + info = list(filter(lambda x: (filesApply is None or + x[i_data][0][i_cfgname] in filesApply)), cfg_files) max_info = len(info) for ind, data in enumerate(info): diff --git a/pym/core/server/local_call.py b/pym/core/server/local_call.py index 0148658..d706852 100644 --- a/pym/core/server/local_call.py +++ b/pym/core/server/local_call.py @@ -186,7 +186,10 @@ def local_method(metaObject, args, unknown_args): """ import os - sym_link = os.path.basename(sys.argv[0]) + # sym_link = os.path.basename(sys.argv[0]) + + #DEBUG - TODO remove this and uncomment thing above + sym_link = "cl-core" if sym_link != 'cl-core': if sym_link in LoadedMethods.conMethods.keys(): args.method = LoadedMethods.conMethods[sym_link][0] @@ -220,6 +223,7 @@ def local_method(metaObject, args, unknown_args): try: view = getattr(metaObject, method_view_name)(metaObject, 0, view_obj) except AttributeError: + print("DE") colorPrint.printERROR(_('Method not found: ') + method_view_name) return 1 try: @@ -266,6 +270,9 @@ def call_method(metaObject, args, unknown_args, colorPrint): """ Function for call method through metaObject and args """ + print("METHODCALL") + print(metaObject) + print(dir(metaObject)) method_name = args.method stdin_passwd = args.stdin_passwd method_view_name = method_name + '_view' diff --git a/pym/core/server/methods_func.py b/pym/core/server/methods_func.py index 7c60662..d547ca9 100644 --- a/pym/core/server/methods_func.py +++ b/pym/core/server/methods_func.py @@ -200,7 +200,7 @@ def get_method_argparser(view, args, cl_core=False): prog=progr, add_help=False, formatter_class=RawAndDefaultsHelpFormatter) parser.fixBoolVariables = fix_bool_variables - for Group in ifilter(lambda x: x.fields, get_list(view.groups)): + for Group in filter(lambda x: x.fields, get_list(view.groups)): group = parser.add_argument_group(Group.name) for field in get_list(Group.fields): if field.element == 'error': @@ -622,7 +622,7 @@ def collect_table(field, val_list, client, wait_thread=None, if hasattr(field.opt, "syntax") and field.opt.syntax: reArgs = re.compile(field.opt.syntax) # check for correct sentense - for wrong in ifilterfalse(reArgs.search, val_list): + for wrong in filterfalse(reArgs.search, val_list): # raise Error on wrong raise ValueError(_("Wrong %s value syntax") % (field.opt.shortopt or field.opt.longopt) @@ -642,7 +642,7 @@ def collect_table(field, val_list, client, wait_thread=None, choiceValue = field.tablevalue.values.ChoiceValue choiceValue = filter(lambda x: x.typefield != 'readonly', choiceValue) lenChoiceValue = len(choiceValue) - for wrong in ifilter(lambda x: len(x) > lenChoiceValue, + for wrong in filter(lambda x: len(x) > lenChoiceValue, val_table): if type(wrong) in (list, tuple): wrong = ":".join(wrong) diff --git a/pym/core/set_vars.py b/pym/core/set_vars.py index b2ccbe9..9cbc137 100644 --- a/pym/core/set_vars.py +++ b/pym/core/set_vars.py @@ -34,10 +34,10 @@ class Variables(MethodsInterface): Write variable to env files, or delete from env files """ dv = self.clVars - data = filter(lambda x: x[LOCATION] or + data = list(filter(lambda x: x[LOCATION] or not x[LOCATION] and dv.isFromIni(x[VARIABLE]), - vardata) + vardata)) if data: head = [_("Variable"), _("Mode"), _("Location"), _("Value")] self.printTable(_("List of variables"), head, data)