From 55c491ff2b2bd86044ff4082035730f6dbc2f2a3 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Thu, 21 Apr 2011 16:17:41 +0400 Subject: [PATCH] Add function for getting package use flags. --- pym/cl_utils.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pym/cl_utils.py b/pym/cl_utils.py index ab7bc8e..55ff7cf 100644 --- a/pym/cl_utils.py +++ b/pym/cl_utils.py @@ -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))