From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1SjHhr-0005kE-8W for garchives@archives.gentoo.org; Mon, 25 Jun 2012 22:24:27 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3FECE21C151; Mon, 25 Jun 2012 22:23:45 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 0482821C151 for ; Mon, 25 Jun 2012 22:23:44 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 206181B44CA for ; Mon, 25 Jun 2012 22:23:44 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id DBFAAE5438 for ; Mon, 25 Jun 2012 22:23:42 +0000 (UTC) From: "Slava Bacherikov" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Slava Bacherikov" Message-ID: <1340641854.d79c036afe5ca03db247f66c83da760722a5ccf7.bacher09@gentoo> Subject: [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/package_info/generic_metadata/ X-VCS-Repository: proj/gentoo-packages X-VCS-Files: gpackages/libs/package_info/generic_metadata/license_groups.py X-VCS-Directories: gpackages/libs/package_info/generic_metadata/ X-VCS-Committer: bacher09 X-VCS-Committer-Name: Slava Bacherikov X-VCS-Revision: d79c036afe5ca03db247f66c83da760722a5ccf7 X-VCS-Branch: master Date: Mon, 25 Jun 2012 22:23:42 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: a7d6344e-cecb-4843-ac10-21e56bb49214 X-Archives-Hash: a15375469e05e256f122db0dbd426712 commit: d79c036afe5ca03db247f66c83da760722a5ccf7 Author: Slava Bacherikov bacher09 org> AuthorDate: Mon Jun 25 16:30:54 2012 +0000 Commit: Slava Bacherikov bacherikov org ua> CommitDate: Mon Jun 25 16:30:54 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoo-packag= es.git;a=3Dcommit;h=3Dd79c036a Add class to work with license groups --- .../generic_metadata/license_groups.py | 68 ++++++++++++++= ++++- 1 files changed, 64 insertions(+), 4 deletions(-) diff --git a/gpackages/libs/package_info/generic_metadata/license_groups.= py b/gpackages/libs/package_info/generic_metadata/license_groups.py index e30eb81..dc86f1b 100644 --- a/gpackages/libs/package_info/generic_metadata/license_groups.py +++ b/gpackages/libs/package_info/generic_metadata/license_groups.py @@ -1,5 +1,7 @@ from collections import defaultdict -from ..generic import file_get_content, StrThatIgnoreCase +from ..generic import file_get_content, StrThatIgnoreCase, ToStrMixin + +DEFAULT_FILE_PATH =3D '/usr/portage/profiles/license_groups' =20 def first_and_other(lst): return (lst[0], lst[1:]) if len(lst) > 0 else (None, []) @@ -36,11 +38,69 @@ def parse_groups(groups_str): =20 return lic_dct =20 - -def load_groups(file_path =3D '/usr/portage/profiles/license_groups'): +def load_groups(file_path =3D DEFAULT_FILE_PATH): + """Load file profiles/license_groups and represend it as dict + Args: + file_path -- full path to license_groups file, by default it=20 + /usr/portage/profiles/license_groups + Returns: + dict with license group as key and set of licenses as value + Example: + {u'EULA': set([u'cadsoft', ...]), u'GPL-COMPATIBLE': set([...]),= ...} + """ fc =3D file_get_content(file_path) =20 if fc is None: - return [] + return {} =20 return parse_groups(fc) + + +class LicenseGroups(ToStrMixin): + + def __init__(self, file_path =3D DEFAULT_FILE_PATH): + """Args: + file_path -- full path to license_groups file, by default it= =20 + /usr/portage/profiles/license_groups + """ + self.groups_path =3D file_path + self.groups_dict =3D load_groups(file_path) + self.reverse_group_dict =3D self.gen_reverse_dict() + + def gen_reverse_dict(self): + temp_dict =3D defaultdict(set) + for group, licenses in self.groups_dict.iteritems(): + for lic in licenses: + temp_dict[lic].add(group) + + return temp_dict + + def get_licenses_by_group(self, group_name): + """Args: + group_name -- License group name + + Returns: + return set of licenses that belong to group_name + + Example: + get_licenses_by_group('OSI-APPROVED') -> set([u'AFL-3.0', ..= .]) + """ + =20 + return self.groups_dict[group_name] + + def get_groups_by_license(self, license_name): + """Args: + license_name -- License name + + Returns: + return set of license groups that belong to license + + Example: + get_groups_by_license('GPL-1') -> set([u'FREE', ...]) + """ + return self.reverse_group_dict[license_name] + + + def __unicode__(self): + return unicode(self.groups_path) +