From e9bf40966b15d9de7ce05020cca0c1afdaac66c5 Mon Sep 17 00:00:00 2001
From: Sebastiaan Lokhorst <sebastiaanlokhorst@gmail.com>
Date: Sat, 11 Aug 2018 04:07:04 +0200
Subject: [PATCH] Convert everything to use Python 3
---
usr/lib/blueberry/BlueberrySettingsWidgets.py | 8 ++++----
usr/lib/blueberry/blueberry-obex-agent.py | 8 +-------
usr/lib/blueberry/blueberry-tray.py | 2 +-
usr/lib/blueberry/blueberry.py | 18 +++++++++---------
usr/lib/blueberry/rfkillMagic.py | 7 +++----
usr/lib/blueberry/safechild | 4 ++--
6 files changed, 20 insertions(+), 27 deletions(-)
diff --git a/usr/lib/blueberry/BlueberrySettingsWidgets.py b/usr/lib/blueberry/BlueberrySettingsWidgets.py
index 8d92fbc..ddf2cf5 100644
--- a/usr/lib/blueberry/BlueberrySettingsWidgets.py
+++ b/usr/lib/blueberry/BlueberrySettingsWidgets.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
@@ -54,9 +54,9 @@ def __init__(self, title):
separator_context = toolbar_separator.get_style_context()
frame_color = frame_style.get_border_color(Gtk.StateFlags.NORMAL).to_string()
css_provider = Gtk.CssProvider()
- css_provider.load_from_data(".separator { -GtkWidget-wide-separators: 0; \
- color: %s; \
- }" % frame_color)
+ css_provider.load_from_data(".separator {{ -GtkWidget-wide-separators: 0; \
+ color: {}; \
+ }}".format(frame_color).encode())
separator_context.add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
self.list_box = Gtk.ListBox()
diff --git a/usr/lib/blueberry/blueberry-obex-agent.py b/usr/lib/blueberry/blueberry-obex-agent.py
index 899475c..50381a0 100755
--- a/usr/lib/blueberry/blueberry-obex-agent.py
+++ b/usr/lib/blueberry/blueberry-obex-agent.py
@@ -1,9 +1,4 @@
-#!/usr/bin/python2
-
-from __future__ import print_function
-from __future__ import division
-from __future__ import absolute_import
-from __future__ import unicode_literals
+#!/usr/bin/python3
# CREDITS
# --------
@@ -28,7 +23,6 @@
from datetime import datetime
from gi.types import GObjectMeta
-from inspect import isclass
gi.require_version("Gtk", "3.0")
gi.require_version('Notify', '0.7')
diff --git a/usr/lib/blueberry/blueberry-tray.py b/usr/lib/blueberry/blueberry-tray.py
index 041c5ec..4665d84 100755
--- a/usr/lib/blueberry/blueberry-tray.py
+++ b/usr/lib/blueberry/blueberry-tray.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
import sys
import gettext
diff --git a/usr/lib/blueberry/blueberry.py b/usr/lib/blueberry/blueberry.py
index 88210cf..2667823 100755
--- a/usr/lib/blueberry/blueberry.py
+++ b/usr/lib/blueberry/blueberry.py
@@ -1,10 +1,10 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
-import sys, os, commands
+import sys, os
import gettext
import rfkillMagic
import subprocess
-from BlueberrySettingsWidgets import SettingsPage, SettingsBox, SettingsRow
+from BlueberrySettingsWidgets import SettingsPage, SettingsRow
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GnomeBluetooth', '1.0')
@@ -36,7 +36,7 @@ def on_activate(self, data=None):
self.create_window()
def detect_desktop_environment(self):
- wm_info = commands.getoutput("wmctrl -m")
+ wm_info = subprocess.getoutput("wmctrl -m")
if "XDG_CURRENT_DESKTOP" in os.environ:
xdg_current_desktop = os.environ["XDG_CURRENT_DESKTOP"]
else:
@@ -66,7 +66,7 @@ def detect_desktop_environment(self):
self.configuration_tools = {"sound": "pavucontrol", "keyboard": "lxinput", "mouse": "lxinput"}
else:
self.de = "Unknown"
- print "Warning: DE could not be detected!"
+ print("Warning: DE could not be detected!")
self.configuration_tools = {}
if os.path.exists("/usr/bin/pavucontrol"):
self.configuration_tools["sound"] = "pavucontrol"
@@ -154,7 +154,7 @@ def create_window(self):
if adapter_name is not None:
self.adapter_name_entry.set_text(adapter_name)
self.adapter_name_entry.connect("changed", self.on_adapter_name_changed)
- row = SettingsRow(Gtk.Label(_("Name")), self.adapter_name_entry)
+ row = SettingsRow(Gtk.Label(label=_("Name")), self.adapter_name_entry)
row.set_tooltip_text(_("This is the Bluetooth name of your computer"))
section.add_row(row)
@@ -192,7 +192,7 @@ def create_window(self):
def panel_changed(self, widget, panel):
if not panel in self.configuration_tools:
- print "Warning, no configuration tool known for panel '%s'" % panel
+ print("Warning, no configuration tool known for panel '%s'" % panel)
else:
os.system("%s &" % self.configuration_tools[panel])
@@ -228,7 +228,7 @@ def add_stack_page(self, message, name):
def get_default_adapter_name(self):
name = None
try:
- output = subprocess.check_output(["timeout", "2s", "bt-adapter", "-i"]).strip()
+ output = subprocess.check_output(["timeout", "2s", "bt-adapter", "-i"]).decode("utf-8").strip()
for line in output.split("\n"):
line = line.strip()
if line.startswith("Alias: "):
@@ -260,7 +260,7 @@ def update_status(self, path=None, iter=None, data=None):
else:
explanation_label.set_label("")
except Exception as e:
- print (e)
+ print(e)
return None
def update_ui_callback(self):
diff --git a/usr/lib/blueberry/rfkillMagic.py b/usr/lib/blueberry/rfkillMagic.py
index 03aaed5..b3c7384 100644
--- a/usr/lib/blueberry/rfkillMagic.py
+++ b/usr/lib/blueberry/rfkillMagic.py
@@ -1,7 +1,6 @@
-import thread
+import _thread as thread
import subprocess
-import os
import re
from gi.repository import GLib
@@ -32,7 +31,7 @@ def __init__(self, output_callback, debug):
self.start_event_monitor()
def adapter_check(self):
- res = subprocess.check_output(RFKILL_CHK)
+ res = subprocess.check_output(RFKILL_CHK).decode('utf-8')
'''
Assume the output of:
@@ -69,7 +68,7 @@ def start_event_monitor(self):
def event_monitor_thread(self, data):
self.tproc = subprocess.Popen(RFKILL_EVENT_MONITOR, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
while self.tproc.poll() is None and not self.monitor_killer:
- l = self.tproc.stdout.readline() # This blocks until it receives a newline.
+ l = self.tproc.stdout.readline().decode('utf-8') # This blocks until it receives a newline.
self.update_state(l)
self.tproc = None
diff --git a/usr/lib/blueberry/safechild b/usr/lib/blueberry/safechild
index 9d6918c..20034f5 100755
--- a/usr/lib/blueberry/safechild
+++ b/usr/lib/blueberry/safechild
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
import subprocess
import sys
@@ -32,4 +32,4 @@ try:
proc.wait()
break
except Exception as e:
- print "safechild exception: ", e
+ print("safechild exception: ", e)