-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_year_in_copyright.pl
More file actions
executable file
·64 lines (49 loc) · 1.32 KB
/
set_year_in_copyright.pl
File metadata and controls
executable file
·64 lines (49 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env perl
use strict;
use warnings;
use File::Find;
# either pass in a year to change to or use this year
my $path = $ARGV[0] || die("You must provide the path to the Padre directory");
my $this_year = $ARGV[1] || (localtime)[5] + 1900;
# this is what we are looking for:
# Copyright 2008-\d{4} The Padre development team as listed in Padre.pm.
print "Setting year to $this_year.";
my @ignore = ( '.svn', 'blib' );
my @files;
find( \&files, $path );
foreach my $file (@files) {
print "Checking: $file\n";
open( my $fh, '<', $file ) or die "Failed to open $file: $!\n";
my @contents = <$fh>;
close($fh);
my $changed = 0;
foreach my $line (@contents) {
if ( $line =~ m/(.*Copyright 2008-)(\d{4})( The Padre development team as listed in Padre\.pm\..*)/ ) {
$line = "$1$this_year$3\n";
$changed = 1;
}
}
if ($changed) {
print "*** $file has changed = $changed\n";
open( my $fh, '>', $file ) or die("Failed to open the file for writing $file: $!\n");
print $fh @contents;
close($fh) or die("Failed to close the file $file: $!\n");
}
}
sub files {
my $file = $File::Find::name;
if ( !ignore_file($file) ) {
push @files, $file;
}
}
sub ignore_file {
my $file = shift;
my $ignore = 0;
foreach my $pat (@ignore) {
if ( $file =~ m/$pat/ ) {
$ignore = 1;
last;
}
}
return $ignore;
}