Add function for getting package use flags.

develop
Mike Hiretsky 13 years ago
parent 0a323dbacc
commit 55c491ff2b

@ -858,3 +858,40 @@ def reVerSplitToPV(x):
'PV':"",
'PR':"",
'PVR':""}.copy()
def getPkgUses(fullpkg):
"""Get USE and IUSE from package"""
category,slash,pkg = fullpkg.partition('/')
pkgCategory = '/var/db/pkg/{0}'.format(category)
packages = filter(lambda x:x['PN'] == pkg,
map(reVerSplitToPV,
filter(lambda x:x,
map(lambda x:reVerSplit.search(x),
listDirectory(pkgCategory)))))
if not packages:
return None
usePath = os.path.join(pkgCategory,packages[-1]['PF'],"USE")
iusePath = os.path.join(pkgCategory,packages[-1]['PF'],"IUSE")
return (map(lambda x:x[1:] if x.startswith("+") else x,
filter(lambda x:x,
open(usePath,'r').read().strip().split())),
map(lambda x:x[1:] if x.startswith("+") else x,
filter(lambda x:x,
open(iusePath,'r').read().strip().split())))
def getPkgActiveUses(fullpkg):
"""Get active uses from package"""
res = getPkgUses(fullpkg)
if not res:
return None
return list(set(res[0]) & set(res[1]))
def getSquashList():
"""Get supprted squashfs compressions method"""
wantMethod = set(["lzo","lzma","xz","gzip"])
usesSquashFs = getPkgActiveUses("sys-fs/squashfs-tools")
if not usesSquashFs:
return ["gzip"]
else:
return map(lambda x:{"lzma":"xz"}.get(x,x),
list(set(usesSquashFs) & wantMethod))

Loading…
Cancel
Save