From 9be30b9ff4259e4a5b6896ba628065db4e65de0f Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 14 Feb 2021 23:59:34 +0200 Subject: [PATCH] python3 fixes and more log files were opened in binary mode this was resulting in read_last() not working correctly --- ladi-control-center | 2 +- ladi-system-log | 20 +++++++++++++------- ladi-system-tray | 4 ++-- laditools/gtk/a2jmenu.py | 2 ++ laditools/ladish.py | 6 ++---- setup.py | 2 +- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/ladi-control-center b/ladi-control-center index 4f4b578..0b78243 100755 --- a/ladi-control-center +++ b/ladi-control-center @@ -317,7 +317,7 @@ class cell_renderer_param(Gtk.CellRendererPixbuf): if typechar == 'u' or typechar == 'i': try: value = int(value_str) - except ValueError, e: + except (ValueError, e): # Hide the widget (because it may display something else than what user typed in) widget.hide() # Display the error diff --git a/ladi-system-log b/ladi-system-log index c5a987d..dee2575 100755 --- a/ladi-system-log +++ b/ladi-system-log @@ -36,13 +36,19 @@ from laditools import get_version_string from laditools import LadiConfiguration from laditools import LadiApp +import gi + +gi.require_version('Gtk', '3.0') +from gi.repository import GLib from gi.repository import Gtk from gi.repository import GObject + +gi.require_version('Vte', '2.91') from gi.repository import Vte from laditools.gtk import find_data_file -timeout_add = GObject.timeout_add +timeout_add = GLib.timeout_add # Default configuration max_lines_default = 100 @@ -155,12 +161,12 @@ class LadiSystemLog(LadiApp): # Make it do something... for log in self.log_files: try: - log['log_file'] = open(log['logfile_path'], "rb") + log['log_file'] = open(log['logfile_path'], "r") sys.stderr.write (_("Opening %s...\n") % log['logfile_path']) lines = read_last(log['log_file'], self.max_lines) for line in lines: - line = line.strip('\r\n') + '\r\n' - log["term"].feed(line, -1) + line = line.strip('\r\n') + '\r\n'; + log["term"].feed(bytes(line, "utf-8")) except ValueError: sys.stderr.write( _("You called Popen with invalid arguments... dumbass\n") ) except: @@ -175,7 +181,7 @@ class LadiSystemLog(LadiApp): for log in self.log_files: line = log['log_file'].readline() while line: - log["term"].feed(line + '\r', -1) + log["term"].feed(bytes(line + '\r', "utf-8")) line = log['log_file'].readline() log['log_file'].seek(log['log_file'].tell()) return True @@ -190,13 +196,13 @@ class LadiSystemLog(LadiApp): def on_clear_text (self, data=None): current_view = self.logview_notebook.get_current_page () - self.log_files[current_view]["term"].feed ("\033[2J\033[;f", -1) + self.log_files[current_view]["term"].feed(bytes("\033[2J\033[;f", "utf-8")) def on_purge (self, data=None): current_view = self.logview_notebook.get_current_page () # Opens the file in write anew mode thus clearing the file and close it right away open (self.log_files[current_view]['logfile_path'], "w+") - self.log_files[current_view]["term"].feed ("\033[2J\033[;f", -1) + self.log_files[current_view]["term"].feed(bytes("\033[2J\033[;f", "utf-8")) def run (self): self.ui.show_all() diff --git a/ladi-system-tray b/ladi-system-tray index dc7a616..8f7dc2f 100755 --- a/ladi-system-tray +++ b/ladi-system-tray @@ -149,7 +149,7 @@ class LadiStatusTray(Gtk.StatusIcon, LadiStatusIcon): self.set_tooltip_safe ("JACK is stopped") self.set_icon ("stopped") self.clear_diagnose_text() - except Exception, e: + except (Exception, e): self.set_tooltip_safe ("JACK is sick") self.set_diagnose_text(repr(e)) self.set_icon ("stopped") @@ -185,7 +185,7 @@ class LadiStatusIndicator(LadiStatusIcon): self.set_tooltip_safe ("JACK is stopped") self.set_icon ("stopped") self.clear_diagnose_text() - except Exception, e: + except (Exception, e): self.set_tooltip_safe ("JACK is sick") self.set_diagnose_text(repr(e)) self.set_icon ("stopped") diff --git a/laditools/gtk/a2jmenu.py b/laditools/gtk/a2jmenu.py index dac04e0..24be0dd 100644 --- a/laditools/gtk/a2jmenu.py +++ b/laditools/gtk/a2jmenu.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import gi +gi.require_version('Gtk', '3.0') from gi.repository import Gtk # TODO : somehow, we need stock icons. Nothing else can be used for ImageMenuItems diff --git a/laditools/ladish.py b/laditools/ladish.py index c416f57..a41823b 100644 --- a/laditools/ladish.py +++ b/laditools/ladish.py @@ -28,10 +28,8 @@ control_obj_path = "/org/ladish/Control" studio_obj_path = "/org/ladish/Studio" service_name = name_base -LadishStatusType = Enum("STUDIO_STOPPED", - "NOT_AVAILABLE", - "NO_STUDIO_LOADED", - "STUDIO_RUNNING") +LadishStatusType = Enum("LadishStatusType", + "STUDIO_STOPPED NOT_AVAILABLE NO_STUDIO_LOADED STUDIO_RUNNING") class LadishProxyError(Exception): pass class LadishStudioException(Exception): pass diff --git a/setup.py b/setup.py index 525f9ba..7560581 100755 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ os.environ['XGETTEXT_ARGS'] = "--language=Python" if not os.getenv("LADI_RELEASE") and \ os.path.isfile(get_commit_script): commit = subprocess.check_output(["sh", get_commit_script]).strip() - laditools_version += "~" + commit + laditools_version += "~" + str(commit) iconsizelist = "16 22 24 32 48 64 96 128 256".split()