From dd347399a2ac70467014a1fab1431d179b8f250a Mon Sep 17 00:00:00 2001 From: idziubenko Date: Wed, 30 Jun 2021 11:28:14 +0300 Subject: [PATCH] fixed process translation, images, password auth --- pym/consolegui/application/ControlButton.py | 16 +++++----- pym/consolegui/application/DisplayMethod.py | 6 +--- pym/consolegui/application/View_Process.py | 23 +++++++------ pym/consolegui/application/client_class.py | 2 +- pym/consolegui/application/conf_connection.py | 6 ++-- pym/consolegui/application/create_cert.py | 4 +-- pym/consolegui/application/mainframe.py | 10 +++--- pym/consolegui/application/more.py | 32 ++++++++++++------- .../application/pyopenssl_wrapper.py | 1 - pym/consolegui/qt.py | 12 +------ 10 files changed, 52 insertions(+), 60 deletions(-) diff --git a/pym/consolegui/application/ControlButton.py b/pym/consolegui/application/ControlButton.py index 03313f7..2b77042 100644 --- a/pym/consolegui/application/ControlButton.py +++ b/pym/consolegui/application/ControlButton.py @@ -114,11 +114,10 @@ class ControlButtonWgt(qt.QWidget): # Set style self.setAttribute(qt.Qt.WA_StyledBackground) self.setObjectName('ControlButton') + self.setStyleSheet("QWidget#ControlButton " - "{background-color: rgb(255,0,0);}") - # self.setStyleSheet("QWidget#ControlButton " - # "{background-color: %s;}"% - # get_system_rgb(self, ParameterWindow)) + "{background-color: %s;}"% + get_system_rgb(self, ParameterWindow)) self.main_layout = qt.QVBoxLayout(self) self.main_layout.setContentsMargins(28, 8, 0, 28) @@ -247,13 +246,12 @@ class ControlButtonWgt(qt.QWidget): main_frame = self._parent.MainFrameWgt self.cancel_button = qt.QPushButton(self) if main_frame.has_errors: - # self.cancel_button.setText(_('Close').decode('utf-8')) self.cancel_button.setText(_('Close')) else: - # self.cancel_button.setText(_('Cancel').decode('utf-8')) self.cancel_button.setText(_('Cancel')) self.cancel_button.clicked.connect(self.button_disabled) + self.cancel_button.clicked.connect(self.clear_method_cache) method_name = main_frame.method_name self.cancel_button.clicked.connect( @@ -415,8 +413,9 @@ class ControlButtonWgt(qt.QWidget): res = self.ClientObj.client.service.clear_method_cache \ (sid, method) lerror = self.ClientObj.param_objects[method]['error'] - while len(lerror) > 0: - lerror.pop() + if(lerror): + while len(lerror) > 0: + lerror.pop() except Exception as e: print(e) from calculate.consolegui.application.ConnectionTabs \ @@ -430,6 +429,7 @@ class ControlButtonWgt(qt.QWidget): self._parent.back() def button_disabled(self): + # if self.next_button: # self.next_button.setDisabled(True) # if self.prev_button: diff --git a/pym/consolegui/application/DisplayMethod.py b/pym/consolegui/application/DisplayMethod.py index 4a26a58..dacdfb1 100644 --- a/pym/consolegui/application/DisplayMethod.py +++ b/pym/consolegui/application/DisplayMethod.py @@ -238,7 +238,6 @@ class DisplayMethod(qt.QWidget): def onActivated(self): - print("DEBUG onActivated") # Call server method if hasattr (self, 'onActivated_thread'): if self.onActivated_thread.isRunning(): @@ -263,7 +262,6 @@ class DisplayMethod(qt.QWidget): str(method_name + '_view'), step = step, expert = expert, brief = brief) - print(f"view_params: \n {view_params}") self.onActivated_thread = ClientServiceThread(self.ClientObj, \ str(method_name + '_view'), int(self.ClientObj.sid), \ view_params, return_except = True) @@ -275,9 +273,7 @@ class DisplayMethod(qt.QWidget): #self.con_lost_lbl.hide() if type(view) == Exception: - print("DEBUG excpt") - print(view) - print(dir(view)) + if hasattr (view, 'message'): view = view.message diff --git a/pym/consolegui/application/View_Process.py b/pym/consolegui/application/View_Process.py index 820e70b..f147889 100644 --- a/pym/consolegui/application/View_Process.py +++ b/pym/consolegui/application/View_Process.py @@ -14,12 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import +# from __future__ import absolute_import from calculate.consolegui import qt from .pid_information import client_list_pid, client_pid_info from .more import LabelWordWrap, show_msg, get_sid, ClientServiceThread - class ViewProc(qt.QWidget): def __init__(self, parent, ClientObj): @@ -31,12 +30,11 @@ class ViewProc(qt.QWidget): self.pid = 0 client_pid_info(ClientObj, ClientObj.client, 0) list_pid = client_list_pid(self.ClientObj.client) - ClientObj._parent.setWindowTitle ( _('View information about the running processes')\ + ' - ' + self.ClientObj.Name) - self.lable_list = [] + self.label_list = [] self.button_list = [] self.status_list = [] self.grid_layout = qt.QGridLayout() @@ -57,9 +55,10 @@ class ViewProc(qt.QWidget): else: method_name = self.ClientObj.process_dict[str(list_pid[num])] \ ['name'] - + method_name = str(method_name) 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: # view_method_name = self.ClientObj.param_objects \ # [method_name]['view_method_name'] @@ -67,13 +66,13 @@ class ViewProc(qt.QWidget): else: view_method_name = method_name - try: - view_method_name = view_method_name.encode('utf-8') - except (UnicodeEncodeError, UnicodeDecodeError): - pass + # try: + # view_method_name = view_method_name.encode('utf-8') + # except (UnicodeEncodeError, UnicodeDecodeError): + # pass - self.lable_list.append(LabelWordWrap(str(view_method_name), self)) - self.grid_layout.addWidget(self.lable_list[num], num+2,0) + self.label_list.append(LabelWordWrap(str(view_method_name), self)) + self.grid_layout.addWidget(self.label_list[num], num+2,0) # add start time process # del mircosec diff --git a/pym/consolegui/application/client_class.py b/pym/consolegui/application/client_class.py index fc8ffba..6970c66 100644 --- a/pym/consolegui/application/client_class.py +++ b/pym/consolegui/application/client_class.py @@ -648,7 +648,7 @@ class HTTPSClientCertTransport(HttpTransport): with open(key) as key_file: client_keyobj = OpenSSL.crypto.load_privatekey \ (OpenSSL.SSL.FILETYPE_PEM, key_file.read(), - str(password)) + password) else: import M2Crypto bio = M2Crypto.BIO.openfile(key) diff --git a/pym/consolegui/application/conf_connection.py b/pym/consolegui/application/conf_connection.py index 4af3233..ff2a796 100644 --- a/pym/consolegui/application/conf_connection.py +++ b/pym/consolegui/application/conf_connection.py @@ -327,18 +327,17 @@ class FrameConnection(qt.QWidget): bio = M2Crypto.BIO.openfile(CERT_KEY) rsa = M2Crypto.m2.rsa_read_key(bio._ptr(), lambda *unused: b"") 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: self.passwd_wgt = LocalhostPasswd(self) passwd = self.passwd_wgt.text() self.str_passwd = passwd if passwd else None - try: # if True: self.ClientObj.client = Client_suds(url,\ transport = HTTPSClientCertTransport(CERT_KEY, \ 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.set_parameters \ (path_to_cert, CERT_FILE, CERT_KEY) @@ -354,7 +353,6 @@ class FrameConnection(qt.QWidget): print("OPENSSL ERROR") Connect_Error = 1 crypto_Error = 1 - # DEBUGG uncomment this # except Exception as e: # print("GENERAL ERROR") # print(e) diff --git a/pym/consolegui/application/create_cert.py b/pym/consolegui/application/create_cert.py index f5587f6..1b06cde 100644 --- a/pym/consolegui/application/create_cert.py +++ b/pym/consolegui/application/create_cert.py @@ -23,7 +23,7 @@ from .more import LabelWordWrap, show_msg, get_icon def passphrase_callback(v): if type(v) == int or not v: return "" - return str(v) + return bytes(v, "UTF-8") def generateRSAKey(): from M2Crypto import RSA, m2 @@ -157,7 +157,7 @@ class RequestCreate (qt.QWidget): callback = lambda *unused: "") else: 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.set_version(req.get_version()) diff --git a/pym/consolegui/application/mainframe.py b/pym/consolegui/application/mainframe.py index cdb0ebd..24b7373 100644 --- a/pym/consolegui/application/mainframe.py +++ b/pym/consolegui/application/mainframe.py @@ -1598,11 +1598,11 @@ class MainFrame(qt.QWidget): steps = field.tablevalue.head.string icons = [] - print("---------------------------------------------------") - print("DEBUG") - print(field) - print(dir(field)) - print(type(field)) + # print("---------------------------------------------------") + # print("DEBUG") + # print(field) + # print(dir(field)) + # print(type(field)) if hasattr(field.listvalue, 'string'): icons = field.listvalue.string val_steps = field.tablevalue.body.stringArray diff --git a/pym/consolegui/application/more.py b/pym/consolegui/application/more.py index 9a7508b..296df7e 100644 --- a/pym/consolegui/application/more.py +++ b/pym/consolegui/application/more.py @@ -2336,6 +2336,7 @@ def _print (*args): def show_msg(text, title = None, parent = None): msgBox = qt.QMessageBox(parent) + #DEBUG: want traceback? force error there. # raise Exception if title: msgBox.setWindowTitle(title) @@ -2344,16 +2345,19 @@ def show_msg(text, title = None, parent = None): if not text: return 1 if not type(text) in [str]: - temp = '' - for i in text: - #DEBUG: want traceback? force error there. - # for i in str(text): - try: - # temp += str(i).decode('utf-8')+' ' - temp += str(i) + ' ' - except (UnicodeEncodeError, UnicodeDecodeError): - temp += str(i) + ' ' - text = temp + + if hasattr(text, '__iter__'): + #print(f'{text} is iterable') + temp = '' + for i in text: + try: + # temp += str(i).decode('utf-8')+' ' + temp += str(i) + ' ' + except (UnicodeEncodeError, UnicodeDecodeError): + temp += str(i) + ' ' + text = temp + else: + text = str(text) msgBox.setText(text) msgBox.setStandardButtons(qt.QMessageBox.Ok) msgBox.setWindowIcon(get_icon('calculate-install.svg')) @@ -2648,7 +2652,6 @@ class ImageLabel(qt.QLabel): image_conf = os.path.join(image_path, 'conf') repeat_dict = {'no' : 'no-repeat', 'x' : 'repeat-x'} - for line in readLinesFile(image_conf): list_data = line.split() if len (list_data) < 2: @@ -2664,6 +2667,7 @@ class ImageLabel(qt.QLabel): def resize_image(source_path, height, output_path): convert_cmd = getProgPath('/usr/bin/convert') identify_cmd = getProgPath('/usr/bin/identify') + def convert_image(source, res, target): command = [convert_cmd, "-quality", "100", source, "-resize", "%s" % res, @@ -2671,10 +2675,12 @@ class ImageLabel(qt.QLabel): target] #"-strip", "-gravity", "center", #"-crop", "%s+0+0" % res, target] + convert = process(*command, stderr=STDOUT) if convert.success(): return True return False + def get_image_resolution(source): identify = process(identify_cmd, "-format", "%w %h", source) if identify.success(): @@ -2683,11 +2689,15 @@ class ImageLabel(qt.QLabel): return int(swidth), int(sheight) return None, None return None, None + cx, cy = get_image_resolution(source_path) + if cx and cy: if convert_image(source_path, "{}x{}".format(cx, height), output_path): + return get_image_resolution(output_path) + return None if len(list_data) == 3: diff --git a/pym/consolegui/application/pyopenssl_wrapper.py b/pym/consolegui/application/pyopenssl_wrapper.py index 7ae2ec6..6ec80a0 100644 --- a/pym/consolegui/application/pyopenssl_wrapper.py +++ b/pym/consolegui/application/pyopenssl_wrapper.py @@ -337,7 +337,6 @@ def sslwrap(sock, server_side=False, keyfile=None, certfile=None, key and cert not by filename, but from internal PyOpenSSL structures. """ - print("DEBUG sslwrap") ctx = OpenSSL.SSL.Context(_ssl_to_openssl_version_remap[ssl_version]) if ca_certs: ctx.load_verify_locations(ca_certs) diff --git a/pym/consolegui/qt.py b/pym/consolegui/qt.py index 80f79ad..06f9d41 100644 --- a/pym/consolegui/qt.py +++ b/pym/consolegui/qt.py @@ -87,14 +87,4 @@ Signal = QtCore.pyqtSignal # def handler(msg_type, msg_log_context, msg_string): # pass -# 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 \ No newline at end of file +# QtCore.qInstallMessageHandler(handler) \ No newline at end of file