From patchwork Mon Jan 26 21:22:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Schultz X-Patchwork-Id: 433049 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B4EC11400B7 for ; Tue, 27 Jan 2015 08:22:23 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id B918E28155D; Mon, 26 Jan 2015 22:19:50 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00 autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 55FFE28054F for ; Mon, 26 Jan 2015 22:19:46 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 HELO_IP_IN_CL16_SUBNET=-0.41 (check from: .prplfoundation. - helo: .na01-bn1-obe.outbound.protection.outlook. - helo-domain: .outlook.) FROM/MX_MATCHES_UNVR_HELO(DOMAIN)_OR_CL_NAME(DOMAIN)=-1.5 REV_IP_EQ_HELO_DOMAIN=-1.25; rate: -7.66 Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1on0136.outbound.protection.outlook.com [157.56.110.136]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Mon, 26 Jan 2015 22:19:44 +0100 (CET) Received: from [192.168.169.135] (67.53.189.3) by BY2PR06MB025.namprd06.prod.outlook.com (10.242.45.11) with Microsoft SMTP Server (TLS) id 15.1.65.19; Mon, 26 Jan 2015 21:22:06 +0000 Message-ID: <54C6B007.60006@prplfoundation.org> Date: Mon, 26 Jan 2015 15:22:15 -0600 From: Eric Schultz User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: , X-Originating-IP: [67.53.189.3] X-ClientProxiedBy: CY1PR12CA0034.namprd12.prod.outlook.com (25.160.137.44) To BY2PR06MB025.namprd06.prod.outlook.com (10.242.45.11) Authentication-Results: openwrt.org; dkim=none (message not signed) header.d=none;openwrt.org; dmarc=none action=none header.from=prplfoundation.org; X-DmarcAction-Test: None X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(3005004);SRVR:BY2PR06MB025; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004); SRVR:BY2PR06MB025; X-Forefront-PRVS: 0468FE4A2B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(6049001)(19580395003)(36756003)(77156002)(62966003)(47776003)(46102003)(23676002)(65956001)(66066001)(83506001)(77096005)(19580405001)(92566002)(65806001)(50466002)(122386002)(65816999)(54356999)(50986999)(86362001)(33656002)(229853001)(117156001)(40100003)(42186005)(87976001)(64126003)(107886001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR06MB025; H:[192.168.169.135]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:BY2PR06MB025; X-OriginatorOrg: prplfoundation.org X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2015 21:22:06.8289 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR06MB025 Subject: [OpenWrt-Devel] [PATCH, v3] feeds: search packages by license X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Currently, the feeds scripts provides no way to filter packages by their license. This patch adds a search feature to feeds which can be used to search for packages using the -l option. Additionally, use of the -n option modifies the search to only return packages which don't have a license. Calls to script/feeds which do not use the new -l or -n options should work the same as before. Signed-off-by: Eric Schultz --- scripts/feeds | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 11 deletions(-) diff --git a/scripts/feeds b/scripts/feeds index 31ad544..b098463 100755 --- a/scripts/feeds +++ b/scripts/feeds @@ -206,41 +206,103 @@ sub get_installed() { sub search_feed { my $feed = shift; + my $search_parameters = shift; my @substr = @_; my $display; - return unless @substr > 0; + return unless @substr > 0 or $search_parameters->{use_params}; + get_feed($feed); foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) { + my $pkg = $feed_package->{$name}; my $substr; my $pkgmatch = 1; next if $pkg->{vdepends}; - foreach my $substr (@substr) { - my $match; - foreach my $key (qw(name title description src)) { - $pkg->{$key} and $substr and $pkg->{$key} =~ m/$substr/i and $match = 1; - } - $match or undef $pkgmatch; - }; + if ( $search_parameters->{use_params}) + { + $pkgmatch = do_package_tags_match($pkg, $search_parameters); + } + + if (! $search_parameters->{use_params} or ( $search_parameters->{use_params} and $pkgmatch)) + { + foreach my $substr (@substr) { + my $match; + foreach my $key (qw(name title description src)) { + $pkg->{$key} and $substr and $pkg->{$key} =~ m/$substr/i and $match = 1; + } + + $match or undef $pkgmatch; + }; + } $pkgmatch and do { $display or do { print "Search results in feed '$feed':\n"; $display = 1; }; - printf "\%-25s\t\%s\n", $pkg->{name}, $pkg->{title}; + my $output_print = format_search_parameter_output($pkg, $search_parameters); + printf "\%-20s\%s\%s\n", $pkg->{name}, $output_print, $pkg->{title}; }; } return 0; } +sub format_search_parameter_output +{ + my $pkg = shift; + my $search_parameters = shift; + + my $output = "\t"; + + if (!$search_parameters->{use_params}) { + return $output; + } + + if (defined($search_parameters->{license})) { + $output = $output . sprintf(("\%-10s\t"), $pkg->{license}); + } + + return $output; +} + +sub do_package_tags_match { + my $pkg = shift; + my $parameterized_search = shift; + + + my $match = 0; + if ($pkg->{license} and $parameterized_search->{license}) { + my $substr = $parameterized_search->{license}; + my @results = grep(/^\Q$substr\E.*$/i, split(/\s/, $pkg->{license})); + + $match = @results > 0; + } + + if ($parameterized_search->{no_license}) { + $match = !defined($pkg->{license}); + } + + return $match; +} + sub search { my %opts; - getopt('r:', \%opts); + getopts('r:l:n', \%opts); + my %search_parameters; + if (defined($opts{l})) { + $search_parameters{license} = $opts{l}; + $search_parameters{use_params} = 1; + } + + if (defined($opts{n})) { + $search_parameters{no_license} = $opts{n}; + $search_parameters{use_params} = 1; + } + foreach my $feed (@feeds) { - search_feed($feed->[1], @ARGV) if (!defined($opts{r}) or $opts{r} eq $feed->[1]); + search_feed($feed->[1], \%search_parameters, @ARGV) if (!defined($opts{r}) or $opts{r} eq $feed->[1]); } } @@ -642,6 +704,8 @@ Commands: search [options] : Search for a package Options: -r : Only search in this feed + -l : Only include packages with this license + -n: Only include packages without a license tag uninstall -a|: Uninstall a package Options: