Modernize code for easier Python 3 port

- Replace print statement with function call
- Replace except ..., ...: syntax with except ... as ...:
- Simplify obsolete try ... except ... code block
- Replace some unicode calls with u-prefixed strings
- Do not use `len(SEQUENCE)` to determine if a sequence is empty
- Replace dictionary creation
- Drop support for GObject static bindings
This commit is contained in:
JoeLametta
2019-01-16 21:08:43 +00:00
parent 0e17b32740
commit fef7973113
6 changed files with 17 additions and 28 deletions

View File

@@ -22,10 +22,7 @@ from __future__ import print_function
import logging
import sys
try:
from gi.repository import GLib as gobject
except ImportError:
import gobject
from gi.repository import GLib as GLib
logger = logging.getLogger(__name__)
@@ -463,7 +460,7 @@ class TaskRunner(LogStub):
class SyncRunner(TaskRunner, ITaskListener):
"""
I run the task synchronously in a gobject MainLoop.
I run the task synchronously in a GObject MainLoop.
"""
def __init__(self, verbose=True):
@@ -478,11 +475,11 @@ class SyncRunner(TaskRunner, ITaskListener):
self._verboseRun = verbose
self._skip = skip
self._loop = gobject.MainLoop()
self._loop = GLib.MainLoop()
self._task.addListener(self)
# only start the task after going into the mainloop,
# otherwise the task might complete before we are in it
gobject.timeout_add(0L, self._startWrap, self._task)
GLib.timeout_add(0L, self._startWrap, self._task)
self.debug('run loop')
self._loop.run()
@@ -526,7 +523,7 @@ class SyncRunner(TaskRunner, ITaskListener):
self.debug('schedule: scheduling %r(*args=%r, **kwargs=%r)',
callable, args, kwargs)
gobject.timeout_add(int(delta * 1000L), c)
GLib.timeout_add(int(delta * 1000L), c)
# ITaskListener methods
def progressed(self, task, value):