1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-23 06:37:59 +01:00

Merge pull request #1 from xtaran/master

More fixes for using wicd under Python 3, mostly in the daemon
This commit is contained in:
Guido Maria Serra
2019-09-11 10:49:43 +02:00
committed by GitHub
11 changed files with 32 additions and 26 deletions

View File

@@ -707,7 +707,7 @@ class OptCols(urwid.WidgetWrap):
# callbacks map the text contents to its assigned callback. # callbacks map the text contents to its assigned callback.
self.callbacks = [] self.callbacks = []
for cmd in tuples: for cmd in tuples:
key = reduce(lambda s, (f, t): s.replace(f, t), [ key = reduce(lambda s, tuple: s.replace(tuple[0], tuple[1]), [
('ctrl ', 'Ctrl+'), ('meta ', 'Alt+'), ('ctrl ', 'Ctrl+'), ('meta ', 'Alt+'),
('left', '<-'), ('right', '->'), ('left', '<-'), ('right', '->'),
('page up', 'Page Up'), ('page down', 'Page Down'), ('page up', 'Page Up'), ('page down', 'Page Down'),

View File

@@ -46,7 +46,7 @@ import urwid
# DBus communication stuff # DBus communication stuff
from dbus import DBusException from dbus import DBusException
# It took me a while to figure out that I have to use this. # It took me a while to figure out that I have to use this.
import gobject from gi.repository import GObject as gobject
# Other important wicd-related stuff # Other important wicd-related stuff
from wicd import wpath from wicd import wpath

View File

@@ -26,7 +26,7 @@ Module containing the code for the main wicd GUI.
import os import os
import sys import sys
import time import time
import gobject from gi.repository import GObject as gobject
import gtk import gtk
from itertools import chain from itertools import chain
from dbus import DBusException from dbus import DBusException

View File

@@ -25,7 +25,7 @@ handles recieving/sendings the settings from/to the daemon.
# #
import gtk import gtk
import gobject from gi.repository import GObject as gobject
import os import os
from wicd import misc from wicd import misc

View File

@@ -39,7 +39,7 @@ class TrayIcon() -- Parent class of TrayIconGUI and IconConnectionInfo.
import sys import sys
import gtk import gtk
import gobject from gi.repository import GObject as gobject
import getopt import getopt
import os import os
import pango import pango

View File

@@ -231,36 +231,36 @@ class configure(Command):
pmtemp = subprocess.Popen(["pkg-config", "--variable=pm_sleephooks", pmtemp = subprocess.Popen(["pkg-config", "--variable=pm_sleephooks",
"pm-utils"], stdout=subprocess.PIPE) "pm-utils"], stdout=subprocess.PIPE)
returncode = pmtemp.wait() # let it finish, and get the exit code returncode = pmtemp.wait() # let it finish, and get the exit code
pmutils_candidate = pmtemp.stdout.readline().strip() # read stdout pmutils_candidate = str(pmtemp.stdout.readline().strip()) # read stdout
if len(pmutils_candidate) == 0 or returncode != 0 or \ if len(pmutils_candidate) == 0 or returncode != 0 or \
not os.path.isabs(pmutils_candidate): not os.path.isabs(pmutils_candidate):
raise ValueError raise ValueError
else: else:
self.pmutils = pmutils_candidate self.pmutils = pmutils_candidate
except (OSError, ValueError): except (OSError, ValueError, FileNotFoundError):
pass # use our default pass # use our default
try: try:
kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE) kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE)
returncode = kdetemp.wait() # let it finish, and get the exit code returncode = kdetemp.wait() # let it finish, and get the exit code
kdedir_candidate = kdetemp.stdout.readline().strip() # read stdout kdedir_candidate = str(kdetemp.stdout.readline().strip()) # read stdout
if len(kdedir_candidate) == 0 or returncode != 0 or \ if len(kdedir_candidate) == 0 or returncode != 0 or \
not os.path.isabs(kdedir_candidate): not os.path.isabs(kdedir_candidate):
raise ValueError raise ValueError
else: else:
self.kdedir = kdedir_candidate + '/share/autostart' self.kdedir = kdedir_candidate + '/share/autostart'
except (OSError, ValueError): except (OSError, ValueError, FileNotFoundError):
# If kde-config isn't present, we'll check for kde-4.x # If kde-config isn't present, we'll check for kde-4.x
try: try:
kde4temp = subprocess.Popen(["kde4-config","--prefix"], stdout=subprocess.PIPE) kde4temp = subprocess.Popen(["kde4-config","--prefix"], stdout=subprocess.PIPE)
returncode = kde4temp.wait() # let it finish, and get the exit code returncode = kde4temp.wait() # let it finish, and get the exit code
kde4dir_candidate = kde4temp.stdout.readline().strip() # read stdout kde4dir_candidate = str(kde4temp.stdout.readline().strip()) # read stdout
if len(kde4dir_candidate) == 0 or returncode != 0 or \ if len(kde4dir_candidate) == 0 or returncode != 0 or \
not os.path.isabs(kde4dir_candidate): not os.path.isabs(kde4dir_candidate):
raise ValueError raise ValueError
else: else:
self.kdedir = kde4dir_candidate + '/share/autostart' self.kdedir = kde4dir_candidate + '/share/autostart'
except (OSError, ValueError): except (OSError, ValueError, FileNotFoundError):
# If neither kde-config nor kde4-config are not present or # If neither kde-config nor kde4-config are not present or
# return an error, then we can assume that kde isn't installed # return an error, then we can assume that kde isn't installed
# on the user's system # on the user's system
@@ -339,9 +339,9 @@ class configure(Command):
# if the option is not python (which is not a directory) # if the option is not python (which is not a directory)
if not argument[0][:-1] == "python": if not argument[0][:-1] == "python":
# see if it ends with a / # see if it ends with a /
if not value.endswith("/"): if not str(value).endswith("/"):
# if it doesn't, slap one on # if it doesn't, slap one on
setattr(self, argument_name, value + "/") setattr(self, argument_name, str(value) + "/")
else: else:
# as stated above, the python entry defines the beginning # as stated above, the python entry defines the beginning
# of the files section # of the files section
@@ -636,7 +636,7 @@ class compile_translations(Command):
print(len(output), returncode) print(len(output), returncode)
raise ValueError raise ValueError
else: else:
m = re.match('(\d+) translated messages(?:, (\d+) fuzzy translation)?(?:, (\d+) untranslated messages)?.', output) m = re.match(b'(\d+) translated messages(?:, (\d+) fuzzy translation)?(?:, (\d+) untranslated messages)?.', output)
if m: if m:
done, fuzzy, missing = m.groups() done, fuzzy, missing = m.groups()
fuzzy = int(fuzzy) if fuzzy else 0 fuzzy = int(fuzzy) if fuzzy else 0

View File

@@ -24,20 +24,21 @@ rotates itself when a maximum size is reached.
import sys import sys
import os import os
import time import time
import io
class SizeError(IOError): class SizeError(IOError):
""" Custom error class. """ """ Custom error class. """
pass pass
class LogFile: class LogFile(io.FileIO):
"""LogFile(name, [mode="w"], [maxsize=360000]) """LogFile(name, [mode="w"], [maxsize=360000])
Opens a new file object. After writing <maxsize> bytes a SizeError Opens a new file object. After writing <maxsize> bytes a SizeError
will be raised. will be raised.
""" """
def __init__(self, name, mode="a", maxsize=360000): def __init__(self, name, mode="a", maxsize=360000, *args, **kwargs):
super(LogFile, self).__init__(name, mode) super(LogFile, self).__init__(name, mode, maxsize, *args, **kwargs)
self.maxsize = maxsize self.maxsize = maxsize
self.eol = True self.eol = True
try: try:
@@ -52,7 +53,7 @@ class LogFile:
if len(data) <= 0: if len(data) <= 0:
return return
if self.eol: if self.eol:
super(LogFile, self).write(self.get_time() + ' :: ') super(LogFile, self).write(self.get_time().encode("utf-8") + b' :: ')
self.eol = False self.eol = False
if data[-1] == '\n': if data[-1] == '\n':
@@ -60,7 +61,7 @@ class LogFile:
data = data[:-1] data = data[:-1]
super(LogFile, self).write(data.replace( super(LogFile, self).write(data.replace(
'\n', '\n' + self.get_time() + ' :: ')) b'\n', b'\n' + self.get_time().encode("utf-8") + b' :: '))
if self.eol: if self.eol:
super(LogFile, self).write('\n') super(LogFile, self).write('\n')

View File

@@ -24,7 +24,7 @@ when appropriate.
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import gobject from gi.repository import GObject as gobject
import time import time
from dbus import DBusException from dbus import DBusException

View File

@@ -48,6 +48,7 @@ import time
import threading import threading
import os import os
from signal import SIGTERM from signal import SIGTERM
from functools import cmp_to_key
# wicd imports # wicd imports
from . import misc from . import misc
@@ -643,7 +644,8 @@ class Wireless(Controller):
key = 'quality' key = 'quality'
else: else:
key = 'strength' key = 'strength'
return cmp(x[key], y[key]) return ((x[key] > y[key]) - (x[key] < y[key])) # cmp(x[key], y[key])
if not self.wiface: if not self.wiface:
return [] return []
@@ -663,7 +665,7 @@ class Wireless(Controller):
time.sleep(1) time.sleep(1)
aps = wiface.GetNetworks(essid) aps = wiface.GetNetworks(essid)
aps.sort(cmp=comp, reverse=True) aps.sort(key=cmp_to_key(comp), reverse=True)
return aps return aps

View File

@@ -44,7 +44,7 @@ from subprocess import Popen
from operator import itemgetter from operator import itemgetter
# DBUS # DBUS
import gobject from gi.repository import GObject as gobject
import dbus import dbus
import dbus.service import dbus.service
if getattr(dbus, 'version', (0, 0, 0)) < (0, 80, 0): if getattr(dbus, 'version', (0, 0, 0)) < (0, 80, 0):
@@ -1950,5 +1950,7 @@ if __name__ == '__main__':
print(("Root privileges are required for the daemon to run properly." + print(("Root privileges are required for the daemon to run properly." +
" Exiting.")) " Exiting."))
sys.exit(1) sys.exit(1)
gobject.threads_init() # No more needed since PyGObject 3.11, c.f.
# https://wiki.gnome.org/PyGObject/Threading
#gobject.threads_init()
main(sys.argv) main(sys.argv)

View File

@@ -38,8 +38,9 @@ import time
import dbus import dbus
import socket, fcntl import socket, fcntl
import shutil import shutil
from functools import cmp_to_key
import wpath from . import wpath
from . import misc from . import misc
from .misc import find_path from .misc import find_path
@@ -1444,7 +1445,7 @@ class BaseWirelessInterface(BaseInterface):
m = re.findall(bitrates_pattern, bitrates) m = re.findall(bitrates_pattern, bitrates)
if m: if m:
# numeric sort # numeric sort
ap['bitrates'] = sorted(m, lambda x, y: int(float(x) - float(y))) ap['bitrates'] = sorted(m, key=cmp_to_key(lambda x, y: int(float(x) - float(y))))
else: else:
ap['bitrates'] = None ap['bitrates'] = None