summaryrefslogtreecommitdiff
path: root/portato/backend
diff options
context:
space:
mode:
Diffstat (limited to 'portato/backend')
-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
11 files changed, 80 insertions, 90 deletions
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())