Re: [OpenWrt-Devel] [PATCH, v2] feeds: search packages by license

2015-01-22 Thread John Crispin


On 20/01/2015 23:20, Eric Schultz wrote:
 Currently, the feeds scripts provides no way to filter by packages by license 
 or no license. 
 This patch adds a search feature to feeds which can be used to search 
 packages by license or by no 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 eschu...@prplfoundation.org
 ---

[...]

  
 @@ -642,6 +704,8 @@ Commands:
   search [options] substring: Search for a package
   Options:
   -r feedname: Only search in this feed
 + -l license:  Only include packages with this license
 + -n:Only include packages without a license tag

i think there parameters are still sub optimal

How about these 2
-l Only include packages with a license
-n List all packages that have no license (developer use)

additionally your text editor seems to be wonky and uses leading spaces
instead of tabs. please make sure you use tabs. I also spotted 2-3
whitespace fixes, these should be in a seperate patch and not
intermingled with the actual feature patch




  
   uninstall -a|package: Uninstall a package
   Options:
 
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH, v2] feeds: search packages by license

2015-01-20 Thread Eric Schultz
Currently, the feeds scripts provides no way to filter by packages by license 
or no license. 
This patch adds a search feature to feeds which can be used to search packages 
by license or by no 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 eschu...@prplfoundation.org
---
 scripts/feeds | 90 ++-
 1 file changed, 77 insertions(+), 13 deletions(-)

diff --git a/scripts/feeds b/scripts/feeds
index 31ad544..4bb4a3b 100755
--- a/scripts/feeds
+++ b/scripts/feeds
@@ -151,7 +151,7 @@ sub update_feed_via() {
my $name = shift;
my $src = shift;
my $relocate = shift;
-   
+
my $m = $update_method{$type};
my $localpath = ./feeds/$name;
my $safepath = $localpath;
@@ -173,7 +173,7 @@ sub update_feed_via() {
} else {
system(cd '$safepath'; $m-{'update'}) == 0 or return 1;
}
-   
+
return 0;
 }
 
@@ -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 or $search_parameters-{use_params};
 
-   return unless @substr  0;
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] substring: Search for a package
Options:
-r feedname: Only search in this feed
+   -l license:  Only