General py3 changes, encoding fixes

master
idziubenko 3 years ago
parent 2bb7a6366f
commit a782c69cd6

@ -24,7 +24,7 @@ import sys
class ArgumentParserCheck(argparse.ArgumentParser):
def __init__(self):
super(ArgumentParserCheck, self).__init__(
super().__init__(
description="Check user for admin certificate")
self.add_argument('user', nargs=1, metavar="USER", help='username')

@ -21,7 +21,7 @@ from calculate.core.setup_cache import Cache
class ArgumentParserCache(argparse.ArgumentParser):
def __init__(self):
super(ArgumentParserCache, self).__init__(
super().__init__(
description="Recalculate package cache")
self.add_argument('--force', action="store_true",
help='skip check mtime')

@ -22,7 +22,7 @@ import re
class ArgumentParserVariable(argparse.ArgumentParser):
def __init__(self):
super(ArgumentParserVariable, self).__init__(
super().__init__(
description="Fast variable getter")
group = self.add_mutually_exclusive_group(required=True)
group.add_argument('--value', nargs="+",

@ -284,7 +284,7 @@ class Backup(MethodsInterface):
try:
for fn in find(source_etc_dn, filetype=FindFileType.RegularFile):
if (not reCfg.search(fn) and
" Modified Calculate" in readFileEx(fn,
b" Modified Calculate" in readFileEx(fn,
headbyte=300)):
self.backup_file(fn, root_dn, prefix=source_dn)
except (OSError, IOError) as e:

@ -115,7 +115,7 @@ def listToArrayArray(client, _list, _type='string'):
return array_array
class switch(object):
class switch():
def __init__(self, value):
self.value = value
self.fall = False

@ -98,7 +98,7 @@ def echo_on(f):
return wrapper
class TaskState(object):
class TaskState():
"""
Текущее состояние вывода сообщений
"""
@ -348,15 +348,15 @@ class CleanState(TaskState):
self.parent.addProgress()
def printERROR(self, message):
super(CleanState, self).printERROR(message)
super().printERROR(message)
self.parent.printer('\n')
def printSUCCESS(self, message):
super(CleanState, self).printSUCCESS(message)
super().printSUCCESS(message)
self.parent.printer('\n')
def printWARNING(self, message):
super(CleanState, self).printWARNING(message)
super().printWARNING(message)
self.parent.printer('\n')
@ -590,7 +590,7 @@ class ProgressState(StartState):
self.state.printWARNING(message)
class ResultViewer(object):
class ResultViewer():
"""
Просмотрщик результатов
"""

@ -49,7 +49,7 @@ class ProgressStateGui(ProgressState):
self.parent.set_progressbar(None)
class ResultViewerDecorator(object):
class ResultViewerDecorator():
def __init__(self, rv):
self.rv = rv
for v in self.rv.states.values():
@ -65,7 +65,7 @@ class ProgressGui(ResultViewerDecorator):
"""
def __init__(self, rv):
super(ProgressGui, self).__init__(rv)
super().__init__(rv)
self.rv.states['pre-progress'] = PreProgressStateGui(self)
self.rv.states['progress'] = ProgressStateGui(self)
self.progress_title = ""
@ -84,7 +84,7 @@ class ErrorGui(ResultViewerDecorator):
"""
def __init__(self, rv):
super(ErrorGui, self).__init__(rv)
super().__init__(rv)
self.messages = []
def show_messages(self):
@ -108,7 +108,7 @@ class WarningGui(ResultViewerDecorator):
"""
def __init__(self, rv):
super(WarningGui, self).__init__(rv)
super().__init__(rv)
self.warnings = []
def show_messages(self):

@ -55,7 +55,7 @@ class CommonInfo(ComplexModel):
Default = Array(String)
CheckAll = Boolean
class LazyString(object):
class LazyString():
pass
@ -114,7 +114,7 @@ class ChoiceValue(DataVarsSerializer):
def __init__(self, dv=None, varObj=None, readOnly=False, **kwargs):
if dv:
super(ChoiceValue, self).__init__()
super().__init__()
if not readOnly:
self.values, self.comments = self.getChoice(varObj)
elif isinstance(varObj, SourceReadonlyVariable):
@ -134,7 +134,7 @@ class ChoiceValue(DataVarsSerializer):
else:
self.typefield = "text"
else:
super(ChoiceValue, self).__init__(**kwargs)
super().__init__(**kwargs)
def elementByType(self, typeobj):
"""Get element by variable type, given for table or not"""
@ -163,7 +163,7 @@ class Table(DataVarsSerializer):
varObj=None, head=None, body=None, values=None,
fields=None, onClick=None, addAction=None, step=None,
records=None):
super(Table, self).__init__()
super().__init__()
if dv:
self.head = []
@ -210,7 +210,7 @@ class Option(DataVarsSerializer):
help = String(default=None, min_occurs=1)
def __init__(self, optlist, metaval, helpval, syntax=""):
super(Option, self).__init__()
super().__init__()
self.help = helpval
self.metavalue = metaval
self.syntax = syntax
@ -244,7 +244,7 @@ class Field(DataVarsSerializer):
briefmode - view request for brief, inbrief - variable palced in brief,
"""
if dv:
super(Field, self).__init__()
super().__init__()
self.name = varObj.name
self.type = varObj.type
if varObj.opt:
@ -299,7 +299,7 @@ class Field(DataVarsSerializer):
# if self.value:
# self.default = self.value
else:
super(Field, self).__init__(**kwargs)
super().__init__(**kwargs)
class GroupField(DataVarsSerializer):
@ -312,7 +312,7 @@ class GroupField(DataVarsSerializer):
def __init__(self, name="", fields=list(), prevlabel="",
nextlabel="", last=False, dv=None, info=None,
expert=False, brief=False, onlyhelp=False):
super(GroupField, self).__init__()
super().__init__()
self.last = last
if dv:
self.name = info['name']
@ -403,7 +403,7 @@ class ViewInfo(DataVarsSerializer):
def __init__(self, datavars=None, step=None, expert=None, allsteps=False,
brief=None, brief_label=None, has_brief=False, groups=list(),
viewparams=None):
super(ViewInfo, self).__init__()
super().__init__()
onlyhelp = False
if viewparams:
# for compatible specifing step by param
@ -507,7 +507,7 @@ class ReturnedMessage(ComplexModel):
def __init__(self, type=None, field=None, message=None,
expert=False, field_obj=None):
super(ReturnedMessage, self).__init__()
super().__init__()
self.type = type
self.field = field
self.message = message
@ -528,7 +528,7 @@ class Message(ComplexModel):
def __init__(self, message_type='normal', message=None, id=None,
result=None, onlyShow=None, default=None):
super(Message, self).__init__()
super().__init__()
self.type = message_type
self.message = message
self.id = id
@ -545,7 +545,7 @@ class ReturnProgress(ComplexModel):
def __init__(self, percent=0, short_message=None, long_message=None,
control=None):
super(ReturnProgress, self).__init__()
super().__init__()
self.percent = percent
self.short_message = short_message
self.long_message = long_message
@ -758,7 +758,7 @@ class CoreWsdl(CoreServiceInterface):
class WsdlAdapter(object):
class WsdlAdapter():
adapted_class = None
def __init__(self, source):

@ -17,7 +17,7 @@ from calculate.lib.datavars import DataVars
import calculate.contrib
from spyne import Service
class CoreServiceInterface(object):
class CoreServiceInterface():
########
# Fields
########
@ -322,7 +322,7 @@ class CoreServiceInterface(object):
raise NotImplementedError
class MethodsInterface(object):
class MethodsInterface():
clVars = DataVars()
method_name = None

@ -24,7 +24,7 @@ from calculate.lib.utils.text import _u8
from M2Crypto import m2
from M2Crypto.X509 import X509_Extension
from calculate.lib.utils.files import writeFileBin, readFile
from calculate.lib.utils.files import writeFile, readFile
from ctypes import *
@ -142,7 +142,7 @@ def create_selfsigned_ca(dn_data, keyfile, certfile):
ca.add_extensions([crypto.X509Extension(b'authorityKeyIdentifier', False, b'keyid:always',issuer=ca)])
ca.sign(pkey, 'sha1')
with writeFileBin(certfile) as f:
with writeFile(certfile, binary=True) as f:
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, ca))
except crypto.Error as e:
raise CreateCertError(str(e))
@ -184,7 +184,7 @@ def sign_client_certifacation_request(ca_keyfile, ca_certfile, requestfile, out_
])
cert.sign(pkey, 'sha1')
with writeFileBin(out_cert) as f:
with writeFile(out_cert, binary=True) as f:
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
except crypto.Error as e:
raise CreateCertError(str(e))

@ -108,6 +108,7 @@ class CommonMethods(MethodsInterface):
if orig_content == new_content:
answ = "use new"
else:
print("DEBUG dispatch conf")
for i, s in enumerate(list(process("diff", "-Nu",
orig, data[i_cfgname]))):
s = convert_console_to_xml(s)
@ -128,7 +129,7 @@ class CommonMethods(MethodsInterface):
continue
elif answ == "use new":
try:
with open(orig, 'w') as fd:
with open(orig, 'w', encoding="UTF-8") as fd:
fd.write(readFile(data[i_cfgname]))
os.unlink(data[i_cfgname])
if filesApply:
@ -221,7 +222,7 @@ class CommonMethods(MethodsInterface):
return True
class CommonLink(object):
class CommonLink():
"""
Объект-связка объектов тип Install,Client,Action с Common объектом
"""
@ -245,7 +246,7 @@ class ActionError(Exception):
pass
class Tasks(object):
class Tasks():
"""
Класс для создания проверок необходимости запуска задачи в зависимости
от результатра работы предыдущих задач
@ -497,7 +498,7 @@ class Action(MethodsInterface):
Вставить значения переменных в текст сообщения
"""
class TextTrasformer(object):
class TextTrasformer():
@staticmethod
def first_letter_upper(s):
@ -621,7 +622,7 @@ class Action(MethodsInterface):
def run(self, objs, dv):
"""Запустить список действий"""
class StubLogger(object):
class StubLogger():
def info(self, s):
pass
@ -886,7 +887,7 @@ def shortTraceback(e1, e2, e3):
return "%s:%s(%s:%s)" % (e1.__name__, str(e2), modname, frame.tb_lineno)
class ActiveClientStatus(object):
class ActiveClientStatus():
Success = 0
Failed = 1
WrongSID = 2
@ -1863,7 +1864,7 @@ def clearDataVars(func):
return wrapper
class CustomButton(object):
class CustomButton():
@classmethod
def sort_argv(cls, args):
behavior = []
@ -1889,7 +1890,7 @@ class CustomButton(object):
def next_button(cls, id=None, label=None):
return id, label, None, "button_next"
class Behavior(object):
class Behavior():
@classmethod
def link(cls, source=None, target=None):
return "%s=%s" % (target, source)

@ -29,7 +29,7 @@ import socket
from .cert_cmd import find_cert_id
class ProcessStatus(object):
class ProcessStatus():
SuccessFinished = 0
Worked = 1
FailedFinished = 2
@ -37,7 +37,7 @@ class ProcessStatus(object):
Paused = 4
class ProcessMode(object):
class ProcessMode():
CoreDaemon = "core"
LocalCall = "local"

@ -45,11 +45,7 @@ class Groups(MethodsInterface):
body = []
fields = ['cl_core_group', '']
print("DEBUG show groups meth")
print(list_group_name)
for group in list_group_name[page_offset:page_offset + page_count]:
print("(for) ", group)
dv.Set('cl_core_group', group)
group_rights = ', '.join(dv.Get('cl_core_group_rights'))
body.append([group, group_rights])

@ -17,7 +17,7 @@
from collections import defaultdict
class LoadedMethods(object):
class LoadedMethods():
conMethods = {}
guiMethods = {}
rightsMethods = {}

@ -53,7 +53,7 @@ _ = lambda x: x
setLocalTranslate('cl_core3', sys.modules[__name__])
class LocalCall(object):
class LocalCall():
method_status = ProcessStatus.NotFound
no_progress = None
gui_progress = None
@ -449,7 +449,7 @@ def print_brief(view, brief_label):
class ColorTable(tableReport):
def __init__(self, head, body, printer, head_printer=None,
line_printer=None, body_printer=None):
super(ColorTable, self).__init__(None, head, body, colSpan=0)
super().__init__(None, head, body, colSpan=0)
self.default_printer = printer
self.line_printer = line_printer or printer
self.head_printer = head_printer or printer
@ -458,7 +458,7 @@ class ColorTable(tableReport):
self.body = body
class Display(object):
class Display():
def __init__(self):
self._print = get_terminal_print(color_print().defaultPrint)
@ -505,7 +505,7 @@ class Display(object):
self._print("\n")
class InformationElement(object):
class InformationElement():
def __init__(self, field, display):
self.value = ""
self.label = ""
@ -540,14 +540,14 @@ class InformationElement(object):
class ValueInfo(InformationElement):
def __init__(self, field, display):
super(ValueInfo, self).__init__(field, display)
super().__init__(field, display)
self.value = field.value or ''
self.label = field.label
class CheckInfo(InformationElement):
def __init__(self, field, display):
super(CheckInfo, self).__init__(field, display)
super().__init__(field, display)
self.label = field.label
map_answer = {'on': _('yes'), 'off': _("no"), 'auto': _('auto')}
self.value = map_answer.get(field.value, field.value)
@ -555,7 +555,7 @@ class CheckInfo(InformationElement):
class ChoiceInfo(InformationElement):
def __init__(self, field, display):
super(ChoiceInfo, self).__init__(field, display)
super().__init__(field, display)
self.label = field.label or ''
if field.choice and field.comments:
map_comment = dict(zip(field.choice, field.comments))
@ -566,7 +566,7 @@ class ChoiceInfo(InformationElement):
class MultiChoiceInfo(InformationElement):
def __init__(self, field, display):
super(MultiChoiceInfo, self).__init__(field, display)
super().__init__(field, display)
self.label = field.label or ''
if field.listvalue:
value = field.listvalue
@ -584,7 +584,7 @@ class MultiChoiceInfo(InformationElement):
class ErrorInfo(InformationElement):
def __init__(self, field, display):
super(ErrorInfo, self).__init__(field, display)
super().__init__(field, display)
self.label = field.label
def show(self):
@ -607,7 +607,7 @@ class TableInfo(InformationElement):
yield cell or ""
def __init__(self, field, display):
super(TableInfo, self).__init__(field, display)
super().__init__(field, display)
self.label = field.label
self.head = field.tablevalue.head
@ -651,7 +651,7 @@ class Methods(LocalCall.Common, object):
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(Methods, cls).__new__(
cls._instance = super().__new__(
cls, *args, **kwargs)
return cls._instance

@ -51,7 +51,7 @@ class BoolAction(argparse.Action):
def __init__(self, option_strings, dest, nargs="?",
const=None, default=None, type=None, choices=None,
required=False, help=None, metavar=None):
super(BoolAction, self).__init__(
super().__init__(
option_strings=option_strings, dest=dest,
nargs=nargs, const=const, default=default,
type=type, choices=choices, required=required,

@ -49,7 +49,7 @@ not_log_list = ['post_server_request', 'post_client_request', 'del_sid',
class ClApplication(WsgiApplication):
def __init__(self, app, log=None):
super(ClApplication, self).__init__(app)
super().__init__(app)
# add object logging
self.log = logger
@ -389,7 +389,7 @@ class ClApplication(WsgiApplication):
finger, ip,
method_name[5:]))
return super(ClApplication, self).handle_rpc(req_env, start_response)
return super().handle_rpc(req_env, start_response)
class OpenSSLAdapter(pyOpenSSLAdapter):
def verify_func(self, connection, x509, errnum, errdepth, ok):

@ -27,7 +27,7 @@ from calculate.lib.utils.files import readFile, writeFile
get_pkgname_by_filename = templateFunction.get_pkgname_by_filename
class Cache(object):
class Cache():
reMerge = re.compile(r"(merge|mergepkg)\(([-\w/]*)(?:\[[^\]]\])?\)[-!=<>]")
rePatch = re.compile(r"^#\s*Calculate.*ac_install_patch==on")

@ -22,7 +22,7 @@ from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_core3', sys.modules[__name__])
class Actions(object):
class Actions():
Restore = "restore"
Service = "service"

@ -63,18 +63,12 @@ class VariableClCoreGroup(Variable):
'digits and underline symbols') + '\n' +
_('The group name must consist of 2 to 20 symbols'))
group_rights = self.Get('cl_core_group_rights_path')
print("DEBUG GROUP")
print(group_rights)
print(group)
if group == 'all':
return
t = readFile(group_rights)
print(t)
find = False
for line in t.splitlines():
print("line: ", line)
words = line.split()
print("words: ", words)
if not words or words[0].startswith('#'):
continue
if group == words[0]:

@ -29,7 +29,7 @@ from calculate.lib.utils.files import listDirectory
from itertools import *
class VarHelper(object):
class VarHelper():
aliases = (('main', 'lib'),)
mapName = dict(aliases)
mapMethod = {'importLib': 'importVariables',

Loading…
Cancel
Save