fixed process translation, images, password auth

Py3
idziubenko 3 years ago
parent 032364b614
commit dd347399a2

@ -114,11 +114,10 @@ class ControlButtonWgt(qt.QWidget):
# Set style # Set style
self.setAttribute(qt.Qt.WA_StyledBackground) self.setAttribute(qt.Qt.WA_StyledBackground)
self.setObjectName('ControlButton') self.setObjectName('ControlButton')
self.setStyleSheet("QWidget#ControlButton " self.setStyleSheet("QWidget#ControlButton "
"{background-color: rgb(255,0,0);}") "{background-color: %s;}"%
# self.setStyleSheet("QWidget#ControlButton " get_system_rgb(self, ParameterWindow))
# "{background-color: %s;}"%
# get_system_rgb(self, ParameterWindow))
self.main_layout = qt.QVBoxLayout(self) self.main_layout = qt.QVBoxLayout(self)
self.main_layout.setContentsMargins(28, 8, 0, 28) self.main_layout.setContentsMargins(28, 8, 0, 28)
@ -247,13 +246,12 @@ class ControlButtonWgt(qt.QWidget):
main_frame = self._parent.MainFrameWgt main_frame = self._parent.MainFrameWgt
self.cancel_button = qt.QPushButton(self) self.cancel_button = qt.QPushButton(self)
if main_frame.has_errors: if main_frame.has_errors:
# self.cancel_button.setText(_('Close').decode('utf-8'))
self.cancel_button.setText(_('Close')) self.cancel_button.setText(_('Close'))
else: else:
# self.cancel_button.setText(_('Cancel').decode('utf-8'))
self.cancel_button.setText(_('Cancel')) self.cancel_button.setText(_('Cancel'))
self.cancel_button.clicked.connect(self.button_disabled) self.cancel_button.clicked.connect(self.button_disabled)
self.cancel_button.clicked.connect(self.clear_method_cache) self.cancel_button.clicked.connect(self.clear_method_cache)
method_name = main_frame.method_name method_name = main_frame.method_name
self.cancel_button.clicked.connect( self.cancel_button.clicked.connect(
@ -415,8 +413,9 @@ class ControlButtonWgt(qt.QWidget):
res = self.ClientObj.client.service.clear_method_cache \ res = self.ClientObj.client.service.clear_method_cache \
(sid, method) (sid, method)
lerror = self.ClientObj.param_objects[method]['error'] lerror = self.ClientObj.param_objects[method]['error']
while len(lerror) > 0: if(lerror):
lerror.pop() while len(lerror) > 0:
lerror.pop()
except Exception as e: except Exception as e:
print(e) print(e)
from calculate.consolegui.application.ConnectionTabs \ from calculate.consolegui.application.ConnectionTabs \
@ -430,6 +429,7 @@ class ControlButtonWgt(qt.QWidget):
self._parent.back() self._parent.back()
def button_disabled(self): def button_disabled(self):
# if self.next_button: # if self.next_button:
# self.next_button.setDisabled(True) # self.next_button.setDisabled(True)
# if self.prev_button: # if self.prev_button:

@ -238,7 +238,6 @@ class DisplayMethod(qt.QWidget):
def onActivated(self): def onActivated(self):
print("DEBUG onActivated")
# Call server method # Call server method
if hasattr (self, 'onActivated_thread'): if hasattr (self, 'onActivated_thread'):
if self.onActivated_thread.isRunning(): if self.onActivated_thread.isRunning():
@ -263,7 +262,6 @@ class DisplayMethod(qt.QWidget):
str(method_name + '_view'), step = step, str(method_name + '_view'), step = step,
expert = expert, expert = expert,
brief = brief) brief = brief)
print(f"view_params: \n {view_params}")
self.onActivated_thread = ClientServiceThread(self.ClientObj, \ self.onActivated_thread = ClientServiceThread(self.ClientObj, \
str(method_name + '_view'), int(self.ClientObj.sid), \ str(method_name + '_view'), int(self.ClientObj.sid), \
view_params, return_except = True) view_params, return_except = True)
@ -275,9 +273,7 @@ class DisplayMethod(qt.QWidget):
#self.con_lost_lbl.hide() #self.con_lost_lbl.hide()
if type(view) == Exception: if type(view) == Exception:
print("DEBUG excpt")
print(view)
print(dir(view))
if hasattr (view, 'message'): if hasattr (view, 'message'):
view = view.message view = view.message

@ -14,12 +14,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import absolute_import # from __future__ import absolute_import
from calculate.consolegui import qt from calculate.consolegui import qt
from .pid_information import client_list_pid, client_pid_info from .pid_information import client_list_pid, client_pid_info
from .more import LabelWordWrap, show_msg, get_sid, ClientServiceThread from .more import LabelWordWrap, show_msg, get_sid, ClientServiceThread
class ViewProc(qt.QWidget): class ViewProc(qt.QWidget):
def __init__(self, parent, ClientObj): def __init__(self, parent, ClientObj):
@ -31,12 +30,11 @@ class ViewProc(qt.QWidget):
self.pid = 0 self.pid = 0
client_pid_info(ClientObj, ClientObj.client, 0) client_pid_info(ClientObj, ClientObj.client, 0)
list_pid = client_list_pid(self.ClientObj.client) list_pid = client_list_pid(self.ClientObj.client)
ClientObj._parent.setWindowTitle ( ClientObj._parent.setWindowTitle (
_('View information about the running processes')\ _('View information about the running processes')\
+ ' - ' + self.ClientObj.Name) + ' - ' + self.ClientObj.Name)
self.lable_list = [] self.label_list = []
self.button_list = [] self.button_list = []
self.status_list = [] self.status_list = []
self.grid_layout = qt.QGridLayout() self.grid_layout = qt.QGridLayout()
@ -57,9 +55,10 @@ class ViewProc(qt.QWidget):
else: else:
method_name = self.ClientObj.process_dict[str(list_pid[num])] \ method_name = self.ClientObj.process_dict[str(list_pid[num])] \
['name'] ['name']
method_name = str(method_name)
if method_name in self.ClientObj.method_names: if method_name in self.ClientObj.method_names:
view_method_name = self.ClientObj.method_names[method_name] view_method_name = str(self.ClientObj.method_names[method_name])
# try: # try:
# view_method_name = self.ClientObj.param_objects \ # view_method_name = self.ClientObj.param_objects \
# [method_name]['view_method_name'] # [method_name]['view_method_name']
@ -67,13 +66,13 @@ class ViewProc(qt.QWidget):
else: else:
view_method_name = method_name view_method_name = method_name
try: # try:
view_method_name = view_method_name.encode('utf-8') # view_method_name = view_method_name.encode('utf-8')
except (UnicodeEncodeError, UnicodeDecodeError): # except (UnicodeEncodeError, UnicodeDecodeError):
pass # pass
self.lable_list.append(LabelWordWrap(str(view_method_name), self)) self.label_list.append(LabelWordWrap(str(view_method_name), self))
self.grid_layout.addWidget(self.lable_list[num], num+2,0) self.grid_layout.addWidget(self.label_list[num], num+2,0)
# add start time process # add start time process
# del mircosec # del mircosec

@ -648,7 +648,7 @@ class HTTPSClientCertTransport(HttpTransport):
with open(key) as key_file: with open(key) as key_file:
client_keyobj = OpenSSL.crypto.load_privatekey \ client_keyobj = OpenSSL.crypto.load_privatekey \
(OpenSSL.SSL.FILETYPE_PEM, key_file.read(), (OpenSSL.SSL.FILETYPE_PEM, key_file.read(),
str(password)) password)
else: else:
import M2Crypto import M2Crypto
bio = M2Crypto.BIO.openfile(key) bio = M2Crypto.BIO.openfile(key)

@ -327,18 +327,17 @@ class FrameConnection(qt.QWidget):
bio = M2Crypto.BIO.openfile(CERT_KEY) bio = M2Crypto.BIO.openfile(CERT_KEY)
rsa = M2Crypto.m2.rsa_read_key(bio._ptr(), lambda *unused: b"") rsa = M2Crypto.m2.rsa_read_key(bio._ptr(), lambda *unused: b"")
if re_passwd != False: if re_passwd != False:
self.str_passwd = re_passwd self.str_passwd = re_passwd, "UTF-8"
if not rsa and not self.str_passwd and auto: if not rsa and not self.str_passwd and auto:
self.passwd_wgt = LocalhostPasswd(self) self.passwd_wgt = LocalhostPasswd(self)
passwd = self.passwd_wgt.text() passwd = self.passwd_wgt.text()
self.str_passwd = passwd if passwd else None self.str_passwd = passwd if passwd else None
try: try:
# if True: # if True:
self.ClientObj.client = Client_suds(url,\ self.ClientObj.client = Client_suds(url,\
transport = HTTPSClientCertTransport(CERT_KEY, \ transport = HTTPSClientCertTransport(CERT_KEY, \
CERT_FILE, path_to_cert, parent = self.ClientObj, \ CERT_FILE, path_to_cert, parent = self.ClientObj, \
timeout = 5, password = self.str_passwd)) timeout = 5, password = bytes(self.str_passwd, "UTF-8")))
self.ClientObj.client.wsdl.services[0].setlocation(url) self.ClientObj.client.wsdl.services[0].setlocation(url)
self.ClientObj.client.set_parameters \ self.ClientObj.client.set_parameters \
(path_to_cert, CERT_FILE, CERT_KEY) (path_to_cert, CERT_FILE, CERT_KEY)
@ -354,7 +353,6 @@ class FrameConnection(qt.QWidget):
print("OPENSSL ERROR") print("OPENSSL ERROR")
Connect_Error = 1 Connect_Error = 1
crypto_Error = 1 crypto_Error = 1
# DEBUGG uncomment this
# except Exception as e: # except Exception as e:
# print("GENERAL ERROR") # print("GENERAL ERROR")
# print(e) # print(e)

@ -23,7 +23,7 @@ from .more import LabelWordWrap, show_msg, get_icon
def passphrase_callback(v): def passphrase_callback(v):
if type(v) == int or not v: if type(v) == int or not v:
return "" return ""
return str(v) return bytes(v, "UTF-8")
def generateRSAKey(): def generateRSAKey():
from M2Crypto import RSA, m2 from M2Crypto import RSA, m2
@ -157,7 +157,7 @@ class RequestCreate (qt.QWidget):
callback = lambda *unused: "") callback = lambda *unused: "")
else: else:
pkey.save_key(self.key,\ pkey.save_key(self.key,\
callback= lambda *unused: str(private_key_passwd)) callback= lambda *unused: bytes(private_key_passwd, "UTF-8"))
######################################### #########################################
req = X509.Request() req = X509.Request()
req.set_version(req.get_version()) req.set_version(req.get_version())

@ -1598,11 +1598,11 @@ class MainFrame(qt.QWidget):
steps = field.tablevalue.head.string steps = field.tablevalue.head.string
icons = [] icons = []
print("---------------------------------------------------") # print("---------------------------------------------------")
print("DEBUG") # print("DEBUG")
print(field) # print(field)
print(dir(field)) # print(dir(field))
print(type(field)) # print(type(field))
if hasattr(field.listvalue, 'string'): if hasattr(field.listvalue, 'string'):
icons = field.listvalue.string icons = field.listvalue.string
val_steps = field.tablevalue.body.stringArray val_steps = field.tablevalue.body.stringArray

@ -2336,6 +2336,7 @@ def _print (*args):
def show_msg(text, title = None, parent = None): def show_msg(text, title = None, parent = None):
msgBox = qt.QMessageBox(parent) msgBox = qt.QMessageBox(parent)
#DEBUG: want traceback? force error there.
# raise Exception # raise Exception
if title: if title:
msgBox.setWindowTitle(title) msgBox.setWindowTitle(title)
@ -2344,16 +2345,19 @@ def show_msg(text, title = None, parent = None):
if not text: if not text:
return 1 return 1
if not type(text) in [str]: if not type(text) in [str]:
temp = ''
for i in text: if hasattr(text, '__iter__'):
#DEBUG: want traceback? force error there. #print(f'{text} is iterable')
# for i in str(text): temp = ''
try: for i in text:
# temp += str(i).decode('utf-8')+' ' try:
temp += str(i) + ' ' # temp += str(i).decode('utf-8')+' '
except (UnicodeEncodeError, UnicodeDecodeError): temp += str(i) + ' '
temp += str(i) + ' ' except (UnicodeEncodeError, UnicodeDecodeError):
text = temp temp += str(i) + ' '
text = temp
else:
text = str(text)
msgBox.setText(text) msgBox.setText(text)
msgBox.setStandardButtons(qt.QMessageBox.Ok) msgBox.setStandardButtons(qt.QMessageBox.Ok)
msgBox.setWindowIcon(get_icon('calculate-install.svg')) msgBox.setWindowIcon(get_icon('calculate-install.svg'))
@ -2648,7 +2652,6 @@ class ImageLabel(qt.QLabel):
image_conf = os.path.join(image_path, 'conf') image_conf = os.path.join(image_path, 'conf')
repeat_dict = {'no' : 'no-repeat', 'x' : 'repeat-x'} repeat_dict = {'no' : 'no-repeat', 'x' : 'repeat-x'}
for line in readLinesFile(image_conf): for line in readLinesFile(image_conf):
list_data = line.split() list_data = line.split()
if len (list_data) < 2: if len (list_data) < 2:
@ -2664,6 +2667,7 @@ class ImageLabel(qt.QLabel):
def resize_image(source_path, height, output_path): def resize_image(source_path, height, output_path):
convert_cmd = getProgPath('/usr/bin/convert') convert_cmd = getProgPath('/usr/bin/convert')
identify_cmd = getProgPath('/usr/bin/identify') identify_cmd = getProgPath('/usr/bin/identify')
def convert_image(source, res, target): def convert_image(source, res, target):
command = [convert_cmd, "-quality", "100", command = [convert_cmd, "-quality", "100",
source, "-resize", "%s" % res, source, "-resize", "%s" % res,
@ -2671,10 +2675,12 @@ class ImageLabel(qt.QLabel):
target] target]
#"-strip", "-gravity", "center", #"-strip", "-gravity", "center",
#"-crop", "%s+0+0" % res, target] #"-crop", "%s+0+0" % res, target]
convert = process(*command, stderr=STDOUT) convert = process(*command, stderr=STDOUT)
if convert.success(): if convert.success():
return True return True
return False return False
def get_image_resolution(source): def get_image_resolution(source):
identify = process(identify_cmd, "-format", "%w %h", source) identify = process(identify_cmd, "-format", "%w %h", source)
if identify.success(): if identify.success():
@ -2683,11 +2689,15 @@ class ImageLabel(qt.QLabel):
return int(swidth), int(sheight) return int(swidth), int(sheight)
return None, None return None, None
return None, None return None, None
cx, cy = get_image_resolution(source_path) cx, cy = get_image_resolution(source_path)
if cx and cy: if cx and cy:
if convert_image(source_path, "{}x{}".format(cx, height), if convert_image(source_path, "{}x{}".format(cx, height),
output_path): output_path):
return get_image_resolution(output_path) return get_image_resolution(output_path)
return None return None
if len(list_data) == 3: if len(list_data) == 3:

@ -337,7 +337,6 @@ def sslwrap(sock, server_side=False, keyfile=None, certfile=None,
key and cert not by filename, but from internal PyOpenSSL key and cert not by filename, but from internal PyOpenSSL
structures. structures.
""" """
print("DEBUG sslwrap")
ctx = OpenSSL.SSL.Context(_ssl_to_openssl_version_remap[ssl_version]) ctx = OpenSSL.SSL.Context(_ssl_to_openssl_version_remap[ssl_version])
if ca_certs: if ca_certs:
ctx.load_verify_locations(ca_certs) ctx.load_verify_locations(ca_certs)

@ -87,14 +87,4 @@ Signal = QtCore.pyqtSignal
# def handler(msg_type, msg_log_context, msg_string): # def handler(msg_type, msg_log_context, msg_string):
# pass # pass
# QtCore.qInstallMessageHandler(handler) # QtCore.qInstallMessageHandler(handler)
# import traceback, sys
# if QtCore.QT_VERSION >= 0x50501:
# def excepthook(type_, value, traceback_):
# traceback.print_exception(type_, value, traceback_)
# QtCore.qFatal('')
# sys.excepthook = excepthook
Loading…
Cancel
Save