summaryrefslogtreecommitdiff
path: root/portato
diff options
context:
space:
mode:
Diffstat (limited to 'portato')
-rw-r--r--portato/__init__.py2
-rw-r--r--portato/backend/__init__.py6
-rw-r--r--portato/backend/flags.py77
-rw-r--r--portato/backend/package.py18
-rw-r--r--portato/backend/portage/__init__.py2
-rw-r--r--portato/backend/portage/package.py12
-rw-r--r--portato/backend/portage/package_22.py2
-rw-r--r--portato/backend/portage/sets.py8
-rw-r--r--portato/backend/portage/settings.py2
-rw-r--r--portato/backend/portage/settings_22.py2
-rw-r--r--portato/backend/portage/system.py37
-rw-r--r--portato/backend/portage/system_22.py4
-rw-r--r--portato/config_parser.py20
-rw-r--r--portato/db/__init__.py4
-rw-r--r--portato/db/database.py4
-rw-r--r--portato/db/eix_sql.py2
-rw-r--r--portato/db/hash.py8
-rw-r--r--portato/db/sql.py4
-rw-r--r--portato/dependency.py6
-rw-r--r--portato/eix/__init__.py1
-rw-r--r--portato/eix/exceptions.py2
-rw-r--r--portato/eix/py_parser.py6
-rw-r--r--portato/gui/__init__.py4
-rw-r--r--portato/gui/exception_handling.py6
-rw-r--r--portato/gui/queue.py14
-rw-r--r--portato/gui/slots.py2
-rw-r--r--portato/gui/updater.py4
-rw-r--r--portato/gui/utils.py4
-rw-r--r--portato/gui/views.py4
-rw-r--r--portato/gui/windows/about.py2
-rw-r--r--portato/gui/windows/basic.py2
-rw-r--r--portato/gui/windows/mailinfo.py10
-rw-r--r--portato/gui/windows/main.py45
-rw-r--r--portato/gui/windows/pkglist.py6
-rw-r--r--portato/gui/windows/plugin.py12
-rw-r--r--portato/gui/windows/preference.py14
-rw-r--r--portato/gui/windows/search.py2
-rw-r--r--portato/gui/windows/splash.py2
-rw-r--r--portato/helper.py6
-rw-r--r--portato/listener.py4
-rw-r--r--portato/log.py4
-rw-r--r--portato/plugin.py26
-rw-r--r--portato/session.py16
-rw-r--r--portato/su.py2
-rw-r--r--portato/waiting_queue.py4
45 files changed, 202 insertions, 222 deletions
diff --git a/portato/__init__.py b/portato/__init__.py
index 61d6a42..ed5c94b 100644
--- a/portato/__init__.py
+++ b/portato/__init__.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+
import gettext, locale
import sys, os
diff --git a/portato/backend/__init__.py b/portato/backend/__init__.py
index 5f32818..5fb716e 100644
--- a/portato/backend/__init__.py
+++ b/portato/backend/__init__.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+
from ..helper import debug
from .system_interface import SystemInterface
@@ -21,7 +21,7 @@ class _Package (object):
whether an object is a package. It cannot use the normal Package class as this results in cyclic dependencies."""
def __init__ (self):
- raise TypeError, "Calling __init__ on portato.backend._Package objects is not allowed."
+ raise TypeError("Calling __init__ on portato.backend._Package objects is not allowed.")
def is_package(what):
return isinstance(what, _Package)
@@ -65,6 +65,6 @@ class SystemWrapper (SystemInterface):
from .portage import PortageSystem
cls.__wrapped_sys = PortageSystem ()
else:
- raise InvalidSystemError, cls.__system
+ raise InvalidSystemError(cls.__system)
system = SystemWrapper()
diff --git a/portato/backend/flags.py b/portato/backend/flags.py
index 810b607..45826c3 100644
--- a/portato/backend/flags.py
+++ b/portato/backend/flags.py
@@ -10,8 +10,6 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
-
import os
import itertools as itt
from subprocess import Popen, PIPE # needed for grep
@@ -134,7 +132,7 @@ def set_config (cfg):
for i in CONFIG.keys():
if not i in cfg:
- raise KeyError, "Missing keyword in config: "+i
+ raise KeyError("Missing keyword in config: "+i)
for i in CONFIG:
CONFIG[i] = cfg[i]
@@ -583,31 +581,29 @@ def write_masked ():
list = system.split_cpv(cpv)
msg += "%s/%s\n" % (list[0],list[1])
if not file in file_cache:
- f = open(file, "a")
- f.write(msg)
- f.close()
+ with open(file, "a") as f:
+ f.write(msg)
else:
file_cache[file].append(msg)
# change a line
else:
if not file in file_cache:
# read file
- f = open(file, "r")
- lines = []
- i = 1
- while i < line: # stop at the given line
- lines.append(f.readline())
- i = i+1
- # delete
- l = f.readline()
- l = "#"+l[:-1]+" # removed by portato\n"
- lines.append(l)
+ with open(file, "r") as f:
+ lines = []
+ i = 1
+ while i < line: # stop at the given line
+ lines.append(f.readline())
+ i = i+1
+ # delete
+ l = f.readline()
+ l = "#"+l[:-1]+" # removed by portato\n"
+ lines.append(l)
- # read the rest
- lines.extend(f.readlines())
+ # read the rest
+ lines.extend(f.readlines())
- file_cache[file] = lines
- f.close()
+ file_cache[file] = lines
else: # in cache
l = file_cache[file][line-1]
# delete:
@@ -719,31 +715,29 @@ def write_testing ():
list = system.split_cpv(cpv)
msg += "%s/%s ~%s\n" % (list[0],list[1],arch)
if not file in file_cache:
- f = open(file, "a")
- f.write(msg)
- f.close()
+ with open(file, "a") as f:
+ f.write(msg)
else:
file_cache[file].append(msg)
# change a line
else:
if not file in file_cache:
# read file
- f = open(file, "r")
- lines = []
- i = 1
- while i < line: # stop at the given line
- lines.append(f.readline())
- i = i+1
- # delete
- l = f.readline()
- l = "#"+l[:-1]+" # removed by portato\n"
- lines.append(l)
-
- # read the rest
- lines.extend(f.readlines())
-
- file_cache[file] = lines
- f.close()
+ with open(file, "r") as f:
+ lines = []
+ i = 1
+ while i < line: # stop at the given line
+ lines.append(f.readline())
+ i = i+1
+ # delete
+ l = f.readline()
+ l = "#"+l[:-1]+" # removed by portato\n"
+ lines.append(l)
+
+ # read the rest
+ lines.extend(f.readlines())
+
+ file_cache[file] = lines
else: # in cache
l = file_cache[file][line-1]
# delete:
@@ -752,9 +746,8 @@ def write_testing ():
# write to disk
for file in file_cache.keys():
- f = open(file, "w")
- f.writelines(file_cache[file])
- f.close()
+ with open(file, "w") as f:
+ f.writelines(file_cache[file])
# reset
newTesting = {}
system.reload_settings()
diff --git a/portato/backend/package.py b/portato/backend/package.py
index 34cdbe4..7fddb21 100644
--- a/portato/backend/package.py
+++ b/portato/backend/package.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+from future_builtins import map, filter, zip
from ..helper import debug, paren_reduce
from ..dependency import DependencyTree
@@ -27,6 +27,7 @@ class Package (_Package):
@type cpv: string (cat/pkg-ver)"""
self._cpv = cpv
+ self._slot = None
def __repr__ (self):
return "<Package '%s' @0x%x>" % (self._cpv, id(self))
@@ -154,15 +155,26 @@ class Package (_Package):
@returns: category/package.
@rtype: string"""
- return self.get_category()+"/"+self.get_name()
+ return "/".join((self.get_category(), self.get_name()))
+ def get_slot (self):
+ """Returns the slot.
+
+ @returns: Slot
+ @rtype: string"""
+
+ if self._slot is None:
+ self._slot = self.get_package_settings("SLOT")
+
+ return self._slot
+
def get_slot_cp (self):
"""Returns the current cp followed by a colon and the slot-number.
@returns: cp:slot
@rtype: string"""
- return ("%s:%s" % (self.get_cp(), self.get_package_settings("SLOT")))
+ return ":".join((self.get_cp(), self.get_slot()))
def get_package_path(self):
"""Returns the path to where the ChangeLog, Manifest, .ebuild files reside.
diff --git a/portato/backend/portage/__init__.py b/portato/backend/portage/__init__.py
index e559f9e..6a68bbc 100644
--- a/portato/backend/portage/__init__.py
+++ b/portato/backend/portage/__init__.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+from future_builtins import map, filter, zip
from ...helper import debug
from portage import VERSION as PV
diff --git a/portato/backend/portage/package.py b/portato/backend/portage/package.py
index b34e3ef..5f01cad 100644
--- a/portato/backend/portage/package.py
+++ b/portato/backend/portage/package.py
@@ -10,8 +10,6 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
-
from ..package import Package
from .. import flags
from .. import system
@@ -184,7 +182,7 @@ class PortagePackage (Package):
return []
if deps[0] == 0: # error
- raise DependencyCalcError, deps[1]
+ raise DependencyCalcError(deps[1])
deps = deps[1]
@@ -206,7 +204,7 @@ class PortagePackage (Package):
return []
if deps[0] == 0: # error
- raise DependencyCalcError, deps[1]
+ raise DependencyCalcError(deps[1])
deps = deps[1]
@@ -234,7 +232,7 @@ class PortagePackage (Package):
else:
dep_pkgs.append(dep)
elif blocked:
- raise BlockedException, (self.get_cpv(), blocked[0].get_cpv())
+ raise BlockedException((self.get_cpv(), blocked[0].get_cpv()))
continue # finished with the blocking one -> next
@@ -242,7 +240,7 @@ class PortagePackage (Package):
if not pkg: # try to find masked ones
pkgs = system.find_packages(dep, masked = True)
if not pkgs:
- raise PackageNotFoundException, dep
+ raise PackageNotFoundException(dep)
pkgs = system.sort_package_list(pkgs)
pkgs.reverse()
@@ -299,5 +297,5 @@ class PortagePackage (Package):
def matches (self, criterion):
# cpv_matches needs explicit slot info
- scpv = "%s:%s" % (self.get_cpv(), self.get_package_settings("SLOT"))
+ scpv = ":".join((self.get_cpv(), self.get_slot()))
return system.cpv_matches(scpv, criterion)
diff --git a/portato/backend/portage/package_22.py b/portato/backend/portage/package_22.py
index 23e8ed5..61d7364 100644
--- a/portato/backend/portage/package_22.py
+++ b/portato/backend/portage/package_22.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+
from .package import PortagePackage
diff --git a/portato/backend/portage/sets.py b/portato/backend/portage/sets.py
index 6c483c9..0e9bf2f 100644
--- a/portato/backend/portage/sets.py
+++ b/portato/backend/portage/sets.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+from future_builtins import map, filter, zip
import re
import itertools as itt
@@ -33,7 +33,7 @@ class Set(object):
try:
t = self.get_pkgs(key, is_regexp, masked, with_version, only_cpv)
# catch the "ambigous package" Exception
- except ValueError, e:
+ except ValueError as e:
if isinstance(e[0], list):
t = set()
for cp in e[0]:
@@ -55,7 +55,7 @@ class InstalledSet (Set):
t = system.settings.vartree.dbapi.cp_all()
if key:
- t = filter(lambda x: re.search(key, x, re.I), t)
+ t = [x for x in t if re.search(key, x, re.I)]
return t
@@ -82,7 +82,7 @@ class TreeSet (Set):
t = system.settings.porttree.dbapi.cp_all()
if key:
- t = filter(lambda x: re.search(key, x, re.I), t)
+ t = [x for x in t if re.search(key, x, re.I)]
return set(t)
diff --git a/portato/backend/portage/settings.py b/portato/backend/portage/settings.py
index 2f3b780..0c857ac 100644
--- a/portato/backend/portage/settings.py
+++ b/portato/backend/portage/settings.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+
import os
import portage
diff --git a/portato/backend/portage/settings_22.py b/portato/backend/portage/settings_22.py
index ba4f1e8..253ecaa 100644
--- a/portato/backend/portage/settings_22.py
+++ b/portato/backend/portage/settings_22.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+
import portage.sets
from .settings import PortageSettings
diff --git a/portato/backend/portage/system.py b/portato/backend/portage/system.py
index 990a39a..a7fea5d 100644
--- a/portato/backend/portage/system.py
+++ b/portato/backend/portage/system.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+from future_builtins import map, filter, zip
import re, os
import portage
@@ -172,24 +172,6 @@ class PortageSystem (SystemInterface):
else:
return lambda x: True
- def geneticize_list (self, list_of_packages, only_cpv = False):
- """Convertes a list of cpv's into L{backend.Package}s.
-
- @param list_of_packages: the list of packages
- @type list_of_packages: string[]
- @param only_cpv: do nothing - return the passed list
- @type only_cpv: boolean
- @returns: converted list
- @rtype: PortagePackage[]
- """
-
- if not only_cpv:
- return [self.new_package(x) for x in list_of_packages]
- elif not isinstance(list_of_packages, list):
- return list(list_of_packages)
- else:
- return list_of_packages
-
def get_global_settings (self, key):
return self.settings.global_settings[key]
@@ -228,11 +210,18 @@ class PortageSystem (SystemInterface):
return self.setmap[pkgSet]()
def find_packages (self, key = "", pkgSet = SystemInterface.SET_ALL, masked = False, with_version = True, only_cpv = False):
- return self.geneticize_list(self._get_set(pkgSet).find(key, masked, with_version, only_cpv), only_cpv or not with_version)
+ result = self._get_set(pkgSet).find(key, masked, with_version, only_cpv)
+
+ if (not only_cpv) and with_version:
+ result = list(map(self.new_package, result))
+ else:
+ result = list(result)
+
+ return result
def list_categories (self, name = None):
categories = self.settings.global_settings.categories
- return filter(self.find_lambda(name), categories)
+ return list(filter(self.find_lambda(name), categories))
def split_cpv (self, cpv):
cpv = portage.dep_getcpv(cpv)
@@ -286,9 +275,9 @@ class PortageSystem (SystemInterface):
if len(inst) > 1:
myslots = set()
for i in inst: # get the slots of the installed packages
- myslots.add(i.get_package_settings("SLOT"))
+ myslots.add(i.get_slot())
- myslots.add(best_p.get_package_settings("SLOT")) # add the slot of the best package in portage
+ myslots.add(best_p.get_slot()) # add the slot of the best package in portage
for slot in myslots:
crit = "%s:%s" % (p, slot)
append(crit, self.find_best_match(crit), inst)
@@ -304,7 +293,7 @@ class PortageSystem (SystemInterface):
def update_world (self, sets = ("world", "system"), newuse = False, deep = False):
packages = set()
- map(packages.add, itt.chain(*[self.find_packages(pkgSet = s, with_version = False) for s in sets]))
+ list(map(packages.add, itt.chain(*[self.find_packages(pkgSet = s, with_version = False) for s in sets])))
states = [(["RDEPEND", "PDEPEND"], True)]
if self.with_bdeps():
diff --git a/portato/backend/portage/system_22.py b/portato/backend/portage/system_22.py
index c3bfa5f..882232f 100644
--- a/portato/backend/portage/system_22.py
+++ b/portato/backend/portage/system_22.py
@@ -10,8 +10,6 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
-
import os
import portage
@@ -46,7 +44,7 @@ class PortageSystem_22 (PortageSystem):
def get_sets (self, description = False):
if description:
- return ((name, set.description) for name, set in self.settings.setsconfig.getSets().iteritems())
+ return ((name, set.description) for name, set in self.settings.setsconfig.getSets().items())
else:
return tuple(self.settings.setsconfig.getSets())
diff --git a/portato/config_parser.py b/portato/config_parser.py
index 2ef52c5..45a2e66 100644
--- a/portato/config_parser.py
+++ b/portato/config_parser.py
@@ -37,9 +37,11 @@ Thus it keeps comments and structuring of the file.
Regular expression defining a normal option-value pair.
"""
-from __future__ import absolute_import, with_statement
+
__docformat__ = "restructuredtext"
+from future_builtins import map, filter, zip
+
import re
from threading import Lock
@@ -181,7 +183,7 @@ class ConfigParser:
"yes" : "no",
"ja" : "nein",
"wahr" : "falsch"}
- true_false.update(zip(true_false.values(), true_false.keys()))
+ true_false.update(list(zip(list(true_false.values()), list(true_false.keys()))))
def __init__ (self, file):
"""
@@ -348,7 +350,7 @@ class ConfigParser:
if val.is_bool():
return val.boolean
- raise ValueError, "\"%s\" is not a boolean. (%s)" % (key, val.value)
+ raise ValueError("\"%s\" is not a boolean. (%s)" % (key, val.value))
def set (self, key, value, section = "MAIN"):
"""
@@ -382,7 +384,7 @@ class ConfigParser:
val.boolean = value
val.value = self._invert(val.value)
else:
- raise ValueError, "\"%s\" is not a boolean." % key
+ raise ValueError("\"%s\" is not a boolean." % key)
def add_section (self, section, comment = None, with_blankline = True):
"""
@@ -405,7 +407,7 @@ class ConfigParser:
self.cache.append("\n")
if comment:
- if isinstance(comment, basestring):
+ if isinstance(comment, str):
comment = comment.split("\n")
# add newlines to comment at the beginning and the end
@@ -450,7 +452,7 @@ class ConfigParser:
# find line# to add
if self.vars[section]:
- mline = max((x.line for x in self.vars[section].itervalues())) + 1
+ mline = max((x.line for x in self.vars[section].values())) + 1
else: # no value inside the section at the moment
mline = self.sections[section] + 1
@@ -459,7 +461,7 @@ class ConfigParser:
mline += 1
if comment:
- if isinstance(comment, basestring):
+ if isinstance(comment, str):
comment = comment.split("\n")
for c in comment:
@@ -479,8 +481,8 @@ class ConfigParser:
return
with self.writelock:
- for sec in self.vars.itervalues():
- for val in sec.itervalues():
+ for sec in self.vars.values():
+ for val in sec.values():
if val.changed:
part1 = self.cache[val.line][:self.pos[val.line][0]] # key+DELIMITER
part2 = val.value # value
diff --git a/portato/db/__init__.py b/portato/db/__init__.py
index 21d8f80..74479e6 100644
--- a/portato/db/__init__.py
+++ b/portato/db/__init__.py
@@ -10,8 +10,6 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
-
from . import database as db
from .exceptions import UnknownDatabaseTypeError, DatabaseInstantiationError
from ..session import Session, SectionDict
@@ -71,7 +69,7 @@ class Database(db.Database):
else:
error(_("Unknown database type: %s"), type)
- raise UnknownDatabaseTypeError, type
+ raise UnknownDatabaseTypeError(type)
@classmethod
def _get_session(cls):
diff --git a/portato/db/database.py b/portato/db/database.py
index c679d06..9ab431c 100644
--- a/portato/db/database.py
+++ b/portato/db/database.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+
from threading import RLock
from functools import wraps
@@ -77,7 +77,7 @@ class Database (object):
def set_type (self, type):
if type & self.search_types() != type:
- raise UnsupportedSearchTypeError, type
+ raise UnsupportedSearchTypeError(type)
self._type = type
diff --git a/portato/db/eix_sql.py b/portato/db/eix_sql.py
index 758f42c..2a693e9 100644
--- a/portato/db/eix_sql.py
+++ b/portato/db/eix_sql.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+
try:
import sqlite3 as sql
diff --git a/portato/db/hash.py b/portato/db/hash.py
index 4a6958b..f52f4dd 100644
--- a/portato/db/hash.py
+++ b/portato/db/hash.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+
import re
from collections import defaultdict
@@ -102,7 +102,7 @@ class HashDatabase (Database):
if installed:
cats = self.inst_cats
else:
- cats = self._db.iterkeys()
+ cats = iter(self._db.keys())
else:
if installed:
@@ -124,7 +124,7 @@ class HashDatabase (Database):
except KeyError: # not in inst_cats - can be ignored
pass
- self._db[self.ALL] = filter(lambda x: x.cat != cat, self._db[self.ALL])
+ self._db[self.ALL] = [x for x in self._db[self.ALL] if x.cat != cat]
self.populate(cat+"/*")
else:
self.__initialize()
@@ -148,7 +148,7 @@ class HashDatabase (Database):
else:
try:
regex = re.compile(restrict, re.I)
- except re.error, e:
+ except re.error as e:
info(_("Error while compiling search expression: '%s'."), str(e))
else: # only set self._restrict if no error occurred
self._restrict = regex
diff --git a/portato/db/sql.py b/portato/db/sql.py
index 581ebc4..f3b93f0 100644
--- a/portato/db/sql.py
+++ b/portato/db/sql.py
@@ -10,8 +10,6 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
-
try:
import sqlite3 as sql
except ImportError:
@@ -136,7 +134,7 @@ class SQLDatabase (Database):
debug("Overlay '%s' has been removed", key)
changed = True
- for key in hashes.iterkeys():
+ for key in hashes.keys():
if key not in db:
debug("Overlay '%s' has been added.", key)
diff --git a/portato/dependency.py b/portato/dependency.py
index 4b505e6..0699b8a 100644
--- a/portato/dependency.py
+++ b/portato/dependency.py
@@ -14,7 +14,7 @@
Provides classes for the presentation of dependencies.
"""
-from __future__ import absolute_import, with_statement
+
__docformat__ = "restructuredtext"
from collections import defaultdict
@@ -165,14 +165,14 @@ class DependencyTree (object):
# use
if dep[-1] == "?":
ntree = self.add_flag(dep[:-1])
- n = it.next()
+ n = next(it)
if not hasattr(n, "__iter__"):
n = [n]
ntree.parse(n)
# or
elif dep == "||":
- n = it.next() # skip
+ n = next(it) # skip
if not hasattr(n, "__iter__"):
n = [n]
diff --git a/portato/eix/__init__.py b/portato/eix/__init__.py
index 8fa1da6..ed86ec5 100644
--- a/portato/eix/__init__.py
+++ b/portato/eix/__init__.py
@@ -14,7 +14,6 @@
A module to parse the eix-cache files.
"""
-from __future__ import absolute_import, with_statement
__docformat__ = "restructuredtext"
from . import parser
diff --git a/portato/eix/exceptions.py b/portato/eix/exceptions.py
index cc4665d..955da42 100644
--- a/portato/eix/exceptions.py
+++ b/portato/eix/exceptions.py
@@ -14,7 +14,7 @@
Different exceptions used in the eix module.
"""
-from __future__ import absolute_import, with_statement
+
__docformat__ = "restructuredtext"
class EixError (Exception):
diff --git a/portato/eix/py_parser.py b/portato/eix/py_parser.py
index 231c206..a6927a1 100644
--- a/portato/eix/py_parser.py
+++ b/portato/eix/py_parser.py
@@ -17,7 +17,7 @@ In this module (nearly) all of these types have a corresponding function.
For the exact way all the functions work, have a look at the eix format description.
"""
-from __future__ import absolute_import, with_statement
+
__docformat__ = "restructuredtext"
import os
@@ -53,7 +53,7 @@ def _get_bytes (file, length, expect_list = False):
s = file.read(length)
if len(s) != length:
- raise EndOfFileException, file.name
+ raise EndOfFileException(file.name)
if length == 1 and not expect_list:
return ord(s) # is faster than unpack and we have a scalar
@@ -187,7 +187,7 @@ def string (file, skip = False):
s = file.read(nelems)
if len(s) != nelems:
- raise EndOfFileException, file.name
+ raise EndOfFileException(file.name)
return s
diff --git a/portato/gui/__init__.py b/portato/gui/__init__.py
index bbe21d8..63f5eb0 100644
--- a/portato/gui/__init__.py
+++ b/portato/gui/__init__.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+
from ..helper import error
from .exception_handling import register_ex_handler
@@ -31,7 +31,7 @@ def run ():
del s
m.main()
- except PreReqError, e:
+ except PreReqError as e:
error("Prerequisite not matched. Aborting.")
prereq_error_dialog(e)
s.destroy()
diff --git a/portato/gui/exception_handling.py b/portato/gui/exception_handling.py
index d9b133c..10b36fc 100644
--- a/portato/gui/exception_handling.py
+++ b/portato/gui/exception_handling.py
@@ -11,12 +11,12 @@
#
# Written by René 'Necoro' Neumann
-from __future__ import absolute_import, with_statement
+from future_builtins import map, filter, zip
import gtk, pango, gobject
import sys, traceback
-from StringIO import StringIO
+from cStringIO import StringIO
from ..helper import debug, error, get_runsystem
from .dialogs import file_chooser_dialog, io_ex_dialog
@@ -78,7 +78,7 @@ class UncaughtExceptionDialog(gtk.MessageDialog):
try:
with open(file, "w") as f:
f.writelines(self.text)
- except IOError, e:
+ except IOError as e:
io_ex_dialog(e)
else:
diff --git a/portato/gui/queue.py b/portato/gui/queue.py
index b18e4e7..d3ae1f2 100644
--- a/portato/gui/queue.py
+++ b/portato/gui/queue.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+from future_builtins import map, filter, zip
# some stuff needed
import os, pty
@@ -61,7 +61,7 @@ class EmergeQueue:
# member vars
self.tree = tree
- if self.tree and not isinstance(self.tree, GtkTree): raise TypeError, "tree passed is not a GtkTree-object"
+ if self.tree and not isinstance(self.tree, GtkTree): raise TypeError("tree passed is not a GtkTree-object")
self.console = console
@@ -170,7 +170,7 @@ class EmergeQueue:
for i in new_iuse.difference(old_iuse):
changedUse.append("+"+i)
- except backend.PackageNotFoundException, e: # package not found / package is masked -> delete current tree and re-raise the exception
+ except backend.PackageNotFoundException as e: # package not found / package is masked -> delete current tree and re-raise the exception
if type == "update": # remove complete tree
self.remove_with_children(self.tree.first_iter(it), removeNewFlags = False)
@@ -321,7 +321,7 @@ class EmergeQueue:
def doEmerge (self, options, packages, its, *args, **kwargs):
top = None
if self.tree and its:
- for v in its.itervalues():
+ for v in its.values():
self.tree.set_in_progress(v)
top = self.tree.first_iter(v)
break
@@ -361,7 +361,7 @@ class EmergeQueue:
os.dup2(self.pty[1], 2)
# get all categories that are being touched during the emerge process
- cats = set(x.split("/")[0] for x in its.iterkeys())
+ cats = set(x.split("/")[0] for x in its.keys())
# start emerge
self.process = Popen(command+options+packages, shell = False, env = system.get_environment(), preexec_fn = pre)
@@ -642,7 +642,7 @@ class EmergeQueue:
elif self.tree.is_in_unmerge(it): # in Unmerge
try:
del self.iters["uninstall"][cpv]
- except KeyError, e: # this is just for debugging
+ except KeyError as e: # this is just for debugging
error("'%s' not in self.iters[\"uninstall\"] for some reason", cpv)
debug("self.iters: %s", self.iters)
raise
@@ -661,4 +661,4 @@ class EmergeQueue:
@returns: True if everything is empty and the process is not running.
@rtype: bool"""
- return not (self.process or any(map(len, self.iters.itervalues())))
+ return not (self.process or any(map(len, self.iters.values())))
diff --git a/portato/gui/slots.py b/portato/gui/slots.py
index 75f4d77..2706d75 100644
--- a/portato/gui/slots.py
+++ b/portato/gui/slots.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+
import gtk
from ..plugin import WidgetSlot # other modules might import WidgetSlot from here
diff --git a/portato/gui/updater.py b/portato/gui/updater.py
index 6539913..397797d 100644
--- a/portato/gui/updater.py
+++ b/portato/gui/updater.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+
from ..backend import system
@@ -43,7 +43,7 @@ d"""
"""
if not issubclass(threadClass, threading.Thread):
- raise ValueError, "Only subclasses of threading.Thread are allowed."
+ raise ValueError("Only subclasses of threading.Thread are allowed.")
self.queue = queue
self.iterators = iterators
diff --git a/portato/gui/utils.py b/portato/gui/utils.py
index ce5971e..07db45c 100644
--- a/portato/gui/utils.py
+++ b/portato/gui/utils.py
@@ -10,8 +10,6 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
-
# some stuff needed
import sys
import logging
@@ -45,7 +43,7 @@ class GtkThread (Thread):
try:
sys.excepthook(type, val, tb, thread = self.getName())
except TypeError:
- raise type, val, tb # let normal thread handle it
+ raise type(val).with_traceback(tb) # let normal thread handle it
finally:
del type, val, tb
diff --git a/portato/gui/views.py b/portato/gui/views.py
index bb96564..5abf081 100644
--- a/portato/gui/views.py
+++ b/portato/gui/views.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+
import gtk, gobject
import pango
@@ -126,7 +126,7 @@ class HighlightView (gtksourceview2.View, LazyView):
try:
with open(self.get_fn(self.pkg)) as f:
return f.readlines()
- except IOError, e:
+ except IOError as e:
return _("Error: %s") % e.strerror
class LogView (logging.Handler):
diff --git a/portato/gui/windows/about.py b/portato/gui/windows/about.py
index 0d2ce1a..f59e791 100644
--- a/portato/gui/windows/about.py
+++ b/portato/gui/windows/about.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+
import os
import gtk
diff --git a/portato/gui/windows/basic.py b/portato/gui/windows/basic.py
index 01d31e5..3f8c535 100644
--- a/portato/gui/windows/basic.py
+++ b/portato/gui/windows/basic.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+
# gtk stuff
import gtk
diff --git a/portato/gui/windows/mailinfo.py b/portato/gui/windows/mailinfo.py
index 4367482..3cdfb7d 100644
--- a/portato/gui/windows/mailinfo.py
+++ b/portato/gui/windows/mailinfo.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+
import smtplib, socket
import time
@@ -152,7 +152,7 @@ class MailInfoWindow (AbstractDialog):
else: debug("TLS not supported in Python. Continuing without it.")
server.sendmail(self.addr, self.TO, self.message.as_string())
- except smtplib.SMTPRecipientsRefused, e:
+ except smtplib.SMTPRecipientsRefused as e:
if e.recipients[self.TO][0] < 500:
info(_("An error occurred while sending. I think we were greylisted. The error: %s") % e)
else: raise
@@ -164,11 +164,11 @@ class MailInfoWindow (AbstractDialog):
server.quit()
except smtplib.SMTPServerDisconnected:
pass # ignore this
- except socket.error, e:
+ except socket.error as e:
gobject.idle_add(mail_failure_dialog, "%s (Code: %s)" % (e.args[1], e.args[0]))
- except smtplib.SMTPResponseException, e:
+ except smtplib.SMTPResponseException as e:
gobject.idle_add(mail_failure_dialog, "%s (Code: %s)" % (e.smtp_error, e.smtp_code))
- except smtplib.SMTPException, e:
+ except smtplib.SMTPException as e:
gobject.idle_add(mail_failure_dialog, e.args)
def cb_cancel_clicked (self, *args):
diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py
index de62f45..261b999 100644
--- a/portato/gui/windows/main.py
+++ b/portato/gui/windows/main.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+from future_builtins import map, filter, zip
# gtk stuff
import gtk
@@ -199,15 +199,15 @@ class PackageTable:
try:
try:
self.queue.append(self.pkg.get_cpv(), type = type, update = update)
- except PackageNotFoundException, e:
+ except PackageNotFoundException as e:
if dialogs.unmask_dialog(e[0]) == gtk.RESPONSE_YES:
self.queue.append(self.pkg.get_cpv(), type = type, unmask = True, update = update)
- except BlockedException, e:
+ except BlockedException as e:
dialogs.blocked_dialog(e[0], e[1])
else:
try:
self.queue.append(self.pkg.get_cpv(), type = "uninstall")
- except PackageNotFoundException, e:
+ except PackageNotFoundException as e:
error(_("Package could not be found: %s"), e[0])
#masked_dialog(e[0])
@@ -464,7 +464,7 @@ class MainWindow (Window):
splash(_("Loading Config"))
try:
self.cfg = Config(CONFIG_LOCATION)
- except IOError, e:
+ except IOError as e:
dialogs.io_ex_dialog(e)
raise
@@ -521,7 +521,7 @@ class MainWindow (Window):
# notebooks
self.sysNotebook = self.tree.get_widget("systemNotebook")
self.pkgNotebook = self.tree.get_widget("packageNotebook")
- self.set_notebook_tabpos(map(PreferenceWindow.tabpos.get, map(int, (self.cfg.get("packageTabPos", "GUI"), self.cfg.get("systemTabPos", "GUI")))))
+ self.set_notebook_tabpos(list(map(PreferenceWindow.tabpos.get, list(map(int, (self.cfg.get("packageTabPos", "GUI"), self.cfg.get("systemTabPos", "GUI")))))))
slots.NotebookSlot(self.pkgNotebook, gtk.Widget, "Package Notebook")
# the useScroll
@@ -555,9 +555,9 @@ class MainWindow (Window):
try:
try:
self.load_session()
- except OldSessionException, e:
+ except OldSessionException as e:
self.load_session(e)
- except SessionException, e:
+ except SessionException as e:
warning(str(e))
self.load_session(defaults_only = True) # last ressort
@@ -782,7 +782,7 @@ class MainWindow (Window):
# to not query the package with info, we do not need
if self.cfg.get_boolean("showSlots", "GUI"):
def get_slot(pkg):
- return pkg.get_package_settings("SLOT")
+ return pkg.get_slot()
self.slotcol.set_visible(True)
@@ -891,7 +891,7 @@ class MainWindow (Window):
def build_type_combo (self):
model = gtk.ListStore(int, str)
- for k,v in self.db.TYPES.iteritems():
+ for k,v in self.db.TYPES.items():
model.append((k,v))
self.typeCombo.set_model(model)
@@ -915,7 +915,7 @@ class MainWindow (Window):
"""
try:
self.session = Session("gui.cfg", name="GUI", oldfiles=["gtk_session.cfg"])
- except (OSError, IOError), e:
+ except (OSError, IOError) as e:
dialogs.io_ex_dialog(e)
return
@@ -953,7 +953,7 @@ class MainWindow (Window):
# PANED
def load_paned (*pos):
- pos = map(int, pos)
+ pos = list(map(int, pos))
[x.set_position(p) for x,p in zip((self.vpaned, self.hpaned), pos)]
def save_paned ():
@@ -1056,7 +1056,7 @@ class MainWindow (Window):
self.session.add_handler(value)
# set the simple ones :)
- map(_add,[
+ list(map(_add,[
([("gtksessionversion", "session")], load_session_version, lambda: SESSION_VERSION),
(["width", "height"], lambda w,h: self.window.resize(int(w), int(h)), self.window.get_size),
(["vpanedpos", "hpanedpos"], load_paned, save_paned),
@@ -1064,7 +1064,7 @@ class MainWindow (Window):
(["pkgsel"], load_pkg_selection, save_pkg_selection, ["portato@0"]),
(["searchtype"], load_search_type, lambda: self.db.type)
#([("merge", "queue"), ("unmerge", "queue"), ("oneshot", "queue")], load_queue, save_queue),
- ])
+ ]))
# set the plugins
queue = plugin.get_plugin_queue()
@@ -1073,7 +1073,8 @@ class MainWindow (Window):
self.session.add_handler(([(p.name.replace(" ","_").replace(":","_"), "plugins")], load_plugin(p), save_plugin(p)))
# the other things
- def load_cfg ((name, cat)):
+ def load_cfg (pkg):
+ (name, cat) = pkg
def load (v):
self.cfg.set_session(name, cat, v)
@@ -1086,7 +1087,7 @@ class MainWindow (Window):
self.session.add_handler(([(name, cat)], load, save))
- map(load_cfg, [("prefheight", "GUI"), ("prefwidth", "GUI")])
+ list(map(load_cfg, [("prefheight", "GUI"), ("prefwidth", "GUI")]))
# now we have the handlers -> load
self.session.load(defaults_only)
@@ -1307,7 +1308,7 @@ class MainWindow (Window):
self.selCP = "%s/%s" % (store.get_value(it, 2), store.get_value(it, 1))
try:
self.fill_version_list(self.selCP)
- except VersionsNotFoundException, e:
+ except VersionsNotFoundException as e:
warning(_("No versions of package '%s' found!") % self.selCP)
dialogs.no_versions_dialog(self.selCP)
self.db.disable(self.selCP)
@@ -1447,7 +1448,7 @@ class MainWindow (Window):
self.session.set("useflags", str(dialogs.changed_flags_dialog(_("use flags"))[1]), "dialogs")
try:
flags.write_use_flags()
- except IOError, e:
+ except IOError as e:
dialogs.io_ex_dialog(e)
return True
@@ -1460,7 +1461,7 @@ class MainWindow (Window):
try:
flags.write_masked()
flags.write_testing()
- except IOError, e:
+ except IOError as e:
dialogs.io_ex_dialog(e)
return True
else:
@@ -1494,12 +1495,12 @@ class MainWindow (Window):
try:
for pkg, old_pkg in updating:
self.queue.append(pkg.get_cpv(), type = "update", unmask = False)
- except PackageNotFoundException, e:
+ except PackageNotFoundException as e:
if dialogs.unmask_dialog(e[0]) == gtk.RESPONSE_YES:
for pkg, old_pkg in updating:
self.queue.append(pkg.get_cpv(), type = "update", unmask = True)
- except BlockedException, e:
+ except BlockedException as e:
dialogs.blocked_dialog(e[0], e[1])
self.queue.remove_children(self.queueTree.get_update_it())
@@ -1576,7 +1577,7 @@ class MainWindow (Window):
flags.write_use_flags()
flags.write_testing()
flags.write_masked()
- except IOError, e:
+ except IOError as e:
dialogs.io_ex_dialog(e)
@Window.watch_cursor
diff --git a/portato/gui/windows/pkglist.py b/portato/gui/windows/pkglist.py
index df3ef46..956d929 100644
--- a/portato/gui/windows/pkglist.py
+++ b/portato/gui/windows/pkglist.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+
import gtk
from .basic import AbstractDialog
@@ -107,11 +107,11 @@ class PkgListWindow (AbstractDialog):
try:
try:
self.queue.append(item, "install", oneshot = True)
- except PackageNotFoundException, e:
+ except PackageNotFoundException as e:
if unmask_dialog(e[0]) == gtk.RESPONSE_YES :
self.queue.append(item, "install", unmask = True, oneshot = True)
- except BlockedException, e:
+ except BlockedException as e:
blocked_dialog(e[0], e[1])
else:
for item in items:
diff --git a/portato/gui/windows/plugin.py b/portato/gui/windows/plugin.py
index 89d38f5..14d38b1 100644
--- a/portato/gui/windows/plugin.py
+++ b/portato/gui/windows/plugin.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+from future_builtins import map, filter, zip
import gtk
@@ -40,8 +40,8 @@ class PluginWindow (AbstractDialog):
self.inst = []
self.ninst = []
- self.buttons = map(self.tree.get_widget, ("disabledRB", "tempEnabledRB", "enabledRB", "tempDisabledRB"))
- map(lambda b: b.set_mode(False), self.buttons)
+ self.buttons = list(map(self.tree.get_widget, ("disabledRB", "tempEnabledRB", "enabledRB", "tempDisabledRB")))
+ list(map(lambda b: b.set_mode(False), self.buttons))
self.descrLabel = self.tree.get_widget("descrLabel")
self.authorLabel = self.tree.get_widget("authorLabel")
@@ -108,7 +108,7 @@ class PluginWindow (AbstractDialog):
debug("new changed plugins: %s => %d", plugin.name, state)
def cb_ok_clicked (self, btn):
- for plugin, val in self.changedPlugins.iteritems():
+ for plugin, val in self.changedPlugins.items():
plugin.status = val
self.close()
@@ -164,10 +164,10 @@ class PluginWindow (AbstractDialog):
try:
try:
self.queue.append(pkg, type = "install")
- except PackageNotFoundException, e:
+ except PackageNotFoundException as e:
if unmask_dialog(e[0]) == gtk.RESPONSE_YES:
self.queue.append(pkg, type = "install", unmask = True)
- except BlockedException, e:
+ except BlockedException as e:
blocked_dialog(e[0], e[1])
return True
diff --git a/portato/gui/windows/preference.py b/portato/gui/windows/preference.py
index 2b6974e..772c0c7 100644
--- a/portato/gui/windows/preference.py
+++ b/portato/gui/windows/preference.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+from future_builtins import map, filter, zip
import gtk
@@ -111,14 +111,14 @@ class PreferenceWindow (AbstractDialog):
hintEB.modify_bg(gtk.STATE_NORMAL, get_color(self.cfg, "prefhint"))
# the checkboxes
- for box, val in self.checkboxes.iteritems():
+ for box, val in self.checkboxes.items():
if isinstance(val, tuple):
self.tree.get_widget(box).set_active(self.cfg.get_boolean(val[0], section = val[1]))
else:
self.tree.get_widget(box).set_active(self.cfg.get_boolean(val))
# the edits
- for edit, val in self.edits.iteritems():
+ for edit, val in self.edits.items():
if isinstance(val,tuple):
self.tree.get_widget(edit).set_text(self.cfg.get(val[0], section = val[1]))
else:
@@ -191,13 +191,13 @@ class PreferenceWindow (AbstractDialog):
def _save(self):
"""Sets all options in the Config-instance."""
- for box, val in self.checkboxes.iteritems():
+ for box, val in self.checkboxes.items():
if isinstance(val, tuple):
self.cfg.set(val[0], self.tree.get_widget(box).get_active(), section = val[1])
else:
self.cfg.set(val, self.tree.get_widget(box).get_active())
- for edit, val in self.edits.iteritems():
+ for edit, val in self.edits.items():
if isinstance(val,tuple):
self.cfg.set(val[0], self.tree.get_widget(edit).get_text(), section = val[1])
else:
@@ -218,7 +218,7 @@ class PreferenceWindow (AbstractDialog):
self.cfg.set("packageTabPos", str(pkgPos), section = "GUI")
self.cfg.set("systemTabPos", str(sysPos), section = "GUI")
- self.tabpos_fn(map(self.tabpos.get, (pkgPos, sysPos)))
+ self.tabpos_fn(list(map(self.tabpos.get, (pkgPos, sysPos))))
self.linkbtn_fn(self.cfg.get("browserCmd", section="GUI"))
@@ -272,7 +272,7 @@ class PreferenceWindow (AbstractDialog):
self._save()
try:
self.cfg.write()
- except IOError, e:
+ except IOError as e:
io_ex_dialog(e)
self.window.destroy()
diff --git a/portato/gui/windows/search.py b/portato/gui/windows/search.py
index f9191d7..9485396 100644
--- a/portato/gui/windows/search.py
+++ b/portato/gui/windows/search.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+
import gtk
from .basic import AbstractDialog
diff --git a/portato/gui/windows/splash.py b/portato/gui/windows/splash.py
index 2e9d5a8..bd46f62 100644
--- a/portato/gui/windows/splash.py
+++ b/portato/gui/windows/splash.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+
import gtk
diff --git a/portato/helper.py b/portato/helper.py
index eb8ae2d..d1fb65d 100644
--- a/portato/helper.py
+++ b/portato/helper.py
@@ -13,7 +13,7 @@
"""
Some nice functions used in the program.
"""
-from __future__ import absolute_import, with_statement
+
import os, logging
@@ -74,11 +74,11 @@ def paren_reduce(mystr):
subsec,tail = paren_reduce(subsec)
else:
subsec,tail = mystr.split(")",1)
- subsec = filter(None, subsec.split(" "))
+ subsec = [_f for _f in subsec.split(" ") if _f]
return [mylist+subsec,tail]
mystr = tail
if freesec:
- mylist = mylist + filter(None, freesec.split(" "))
+ mylist = mylist + [_f for _f in freesec.split(" ") if _f]
if subsec is not None:
mylist = mylist + [subsec]
return mylist
diff --git a/portato/listener.py b/portato/listener.py
index b3a3ba0..b30869d 100644
--- a/portato/listener.py
+++ b/portato/listener.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+
import os
from subprocess import Popen
@@ -90,7 +90,7 @@ class Listener (object):
def __send (self, string):
try:
self.mq.send(string)
- except ipc.MessageQueueError, e:
+ except ipc.MessageQueueError as e:
error(_("An exception occured while accessing the message queue: %s"), e)
def send_notify (self, base = "", descr = "", icon = "", urgency = None):
diff --git a/portato/log.py b/portato/log.py
index b6462e9..c945372 100644
--- a/portato/log.py
+++ b/portato/log.py
@@ -10,8 +10,6 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
-
import logging
import sys
import os
@@ -41,7 +39,7 @@ class OutputFormatter (logging.Formatter):
def __init__(self, *args, **kwargs):
logging.Formatter.__init__(self, *args, **kwargs)
- for key, value in self.colors.iteritems():
+ for key, value in self.colors.items():
self.colors[key] = "\x1b[01;%02dm*\x1b[39;49;00m" % value
if hasattr(sys.stderr, "fileno"):
diff --git a/portato/plugin.py b/portato/plugin.py
index 11a40c8..f510540 100644
--- a/portato/plugin.py
+++ b/portato/plugin.py
@@ -13,14 +13,12 @@
"""
A module managing the plugins for Portato.
"""
-
-from __future__ import absolute_import
__docformat__ = "restructuredtext"
import os
import os.path as osp
import traceback
-from collections import defaultdict
+from collections import defaultdict, Callable
from functools import wraps
from . import helper
@@ -329,7 +327,7 @@ class WidgetPlugin (Plugin):
"""
if not slot in WidgetSlot.slots:
- raise PluginLoadException, "Could not find specified widget slot: %s" % slot
+ raise PluginLoadException("Could not find specified widget slot: %s" % slot)
self.__widgets.append(Widget(slot, widget))
@@ -352,14 +350,14 @@ class WidgetPlugin (Plugin):
try:
widget = WidgetSlot.slots[slot].widget
except KeyError:
- raise PluginLoadException, "Could not find specified widget slot: %s" % slot
+ raise PluginLoadException("Could not find specified widget slot: %s" % slot)
if not hasattr(args, "__iter__"):
w = widget(args)
else:
w = widget(*args)
- for k,v in kwargs.iteritems():
+ for k,v in kwargs.items():
w.connect(k, v)
self.add_widget(slot, w)
@@ -441,8 +439,8 @@ class PluginQueue (object):
for p in plugins: # import them
try:
- exec "from portato.plugins import %s" % p in {}
- except PluginLoadException, e:
+ exec("from portato.plugins import %s" % p, {})
+ except PluginLoadException as e:
error(_("Loading plugin '%(plugin)s' failed: %(error)s"), {"plugin" : p, "error" : e})
except:
tb = traceback.format_exc()
@@ -455,7 +453,7 @@ class PluginQueue (object):
if isinstance(p, WidgetPlugin):
try:
p._widget_init(window)
- except PluginLoadException, e:
+ except PluginLoadException as e:
error(_("Loading plugin '%(plugin)s' failed: %(error)s"), {"plugin" : p, "error" : e})
except:
tb = traceback.format_exc()
@@ -480,14 +478,14 @@ class PluginQueue (object):
:raise PluginLoadException: passed plugin is not of class `Plugin`
"""
- if callable(plugin) and issubclass(plugin, Plugin):
+ if isinstance(plugin, Callable) and issubclass(plugin, Plugin):
p = plugin(disable = disable) # need an instance and not the class
elif isinstance(plugin, Plugin):
p = plugin
if disable:
p.status = p.STAT_HARD_DISABLED
else:
- raise PluginLoadException, "Is neither a subclass nor an instance of Plugin."
+ raise PluginLoadException("Is neither a subclass nor an instance of Plugin.")
p._init()
@@ -606,10 +604,10 @@ class PluginQueue (object):
self._resolve_unresolved(unresolved_before, unresolved_after)
- for hook, calls in star_before.iteritems():
+ for hook, calls in star_before.items():
self.hooks[hook].before.extend(calls) # append the list
- for hook, calls in star_after.iteritems():
+ for hook, calls in star_after.items():
self.hooks[hook].after.extend(calls) # append the list
def _resolve_unresolved (self, before, after):
@@ -700,7 +698,7 @@ def register (plugin, disable = False):
if __plugins is not None:
try:
__plugins.add(plugin, disable)
- except PluginLoadException, e:
+ except PluginLoadException as e:
error(_("Registrating plugin '%(plugin)s' failed: %(error)s"), {"plugin" : plugin, "error" : e})
except:
tb = traceback.format_exc()
diff --git a/portato/session.py b/portato/session.py
index aadf6c4..e1ed7d3 100644
--- a/portato/session.py
+++ b/portato/session.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import, with_statement
+from future_builtins import map, filter, zip
import os
from UserDict import DictMixin
@@ -75,16 +75,16 @@ class Session (object):
# add version check
self.add_handler(([("version", "session")], self.check_version, lambda: self.VERSION))
- def add_handler (self, (options, load_fn, save_fn), default = None):
+ def add_handler (self, handler, default = None):
"""
Adds a handler to this session. A handler is a three-tuple consisting of:
- a list of (key,section) values
- a function getting number of option arguments and applying them to the program
- a function returning the number of option return values - getting them out of the program
"""
-
- convert = lambda (x,y): (unicode(y).upper(), unicode(x).lower())
- options = map(lambda x: (self._name, unicode(x).lower()) if not hasattr(x, "__iter__") else convert(x), options)
+ (options, load_fn, save_fn) = handler
+ convert = lambda x_y: (unicode(x_y[1]).upper(), unicode(x_y[0]).lower())
+ options = [(self._name, unicode(x).lower()) if not hasattr(x, "__iter__") else convert(x) for x in options]
self._handlers.append((options, load_fn, save_fn, default))
def load (self, defaults_only = False):
@@ -124,7 +124,7 @@ class Session (object):
debug("Saving %s with values %s", options, vals)
for value, (section, option) in zip(vals, options):
- self.set(option, str(value), section)
+ self.set(option, unicode(value), section)
with open(self._file, "w") as f:
self._cfg.write(f)
@@ -163,7 +163,7 @@ class Session (object):
try:
return self._cfg.getboolean(section, key)
- except NoSuchThing, ValueError:
+ except NoSuchThing as ValueError:
return None
def remove (self, key, section = None):
@@ -209,7 +209,7 @@ class SectionDict (DictMixin):
item = self._session.get(name, section = self._section)
if item is None:
- raise KeyError, "%s not in section %s" % (name, self._section)
+ raise KeyError("%s not in section %s" % (name, self._section))
return item
def __setitem__ (self, name, value):
diff --git a/portato/su.py b/portato/su.py
index eb1f031..41d8c5c 100644
--- a/portato/su.py
+++ b/portato/su.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import with_statement, absolute_import
+
import os
diff --git a/portato/waiting_queue.py b/portato/waiting_queue.py
index 1e3f7ad..64fe727 100644
--- a/portato/waiting_queue.py
+++ b/portato/waiting_queue.py
@@ -10,8 +10,6 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
-
from threading import Thread, Event
from Queue import Queue
@@ -19,7 +17,7 @@ class WaitingQueue (Queue):
def __init__ (self, setTrue = True, threadClass = Thread):
if not issubclass(threadClass, Thread):
- raise ValueError, "Only subclasses of threading.Thread are allowed."
+ raise ValueError("Only subclasses of threading.Thread are allowed.")
Queue.__init__(self)
self.event = Event()