add function getlicensetexts() to extract license texts relevant to a given cpv ...
authorMarius Mauch <genone@gentoo.org>
Thu, 26 Oct 2006 16:18:00 +0000 (16:18 -0000)
committerMarius Mauch <genone@gentoo.org>
Thu, 26 Oct 2006 16:18:00 +0000 (16:18 -0000)
svn path=/main/trunk/; revision=4826

pym/portage.py

index c81e34479610f58e988b4667e70c5e50bab75d38..2862db7cc18b3c3230444e1645a16f4287954349 100644 (file)
@@ -3832,6 +3832,33 @@ def cpv_expand(mycpv, mydb=None, use_cache=1, settings=None):
        else:
                return mykey
 
+def getlicensetexts(mycpv, settings=None, portdb=None, onlymasked=True):
+       if portdb is None:
+               portdb = globals()["portdb"]
+       if settings is None:
+               settings = config(clone=globals()["settings"])
+
+       license_data = portdb.aux_get(mycpv, ["LICENSE"])[0]
+       settings.setcpv(mycpv, mydb=portdb)
+       acceptable_licenses = settings.acceptable_licenses(mycpv)
+
+       def str_matches(myatom):
+               return (not onlymasked) and (myatom in acceptable_licenses)
+
+       license_list = dep_check(license_data, None, settings,
+               str_matches=str_matches)[1]
+       if onlymasked and "*" in acceptable_licenses:
+               license_list = []
+
+       rValue = {}
+       for lic in license_list:
+               # Account for overlays here? How?
+               licfilename = os.path.join(settings["PORTDIR"], "licenses", lic)
+               fd = open(licfilename, "r")
+               rValue[lic] = (licfilename, fd.read())
+               fd.close()
+       return rValue
+
 def getpmaskcomment(mycpv, settings=None, portdb=None):
        from portage_util import grablines
        if settings is None: