summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Luther <SebastianLuther@gmx.de>2010-08-27 09:02:50 +0200
committerZac Medico <zmedico@gentoo.org>2010-08-27 08:42:07 -0700
commita569acee165f2533c15322e8e0c33f322baae9f2 (patch)
tree4b3f6bd5d3dabc44367716aa419d5665bad77d4a
parent58d259d79a2d15a1dff1a90ff066615318b35917 (diff)
downloadportage-a569acee165f2533c15322e8e0c33f322baae9f2.tar.gz
portage-a569acee165f2533c15322e8e0c33f322baae9f2.tar.bz2
portage-a569acee165f2533c15322e8e0c33f322baae9f2.zip
config: Avoid copying _license_manager
Strictly speaking _license_manager is not immutable. Users need to ensure that extract_global_changes() is called right after __init__ (if at all). It also has the mutable member _undef_lic_groups. It is used to track undifiend license groups, to not display an error message for the same group again and again. Because of this, it's useful to share it between all LicenseManager instances.
-rw-r--r--pym/portage/package/ebuild/_config/LicenseManager.py36
-rw-r--r--pym/portage/package/ebuild/config.py26
-rw-r--r--pym/portage/tests/ebuild/test_config.py16
-rw-r--r--pym/portage/tests/resolver/ResolverPlayground.py7
4 files changed, 31 insertions, 54 deletions
diff --git a/pym/portage/package/ebuild/_config/LicenseManager.py b/pym/portage/package/ebuild/_config/LicenseManager.py
index 4ce1123b0..e092e411f 100644
--- a/pym/portage/package/ebuild/_config/LicenseManager.py
+++ b/pym/portage/package/ebuild/_config/LicenseManager.py
@@ -5,8 +5,6 @@ __all__ = (
'LicenseManager',
)
-from copy import deepcopy
-
from portage import os
from portage.dep import ExtendedAtomDict, use_reduce
from portage.exception import InvalidDependString
@@ -19,46 +17,30 @@ from portage.package.ebuild._config.helper import ordered_by_atom_specificity
class LicenseManager(object):
- def __init__(self, _copy=False):
- if _copy:
- return
+ def __init__(self, license_group_locations, abs_user_config, user_config=True):
+
self._accept_license_str = None
self._accept_license = None
self._license_groups = {}
self._plicensedict = ExtendedAtomDict(dict)
self._undef_lic_groups = set()
- def __deepcopy__(self, memo=None):
-
- if memo is None:
- memo = {}
- result = LicenseManager(_copy=True)
- memo[id(self)] = result
-
- # immutable attributes
- result._accept_license_str = self._accept_license_str
- memo[id(self._accept_license_str)] = self._accept_license_str
- result._accept_license = self._accept_license
- memo[id(self._accept_license)] = self._accept_license
-
- # immutable attributes (internal policy ensures lack of mutation)
- result._license_groups = self._license_groups
- memo[id(self._license_groups)] = self._license_groups
+ if user_config:
+ license_group_locations = list(license_group_locations) + [abs_user_config]
- # mutable attributes
- result._plicensedict = deepcopy(self._plicensedict, memo)
- result._undef_lic_groups = deepcopy(self._undef_lic_groups, memo)
+ self._read_license_groups(license_group_locations)
- return result
+ if user_config:
+ self._read_user_config(abs_user_config)
- def read_config_files(self, abs_user_config):
+ def _read_user_config(self, abs_user_config):
licdict = grabdict_package(os.path.join(
abs_user_config, "package.license"), recursive=1, allow_wildcard=True)
for k, v in licdict.items():
self._plicensedict.setdefault(k.cp, {})[k] = \
self.expandLicenseTokens(v)
- def parse_license_groups(self, locations):
+ def _read_license_groups(self, locations):
for loc in locations:
for k, v in grabdict(
os.path.join(loc, "license_groups")).items():
diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py
index a978e33d1..122a7f6ed 100644
--- a/pym/portage/package/ebuild/config.py
+++ b/pym/portage/package/ebuild/config.py
@@ -344,7 +344,6 @@ class config(object):
self.modifiedkeys = []
self.uvlist = []
self._accept_chost_re = None
- self._license_manager = LicenseManager()
self._accept_properties = None
self._features_overrides = []
@@ -429,7 +428,14 @@ class config(object):
self.features._features = copy.deepcopy(clone.features._features)
self._features_overrides = copy.deepcopy(clone._features_overrides)
- self._license_manager = copy.deepcopy(clone._license_manager)
+ #Strictly speaking _license_manager is not immutable. Users need to ensure that
+ #extract_global_changes() is called right after __init__ (if at all).
+ #It also has the mutable member _undef_lic_groups. It is used to track
+ #undifiend license groups, to not display an error message for the same
+ #group again and again. Because of this, it's useful to share it between
+ #all LicenseManager instances.
+ self._license_manager = clone._license_manager
+
self._accept_properties = copy.deepcopy(clone._accept_properties)
self._ppropertiesdict = copy.deepcopy(clone._ppropertiesdict)
self._penvdict = copy.deepcopy(clone._penvdict)
@@ -849,6 +855,13 @@ class config(object):
self._use_manager.extract_global_USE_changes( \
self.configdict["conf"].get("USE", ""))
+ #Read license_groups and optionally license_groups and package.license from user config
+ self._license_manager = LicenseManager(locations, abs_user_config, user_config=local_config)
+ #Extract '*/*' entries from package.license
+ self.configdict["conf"]["ACCEPT_LICENSE"] = \
+ self._license_manager.extract_global_changes( \
+ self.configdict["conf"].get("ACCEPT_LICENSE", ""))
+
if local_config:
locations.append(abs_user_config)
@@ -877,12 +890,6 @@ class config(object):
v = accept_keywords_defaults
self.pkeywordsdict.setdefault(k.cp, {})[k] = v
- #package.license
- self._license_manager.read_config_files(abs_user_config)
- self.configdict["conf"]["ACCEPT_LICENSE"] = \
- self._license_manager.extract_global_changes(\
- self.configdict["conf"].get("ACCEPT_LICENSE", ""))
-
#package.properties
propdict = grabdict_package(os.path.join(
abs_user_config, "package.properties"), recursive=1, allow_wildcard=True)
@@ -1013,9 +1020,6 @@ class config(object):
else:
self.pprovideddict[mycatpkg]=[x]
- # parse licensegroups
- self._license_manager.parse_license_groups(locations)
-
# reasonable defaults; this is important as without USE_ORDER,
# USE will always be "" (nothing set)!
if "USE_ORDER" not in self:
diff --git a/pym/portage/tests/ebuild/test_config.py b/pym/portage/tests/ebuild/test_config.py
index 6b655daf0..f48717d4f 100644
--- a/pym/portage/tests/ebuild/test_config.py
+++ b/pym/portage/tests/ebuild/test_config.py
@@ -1,11 +1,8 @@
# Copyright 2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import copy
-
import portage
from portage import os
-from portage.dep import ExtendedAtomDict
from portage.package.ebuild.config import config
from portage.package.ebuild._config.LicenseManager import LicenseManager
from portage.tests import TestCase
@@ -60,26 +57,15 @@ class ConfigTestCase(TestCase):
license_group_locations = (os.path.join(playground.portdir, "profiles"),)
pkg_license = os.path.join(playground.eroot, "etc", "portage")
- lic_man = LicenseManager()
-
- lic_man.parse_license_groups(license_group_locations)
- lic_man.read_config_files(pkg_license)
- lic_man_backup = copy.deepcopy(lic_man)
+ lic_man = LicenseManager(license_group_locations, pkg_license)
self.assertEqual(lic_man._accept_license_str, None)
- self.assertEqual(lic_man._accept_license_str, lic_man_backup._accept_license_str)
self.assertEqual(lic_man._accept_license, None)
- self.assertEqual(lic_man._accept_license, lic_man_backup._accept_license)
self.assertEqual(lic_man._license_groups, {"EULA": ["TEST"]})
- self.assertEqual(lic_man._license_groups, lic_man_backup._license_groups)
- self.assertEqual(lic_man._plicensedict, lic_man_backup._plicensedict)
self.assertEqual(lic_man._undef_lic_groups, set(["TEST"]))
- self.assertEqual(lic_man._undef_lic_groups, lic_man_backup._undef_lic_groups)
self.assertEqual(lic_man.extract_global_changes(), "TEST TEST2")
self.assertEqual(lic_man.extract_global_changes(), "")
- self.assertEqual(lic_man_backup.extract_global_changes("TEST3 TEST4"), "TEST3 TEST4 TEST TEST2")
- self.assertEqual(lic_man_backup.extract_global_changes("TEST3 TEST4"), "TEST3 TEST4")
lic_man.set_accept_license_str("TEST TEST2")
self.assertEqual(lic_man._getPkgAcceptLicense("dev-libs/B-1", "0"), ["TEST", "TEST2", "TEST"])
diff --git a/pym/portage/tests/resolver/ResolverPlayground.py b/pym/portage/tests/resolver/ResolverPlayground.py
index 952a5f265..f7707b5ea 100644
--- a/pym/portage/tests/resolver/ResolverPlayground.py
+++ b/pym/portage/tests/resolver/ResolverPlayground.py
@@ -46,6 +46,9 @@ class ResolverPlayground(object):
os.makedirs(self.portdir)
os.makedirs(self.vdbdir)
+ if not debug:
+ portage.util.noiselimit = -2
+
self._create_ebuilds(ebuilds)
self._create_installed(installed)
self._create_profile(ebuilds, installed, profile, user_config, sets)
@@ -54,6 +57,8 @@ class ResolverPlayground(object):
self.settings, self.trees = self._load_config()
self._create_ebuild_manifests(ebuilds)
+
+ portage.util.noiselimit = 0
def _create_ebuilds(self, ebuilds):
for cpv in ebuilds:
@@ -205,7 +210,7 @@ class ResolverPlayground(object):
if profile:
#This is meant to allow the consumer to set up his own profile,
#with package.mask and what not.
- raise NotImplentedError()
+ raise NotImplementedError()
#Create profile symlink
os.makedirs(os.path.join(self.eroot, "etc"))