1 # Copyright 2010 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 __all__ = ['getmaskingreason']
8 from portage.const import USER_CONFIG_PATH
9 from portage.dep import Atom, match_from_list, _slot_separator, _repo_separator
10 from portage.exception import InvalidAtom
11 from portage.localization import _
12 from portage.util import grablines, normalize_path
13 from portage.versions import catpkgsplit
15 def getmaskingreason(mycpv, metadata=None, settings=None, portdb=None, return_location=False):
17 settings = portage.settings
19 portdb = portage.portdb
20 mysplit = catpkgsplit(mycpv)
22 raise ValueError(_("invalid CPV: %s") % mycpv)
24 db_keys = list(portdb._aux_cache_keys)
26 metadata = dict(zip(db_keys, portdb.aux_get(mycpv, db_keys)))
28 if not portdb.cpv_exists(mycpv):
31 # Can't access SLOT due to corruption.
32 cpv_slot_list = [mycpv]
34 pkg = "".join((mycpv, _slot_separator, metadata["SLOT"]))
35 if 'repository' in metadata:
36 pkg = "".join((pkg, _repo_separator, metadata['repository']))
38 mycp=mysplit[0]+"/"+mysplit[1]
40 # XXX- This is a temporary duplicate of code from the config constructor.
41 locations = [os.path.join(settings["PORTDIR"], "profiles")]
42 locations.extend(settings.profiles)
43 for ov in settings["PORTDIR_OVERLAY"].split():
44 profdir = os.path.join(normalize_path(ov), "profiles")
45 if os.path.isdir(profdir):
46 locations.append(profdir)
47 locations.append(os.path.join(settings["PORTAGE_CONFIGROOT"],
50 pmasklists = [(x, grablines(os.path.join(x, "package.mask"), recursive=1)) for x in locations]
52 pmaskdict = settings._mask_manager._pmaskdict
54 for x in pmaskdict[mycp]:
55 if match_from_list(x, cpv_slot_list):
57 for pmask in pmasklists:
60 pmask_filename = os.path.join(pmask[0], "package.mask")
61 for i in range(len(pmask[1])):
62 l = pmask[1][i].strip()
64 l_atom = Atom(l, allow_repo=True,
65 allow_wildcard=True).without_repo
75 if comment_valid != i:
78 return (comment, pmask_filename)
81 elif comment_valid != -1:
82 # Apparently this comment applies to muliple masks, so
83 # it remains valid until a blank line is encountered.