'LicenseManager',
)
-from copy import deepcopy
-
from portage import os
from portage.dep import ExtendedAtomDict, use_reduce
from portage.exception import InvalidDependString
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():
self.modifiedkeys = []
self.uvlist = []
self._accept_chost_re = None
- self._license_manager = LicenseManager()
self._accept_properties = None
self._features_overrides = []
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)
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)
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)
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:
# 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
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"])
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)
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:
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"))