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 match_from_list
10 from portage.localization import _
11 from portage.util import grablines, normalize_path
12 from portage.versions import catpkgsplit
14 def getmaskingreason(mycpv, metadata=None, settings=None, portdb=None, return_location=False):
16 settings = portage.settings
18 portdb = portage.portdb
19 mysplit = catpkgsplit(mycpv)
21 raise ValueError(_("invalid CPV: %s") % mycpv)
23 db_keys = list(portdb._aux_cache_keys)
25 metadata = dict(zip(db_keys, portdb.aux_get(mycpv, db_keys)))
27 if not portdb.cpv_exists(mycpv):
30 # Can't access SLOT due to corruption.
31 cpv_slot_list = [mycpv]
33 cpv_slot_list = ["%s:%s" % (mycpv, metadata["SLOT"])]
34 mycp=mysplit[0]+"/"+mysplit[1]
36 # XXX- This is a temporary duplicate of code from the config constructor.
37 locations = [os.path.join(settings["PORTDIR"], "profiles")]
38 locations.extend(settings.profiles)
39 for ov in settings["PORTDIR_OVERLAY"].split():
40 profdir = os.path.join(normalize_path(ov), "profiles")
41 if os.path.isdir(profdir):
42 locations.append(profdir)
43 locations.append(os.path.join(settings["PORTAGE_CONFIGROOT"],
46 pmasklists = [(x, grablines(os.path.join(x, "package.mask"), recursive=1)) for x in locations]
48 if mycp in settings.pmaskdict:
49 for x in settings.pmaskdict[mycp]:
50 if match_from_list(x, cpv_slot_list):
51 for pmask in pmasklists:
54 pmask_filename = os.path.join(pmask[0], "package.mask")
55 for i in range(len(pmask[1])):
56 l = pmask[1][i].strip()
64 if comment_valid != i:
67 return (comment, pmask_filename)
70 elif comment_valid != -1:
71 # Apparently this comment applies to muliple masks, so
72 # it remains valid until a blank line is encountered.