added more py3 related changes

master
idziubenko 3 years ago
parent 584bc7da9f
commit 940b125820

6
.gitignore vendored

@ -0,0 +1,6 @@
revert_changes_to_vmachine
push_to_vmachine*
.vscode
*.pyc
*.pyo
*.bak

@ -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()

@ -22,8 +22,8 @@ import logging
from calculate.console.application.client_class import Client_suds from calculate.console.application.client_class import Client_suds
import os import os
import sys import sys
# import urllib2
import urllib.request as urllib2 import urllib.request as urllib2
from urllib.error import URLError
from calculate.core.datavars import DataVarsCore from calculate.core.datavars import DataVarsCore
from calculate.core.client.function import clear from calculate.core.client.function import clear
from calculate.consolegui.application.client_class import ( 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) client.wsdl.services[0].setlocation(url)
server_host_name = client.service.get_server_host_name() server_host_name = client.service.get_server_host_name()
del client del client
except (urllib2.URLError, TransportError) as e: except (URLError, TransportError) as e:
log.debug(_('Failed to connect', ) + _(': ') + str(e)) log.debug(_('Failed to connect', ) + _(': ') + str(e))
return [] return []
except KeyboardInterrupt: except KeyboardInterrupt:

@ -16,13 +16,13 @@
from __future__ import print_function from __future__ import print_function
from __future__ import absolute_import from __future__ import absolute_import
import urllib2 as u2 import urllib.request as u2
import os import os
import sys import sys
import calculate.contrib import calculate.contrib
from suds.transport.http import HttpTransport from suds.transport.http import HttpTransport
import httplib #http.client in python3 import httplib.client #http.client in python3
from httplib import HTTPConnection from httplib.client import HTTPConnection
import socket import socket
import ssl import ssl
import hashlib import hashlib

@ -17,8 +17,7 @@
# from server.cl_server import main # from server.cl_server import main
# print(main) # print(main)
from __future__ import print_function from importlib import reload
from __future__ import absolute_import
def core_main(): def core_main():
import sys import sys

@ -261,7 +261,7 @@ class TaskState(object):
i_value, i_comment = 0, 1 i_value, i_comment = 0, 1
answerByChar = map(lambda x: x[i_value][firstletter], answers) 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 use_getch = False
sa = slice(0, None) sa = slice(0, None)
else: else:
@ -287,8 +287,8 @@ class TaskState(object):
printer("\n") printer("\n")
raise KeyboardInterrupt raise KeyboardInterrupt
ask = ask.lower() ask = ask.lower()
like_answers = filter(lambda x: x[i_value].startswith(ask), like_answers = list(filter(lambda x: x[i_value].startswith(ask),
answers) answers))
if not like_answers: if not like_answers:
self.state.printERROR(_('The answer is uncertain')) self.state.printERROR(_('The answer is uncertain'))
continue continue

@ -21,7 +21,7 @@ from calculate.lib.utils.text import _u8
import re import re
from os import path from os import path
from calculate.lib.cl_lang import getLazyLocalTranslate, setLocalTranslate from calculate.lib.cl_lang import getLazyLocalTranslate, setLocalTranslate
from collections import MutableMapping from collections.abc import MutableMapping
_ = lambda x: x _ = lambda x: x
setLocalTranslate('cl_core3', sys.modules[__name__]) setLocalTranslate('cl_core3', sys.modules[__name__])

@ -29,7 +29,6 @@ from calculate.lib.utils import ip as ip
from calculate.core.datavars import DataVarsCore from calculate.core.datavars import DataVarsCore
from calculate.lib.utils.files import readFile from calculate.lib.utils.files import readFile
from calculate.lib.utils.text import _u8 from calculate.lib.utils.text import _u8
# import urllib2 as u2
import urllib.request as u2 import urllib.request as u2
if hasattr(u2, "ssl"): if hasattr(u2, "ssl"):
@ -176,7 +175,7 @@ def check_server_certificate(cert, key, cert_path, args, port, auto=False):
import calculate.contrib import calculate.contrib
from suds.client import Client from suds.client import Client
from .client_class import HTTPSClientsCertTransport from .client_class import HTTPSClientsCertTransport
from urllib2 import URLError from urllib.error import URLError
try: try:
client = Client(url, transport=HTTPSClientsCertTransport( client = Client(url, transport=HTTPSClientsCertTransport(

@ -46,7 +46,9 @@ _('No module named %s')
@clearDataVars @clearDataVars
def main(*args, **keywords): def main(*args, **keywords):
_args = list(unpack_single_opts(sys.argv[1:])) _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) parser = cert_cmd.parse(full=False)
args, unknown_args = parser.parse_known_args(_args) args, unknown_args = parser.parse_known_args(_args)
args.method = '_temp_' args.method = '_temp_'
@ -139,7 +141,7 @@ def main(*args, **keywords):
except IOError: except IOError:
pass pass
from urllib2 import URLError from urllib.error import URLError
from traceback import print_exc from traceback import print_exc
@ -208,7 +210,7 @@ def main(*args, **keywords):
serv_certbase, certbase, data_path) serv_certbase, certbase, data_path)
return 0 return 0
except BaseException as e: except BaseException as e:
from urllib2 import URLError from urllib.error import URLError
if isinstance(e, URLError) and log_filename: if isinstance(e, URLError) and log_filename:
if file_logger: if file_logger:

@ -15,7 +15,7 @@
# limitations under the License. # limitations under the License.
from __future__ import print_function from __future__ import print_function
import urllib2 as u2 import urllib.request as u2
import os import os
import sys import sys
import calculate.contrib import calculate.contrib

@ -76,8 +76,8 @@ class CommonMethods(MethodsInterface):
i_orig, i_data = 0, 1 i_orig, i_data = 0, 1
i_mime, i_cfgname = 0, 1 i_mime, i_cfgname = 0, 1
cfg_files = getCfgFiles(prefix=prefix).items() cfg_files = getCfgFiles(prefix=prefix).items()
info = filter(lambda x: (filesApply is None or info = list(filter(lambda x: (filesApply is None or
x[i_data][0][i_cfgname] in filesApply), x[i_data][0][i_cfgname] in filesApply)),
cfg_files) cfg_files)
max_info = len(info) max_info = len(info)
for ind, data in enumerate(info): for ind, data in enumerate(info):

@ -186,7 +186,10 @@ def local_method(metaObject, args, unknown_args):
""" """
import os 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 != 'cl-core':
if sym_link in LoadedMethods.conMethods.keys(): if sym_link in LoadedMethods.conMethods.keys():
args.method = LoadedMethods.conMethods[sym_link][0] args.method = LoadedMethods.conMethods[sym_link][0]
@ -220,6 +223,7 @@ def local_method(metaObject, args, unknown_args):
try: try:
view = getattr(metaObject, method_view_name)(metaObject, 0, view_obj) view = getattr(metaObject, method_view_name)(metaObject, 0, view_obj)
except AttributeError: except AttributeError:
print("DE")
colorPrint.printERROR(_('Method not found: ') + method_view_name) colorPrint.printERROR(_('Method not found: ') + method_view_name)
return 1 return 1
try: try:
@ -266,6 +270,9 @@ def call_method(metaObject, args, unknown_args, colorPrint):
""" """
Function for call method through metaObject and args Function for call method through metaObject and args
""" """
print("METHODCALL")
print(metaObject)
print(dir(metaObject))
method_name = args.method method_name = args.method
stdin_passwd = args.stdin_passwd stdin_passwd = args.stdin_passwd
method_view_name = method_name + '_view' method_view_name = method_name + '_view'

@ -200,7 +200,7 @@ def get_method_argparser(view, args, cl_core=False):
prog=progr, add_help=False, formatter_class=RawAndDefaultsHelpFormatter) prog=progr, add_help=False, formatter_class=RawAndDefaultsHelpFormatter)
parser.fixBoolVariables = fix_bool_variables 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) group = parser.add_argument_group(Group.name)
for field in get_list(Group.fields): for field in get_list(Group.fields):
if field.element == 'error': 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: if hasattr(field.opt, "syntax") and field.opt.syntax:
reArgs = re.compile(field.opt.syntax) reArgs = re.compile(field.opt.syntax)
# check for correct sentense # 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 Error on wrong
raise ValueError(_("Wrong %s value syntax") % raise ValueError(_("Wrong %s value syntax") %
(field.opt.shortopt or field.opt.longopt) (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 = field.tablevalue.values.ChoiceValue
choiceValue = filter(lambda x: x.typefield != 'readonly', choiceValue) choiceValue = filter(lambda x: x.typefield != 'readonly', choiceValue)
lenChoiceValue = len(choiceValue) lenChoiceValue = len(choiceValue)
for wrong in ifilter(lambda x: len(x) > lenChoiceValue, for wrong in filter(lambda x: len(x) > lenChoiceValue,
val_table): val_table):
if type(wrong) in (list, tuple): if type(wrong) in (list, tuple):
wrong = ":".join(wrong) wrong = ":".join(wrong)

@ -34,10 +34,10 @@ class Variables(MethodsInterface):
Write variable to env files, or delete from env files Write variable to env files, or delete from env files
""" """
dv = self.clVars dv = self.clVars
data = filter(lambda x: x[LOCATION] or data = list(filter(lambda x: x[LOCATION] or
not x[LOCATION] and not x[LOCATION] and
dv.isFromIni(x[VARIABLE]), dv.isFromIni(x[VARIABLE]),
vardata) vardata))
if data: if data:
head = [_("Variable"), _("Mode"), _("Location"), _("Value")] head = [_("Variable"), _("Mode"), _("Location"), _("Value")]
self.printTable(_("List of variables"), head, data) self.printTable(_("List of variables"), head, data)

Loading…
Cancel
Save