diff options
-rwxr-xr-x | bin/repoman | 2 | ||||
-rw-r--r-- | pym/portage/_sets/profiles.py | 2 | ||||
-rw-r--r-- | pym/portage/package/ebuild/_config/LicenseManager.py | 2 | ||||
-rw-r--r-- | pym/portage/package/ebuild/_config/MaskManager.py | 12 | ||||
-rw-r--r-- | pym/portage/package/ebuild/_config/UseManager.py | 4 | ||||
-rw-r--r-- | pym/portage/package/ebuild/config.py | 14 | ||||
-rw-r--r-- | pym/portage/util/__init__.py | 47 |
7 files changed, 57 insertions, 26 deletions
diff --git a/bin/repoman b/bin/repoman index 92b01ec2e..70e7cdaf2 100755 --- a/bin/repoman +++ b/bin/repoman @@ -672,7 +672,7 @@ for path in portdb.porttrees: uselist.add(use_prefix + x[0]) global_pmasklines.append(portage.util.grabfile_package( - os.path.join(path, 'profiles', 'package.mask'), recursive=1)) + os.path.join(path, 'profiles', 'package.mask'), recursive=1, verify_eapi=True)) desc_path = os.path.join(path, 'profiles', 'profiles.desc') try: diff --git a/pym/portage/_sets/profiles.py b/pym/portage/_sets/profiles.py index e47f08db3..39a296814 100644 --- a/pym/portage/_sets/profiles.py +++ b/pym/portage/_sets/profiles.py @@ -33,7 +33,7 @@ class PackagesSystemSet(PackageSet): writemsg_level("\nPackagesSystemSet: profile paths: %s\n" % \ (self._profile_paths,), level=logging.DEBUG, noiselevel=-1) - mylist = [grabfile_package(os.path.join(x, "packages")) for x in self._profile_paths] + mylist = [grabfile_package(os.path.join(x, "packages"), verify_eapi=True) for x in self._profile_paths] if debug: writemsg_level("\nPackagesSystemSet: raw packages: %s\n" % \ diff --git a/pym/portage/package/ebuild/_config/LicenseManager.py b/pym/portage/package/ebuild/_config/LicenseManager.py index e092e411f..627b03fa9 100644 --- a/pym/portage/package/ebuild/_config/LicenseManager.py +++ b/pym/portage/package/ebuild/_config/LicenseManager.py @@ -35,7 +35,7 @@ class LicenseManager(object): def _read_user_config(self, abs_user_config): licdict = grabdict_package(os.path.join( - abs_user_config, "package.license"), recursive=1, allow_wildcard=True) + abs_user_config, "package.license"), recursive=1, allow_wildcard=True, verify_eapi=False) for k, v in licdict.items(): self._plicensedict.setdefault(k.cp, {})[k] = \ self.expandLicenseTokens(v) diff --git a/pym/portage/package/ebuild/_config/MaskManager.py b/pym/portage/package/ebuild/_config/MaskManager.py index d8f06be6e..34cc6ec26 100644 --- a/pym/portage/package/ebuild/_config/MaskManager.py +++ b/pym/portage/package/ebuild/_config/MaskManager.py @@ -25,10 +25,10 @@ class MaskManager(object): repo_pkgunmasklines = [] for x in repo_profiles: repo_pkgmasklines.append(stack_lists([grabfile_package( - os.path.join(x, "package.mask"), recursive=1, remember_source_file=True)], \ + os.path.join(x, "package.mask"), recursive=1, remember_source_file=True, verify_eapi=True)], \ incremental=1, remember_source_file=True, warn_for_unmatched_removal=True)) repo_pkgunmasklines.append(stack_lists([grabfile_package( - os.path.join(x, "package.unmask"), recursive=1, remember_source_file=True)], \ + os.path.join(x, "package.unmask"), recursive=1, remember_source_file=True, verify_eapi=True)], \ incremental=1, remember_source_file=True, warn_for_unmatched_removal=True)) repo_pkgmasklines = list(chain.from_iterable(repo_pkgmasklines)) repo_pkgunmasklines = list(chain.from_iterable(repo_pkgunmasklines)) @@ -39,9 +39,9 @@ class MaskManager(object): profile_pkgunmasklines = [] for x in profiles: profile_pkgmasklines.append(grabfile_package( - os.path.join(x, "package.mask"), recursive=1, remember_source_file=True)) + os.path.join(x, "package.mask"), recursive=1, remember_source_file=True, verify_eapi=True)) profile_pkgunmasklines.append(grabfile_package( - os.path.join(x, "package.unmask"), recursive=1, remember_source_file=True)) + os.path.join(x, "package.unmask"), recursive=1, remember_source_file=True, verify_eapi=True)) profile_pkgmasklines = stack_lists(profile_pkgmasklines, incremental=1, \ remember_source_file=True, warn_for_unmatched_removal=True) profile_pkgunmasklines = stack_lists(profile_pkgunmasklines, incremental=1, \ @@ -54,10 +54,10 @@ class MaskManager(object): if user_config: user_pkgmasklines = grabfile_package( os.path.join(abs_user_config, "package.mask"), recursive=1, \ - allow_wildcard=True, remember_source_file=True) + allow_wildcard=True, remember_source_file=True, verify_eapi=False) user_pkgunmasklines = grabfile_package( os.path.join(abs_user_config, "package.unmask"), recursive=1, \ - allow_wildcard=True, remember_source_file=True) + allow_wildcard=True, remember_source_file=True, verify_eapi=False) #Stack everything together. At this point, only user_pkgmasklines may contain -atoms. #Don't warn for unmatched -atoms here, since we don't do it for any other user config file. diff --git a/pym/portage/package/ebuild/_config/UseManager.py b/pym/portage/package/ebuild/_config/UseManager.py index 9a3038bda..8b3e44b38 100644 --- a/pym/portage/package/ebuild/_config/UseManager.py +++ b/pym/portage/package/ebuild/_config/UseManager.py @@ -52,7 +52,7 @@ class UseManager(object): ret = ExtendedAtomDict(dict) if user_config: pusedict = grabdict_package( - os.path.join(location, file_name), recursive=1, allow_wildcard=True) + os.path.join(location, file_name), recursive=1, allow_wildcard=True, verify_eapi=False) for k, v in pusedict.items(): ret.setdefault(k.cp, {})[k] = v @@ -66,7 +66,7 @@ class UseManager(object): def _parse_profile_files_to_dict(self, file_name, locations, juststrings=False): ret = [] raw = [grabdict_package(os.path.join(x, file_name), - juststrings=juststrings, recursive=1) for x in locations] + juststrings=juststrings, recursive=1, verify_eapi=True) for x in locations] for rawdict in raw: cpdict = {} for k, v in rawdict.items(): diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index 2073f7fe6..fe2cc5497 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -343,7 +343,7 @@ class config(object): self.configlist.append({}) self.configdict["pkginternal"] = self.configlist[-1] - self.packages_list = [grabfile_package(os.path.join(x, "packages")) for x in self.profiles] + self.packages_list = [grabfile_package(os.path.join(x, "packages"), verify_eapi=True) for x in self.profiles] self.packages = tuple(stack_lists(self.packages_list, incremental=1)) del self.packages_list #self.packages = grab_stacked("packages", self.profiles, grabfile, incremental_lines=1) @@ -358,7 +358,7 @@ class config(object): self._pkeywords_list = [] rawpkeywords = [grabdict_package( - os.path.join(x, "package.keywords"), recursive=1) \ + os.path.join(x, "package.keywords"), recursive=1, verify_eapi=True) \ for x in self.profiles] for pkeyworddict in rawpkeywords: if not pkeyworddict: @@ -376,7 +376,7 @@ class config(object): self._p_accept_keywords = [] raw_p_accept_keywords = [grabdict_package( - os.path.join(x, "package.accept_keywords"), recursive=1) \ + os.path.join(x, "package.accept_keywords"), recursive=1, verify_eapi=True) \ for x in self.profiles] for d in raw_p_accept_keywords: if not d: @@ -580,11 +580,11 @@ class config(object): # package.accept_keywords and package.keywords pkgdict = grabdict_package( os.path.join(abs_user_config, "package.keywords"), - recursive=1, allow_wildcard=True) + recursive=1, allow_wildcard=True, verify_eapi=False) for k, v in grabdict_package( os.path.join(abs_user_config, "package.accept_keywords"), - recursive=1, allow_wildcard=True).items(): + recursive=1, allow_wildcard=True, verify_eapi=False).items(): pkgdict.setdefault(k, []).extend(v) accept_keywords_defaults = \ @@ -599,7 +599,7 @@ class config(object): #package.properties propdict = grabdict_package(os.path.join( - abs_user_config, "package.properties"), recursive=1, allow_wildcard=True) + abs_user_config, "package.properties"), recursive=1, allow_wildcard=True, verify_eapi=False) v = propdict.pop("*/*", None) if v is not None: if "ACCEPT_PROPERTIES" in self.configdict["conf"]: @@ -611,7 +611,7 @@ class config(object): #package.env penvdict = grabdict_package(os.path.join( - abs_user_config, "package.env"), recursive=1, allow_wildcard=True) + abs_user_config, "package.env"), recursive=1, allow_wildcard=True, verify_eapi=False) v = penvdict.pop("*/*", None) if v is not None: global_wildcard_conf = {} diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py index d5c87c09d..600068507 100644 --- a/pym/portage/util/__init__.py +++ b/pym/portage/util/__init__.py @@ -309,26 +309,57 @@ def grabdict(myfilename, juststrings=0, empty=0, recursive=0, incremental=1): newdict[k] = " ".join(v) return newdict -def grabdict_package(myfilename, juststrings=0, recursive=0, allow_wildcard=False): +def read_corresponding_eapi_file(filename): + """ + Read the 'eapi' file from the directory 'filename' is in. + Returns "0" if the file is not present or invalid. + """ + default = "0" + eapi_file = os.path.join(os.path.dirname(filename), "eapi") + try: + f = open(eapi_file, "r") + lines = f.readlines() + if len(lines) == 1: + eapi = lines[0] + else: + writemsg(_("--- Invalid 'eapi' file (doesn't contain exactly one line): %s\n") % (eapi_file), + noiselevel=-1) + eapi = default + f.close() + except IOError: + eapi = default + + return eapi + +def grabdict_package(myfilename, juststrings=0, recursive=0, allow_wildcard=False, verify_eapi=False): """ Does the same thing as grabdict except it validates keys with isvalidatom()""" pkgs=grabdict(myfilename, juststrings, empty=1, recursive=recursive) + eapi = None + if verify_eapi: + eapi = read_corresponding_eapi_file(myfilename) + # We need to call keys() here in order to avoid the possibility of # "RuntimeError: dictionary changed size during iteration" # when an invalid atom is deleted. atoms = {} for k, v in pkgs.items(): try: - k = Atom(k, allow_wildcard=allow_wildcard) - except InvalidAtom: - writemsg(_("--- Invalid atom in %s: %s\n") % (myfilename, k), + k = Atom(k, allow_wildcard=allow_wildcard, eapi=eapi) + except InvalidAtom as e: + writemsg(_("--- Invalid atom in %s: %s\n") % (myfilename, e), noiselevel=-1) else: atoms[k] = v return atoms -def grabfile_package(myfilename, compatlevel=0, recursive=0, allow_wildcard=False, remember_source_file=False): +def grabfile_package(myfilename, compatlevel=0, recursive=0, allow_wildcard=False, \ + remember_source_file=False, verify_eapi=False): + pkgs=grabfile(myfilename, compatlevel, recursive=recursive, remember_source_file=True) + eapi = None + if verify_eapi: + eapi = read_corresponding_eapi_file(myfilename) mybasename = os.path.basename(myfilename) atoms = [] for pkg, source_file in pkgs: @@ -339,9 +370,9 @@ def grabfile_package(myfilename, compatlevel=0, recursive=0, allow_wildcard=Fals if pkg[:1] == '*' and mybasename == 'packages': pkg = pkg[1:] try: - pkg = Atom(pkg, allow_wildcard=allow_wildcard) - except InvalidAtom: - writemsg(_("--- Invalid atom in %s: %s\n") % (myfilename, pkg), + pkg = Atom(pkg, allow_wildcard=allow_wildcard, eapi=eapi) + except InvalidAtom as e: + writemsg(_("--- Invalid atom in %s: %s\n") % (myfilename, e), noiselevel=-1) else: if pkg_orig == str(pkg): |