Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1707042 > unrolled thread

[PATCH] parse-maintainers: Add ability to specify filenames

Started byJoe Perches <joe@perches.com>
First post2017-08-09 06:10 +0200
Last post2017-08-11 12:10 +0200
Articles 2 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] parse-maintainers: Add ability to specify filenames Joe Perches <joe@perches.com> - 2017-08-09 06:10 +0200
    Re: [PATCH] parse-maintainers: Add ability to specify filenames Joe Perches <joe@perches.com> - 2017-08-11 12:10 +0200

#1707042 — [PATCH] parse-maintainers: Add ability to specify filenames

FromJoe Perches <joe@perches.com>
Date2017-08-09 06:10 +0200
Subject[PATCH] parse-maintainers: Add ability to specify filenames
Message-ID<ucqtH-1Fl-9@gated-at.bofh.it>
parse-maintainers.pl is convenient, but currently hard-code the
filenames that are used.

Allow user-specified filenames to simplify the use of the script.

Miscellanea:

o Change the file permissions to 755 to the script is executable

Signed-off-by: Joe Perches <joe@perches.com>
---
 scripts/parse-maintainers.pl | 52 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 47 insertions(+), 5 deletions(-)
 mode change 100644 => 100755 scripts/parse-maintainers.pl

diff --git a/scripts/parse-maintainers.pl b/scripts/parse-maintainers.pl
old mode 100644
new mode 100755
index e40b53db7f9f..4499cefce348
--- a/scripts/parse-maintainers.pl
+++ b/scripts/parse-maintainers.pl
@@ -1,9 +1,44 @@
 #!/usr/bin/perl -w
 
 use strict;
+use Getopt::Long qw(:config no_auto_abbrev);
+
+my $input_file = "MAINTAINERS";
+my $output_file = "MAINTAINERS.new";
+my $output_section = "SECTION.new";
+my $help = 0;
 
 my $P = $0;
 
+if (!GetOptions(
+		'input=s' => \$input_file,
+		'output=s' => \$output_file,
+		'section=s' => \$output_section,
+		'h|help|usage' => \$help,
+	    )) {
+    die "$P: invalid argument - use --help if necessary\n";
+}
+
+if ($help != 0) {
+    usage();
+    exit 0;
+}
+
+sub usage {
+    print <<EOT;
+usage: $P [options] <pattern matching regexes>
+
+  --input => MAINTAINERS file to read (default: MAINTAINERS)
+  --output => sorted MAINTAINERS file to write (default: MAINTAINERS.new)
+  --section => new sorted MAINTAINERS file to write to (default: SECTION.new)
+
+If <pattern match regexes> exist, then the sections that match the
+regexes are not written to the output file but are written to the
+section file.
+
+EOT
+}
+
 # sort comparison functions
 sub by_category($$) {
     my ($a, $b) = @_;
@@ -55,13 +90,20 @@ sub trim {
 sub alpha_output {
     my ($hashref, $filename) = (@_);
 
+    return if ! scalar(keys %$hashref);
+
     open(my $file, '>', "$filename") or die "$P: $filename: open failed - $!\n";
+    my $separator;
     foreach my $key (sort by_category keys %$hashref) {
 	if ($key eq " ") {
-	    chomp $$hashref{$key};
 	    print $file $$hashref{$key};
 	} else {
-	    print $file "\n" . $key . "\n";
+	    if (! defined $separator) {
+		$separator = "\n";
+	    } else {
+		print $file $separator;
+	    }
+	    print $file $key . "\n";
 	    foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) {
 		print $file ($pattern . "\n");
 	    }
@@ -111,7 +153,7 @@ sub file_input {
 my %hash;
 my %new_hash;
 
-file_input(\%hash, "MAINTAINERS");
+file_input(\%hash, $input_file);
 
 foreach my $type (@ARGV) {
     foreach my $key (keys %hash) {
@@ -122,7 +164,7 @@ foreach my $type (@ARGV) {
     }
 }
 
-alpha_output(\%hash, "MAINTAINERS.new");
-alpha_output(\%new_hash, "SECTION.new");
+alpha_output(\%hash, $output_file);
+alpha_output(\%new_hash, $output_section);
 
 exit(0);
-- 
2.10.0.rc2.1.g053435c

[toc] | [next] | [standalone]


#1709437

FromJoe Perches <joe@perches.com>
Date2017-08-11 12:10 +0200
Message-ID<udf3c-2bo-7@gated-at.bofh.it>
In reply to#1707042
On Tue, 2017-08-08 at 21:06 -0700, Joe Perches wrote:
> parse-maintainers.pl is convenient, but currently hard-code the
> filenames that are used.
> 
> Allow user-specified filenames to simplify the use of the script.
> 
> Miscellanea:
> 
> o Change the file permissions to 755 to the script is executable

Hey Linus.

Andrew picked this up, but his quilt based tools to not
keep the file permission change.

Could you pick this up instead please?

It could be useful if/when the MAINTAINERS file is split
and when the individual files need to be realphabetized.

Thanks.

> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  scripts/parse-maintainers.pl | 52 +++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 47 insertions(+), 5 deletions(-)
>  mode change 100644 => 100755 scripts/parse-maintainers.pl
> 
> diff --git a/scripts/parse-maintainers.pl b/scripts/parse-maintainers.pl
> old mode 100644
> new mode 100755
> index e40b53db7f9f..4499cefce348
> --- a/scripts/parse-maintainers.pl
> +++ b/scripts/parse-maintainers.pl
> @@ -1,9 +1,44 @@
>  #!/usr/bin/perl -w
>  
>  use strict;
> +use Getopt::Long qw(:config no_auto_abbrev);
> +
> +my $input_file = "MAINTAINERS";
> +my $output_file = "MAINTAINERS.new";
> +my $output_section = "SECTION.new";
> +my $help = 0;
>  
>  my $P = $0;
>  
> +if (!GetOptions(
> +		'input=s' => \$input_file,
> +		'output=s' => \$output_file,
> +		'section=s' => \$output_section,
> +		'h|help|usage' => \$help,
> +	    )) {
> +    die "$P: invalid argument - use --help if necessary\n";
> +}
> +
> +if ($help != 0) {
> +    usage();
> +    exit 0;
> +}
> +
> +sub usage {
> +    print <<EOT;
> +usage: $P [options] <pattern matching regexes>
> +
> +  --input => MAINTAINERS file to read (default: MAINTAINERS)
> +  --output => sorted MAINTAINERS file to write (default: MAINTAINERS.new)
> +  --section => new sorted MAINTAINERS file to write to (default: SECTION.new)
> +
> +If <pattern match regexes> exist, then the sections that match the
> +regexes are not written to the output file but are written to the
> +section file.
> +
> +EOT
> +}
> +
>  # sort comparison functions
>  sub by_category($$) {
>      my ($a, $b) = @_;
> @@ -55,13 +90,20 @@ sub trim {
>  sub alpha_output {
>      my ($hashref, $filename) = (@_);
>  
> +    return if ! scalar(keys %$hashref);
> +
>      open(my $file, '>', "$filename") or die "$P: $filename: open failed - $!\n";
> +    my $separator;
>      foreach my $key (sort by_category keys %$hashref) {
>  	if ($key eq " ") {
> -	    chomp $$hashref{$key};
>  	    print $file $$hashref{$key};
>  	} else {
> -	    print $file "\n" . $key . "\n";
> +	    if (! defined $separator) {
> +		$separator = "\n";
> +	    } else {
> +		print $file $separator;
> +	    }
> +	    print $file $key . "\n";
>  	    foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) {
>  		print $file ($pattern . "\n");
>  	    }
> @@ -111,7 +153,7 @@ sub file_input {
>  my %hash;
>  my %new_hash;
>  
> -file_input(\%hash, "MAINTAINERS");
> +file_input(\%hash, $input_file);
>  
>  foreach my $type (@ARGV) {
>      foreach my $key (keys %hash) {
> @@ -122,7 +164,7 @@ foreach my $type (@ARGV) {
>      }
>  }
>  
> -alpha_output(\%hash, "MAINTAINERS.new");
> -alpha_output(\%new_hash, "SECTION.new");
> +alpha_output(\%hash, $output_file);
> +alpha_output(\%new_hash, $output_section);
>  
>  exit(0);

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web