Changed name to get-licensed
This commit is contained in:
parent
4dfd5f8037
commit
ce05020783
@ -10,7 +10,6 @@ sub new {
|
|||||||
sub get_licenses {
|
sub get_licenses {
|
||||||
my ($self, $app) = @_;
|
my ($self, $app) = @_;
|
||||||
|
|
||||||
print "Plugins\n";
|
|
||||||
foreach my $plugin ($self->plugins()) {
|
foreach my $plugin ($self->plugins()) {
|
||||||
my $stub = $plugin->{'header'};
|
my $stub = $plugin->{'header'};
|
||||||
$stub =~ s/###DESCRIPTION###/$app->{'options'}->{'about'}/;
|
$stub =~ s/###DESCRIPTION###/$app->{'options'}->{'about'}/;
|
||||||
|
@ -6,11 +6,12 @@ use FindBin;
|
|||||||
use lib "$FindBin::Bin";
|
use lib "$FindBin::Bin";
|
||||||
use File::Find;
|
use File::Find;
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
|
use File::Copy;
|
||||||
use FileHandle;
|
use FileHandle;
|
||||||
|
use File::Glob ':globally';
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use Cwd;
|
use Cwd;
|
||||||
use File::Glob ':globally';
|
|
||||||
use Licenses;
|
use Licenses;
|
||||||
|
|
||||||
# Application configuration and state storage
|
# Application configuration and state storage
|
||||||
@ -22,6 +23,8 @@ $app->{'options'}->{'license'} = 'mit';
|
|||||||
$app->{'options'}->{'user'} = $ENV{'USER'};
|
$app->{'options'}->{'user'} = $ENV{'USER'};
|
||||||
$app->{'options'}->{'date'} = (localtime(time))[5] + 1900;
|
$app->{'options'}->{'date'} = (localtime(time))[5] + 1900;
|
||||||
$app->{'options'}->{'about'} = "This is an open-source software";
|
$app->{'options'}->{'about'} = "This is an open-source software";
|
||||||
|
$app->{'options'}->{'dry'} = 0;
|
||||||
|
|
||||||
$app->{'state'}->{'license_stub'} = "NON EXISTANT";
|
$app->{'state'}->{'license_stub'} = "NON EXISTANT";
|
||||||
$app->{'state'}->{'app_dir'} = dirname($0);
|
$app->{'state'}->{'app_dir'} = dirname($0);
|
||||||
|
|
||||||
@ -32,6 +35,7 @@ my $correct_usage = GetOptions (
|
|||||||
'about=s' => \$app->{'options'}->{'about'},
|
'about=s' => \$app->{'options'}->{'about'},
|
||||||
'user=s' => \$app->{'options'}->{'user'},
|
'user=s' => \$app->{'options'}->{'user'},
|
||||||
'date=s' => \$app->{'options'}->{'date'},
|
'date=s' => \$app->{'options'}->{'date'},
|
||||||
|
'dry' => \$app->{'options'}->{'dry'},
|
||||||
);
|
);
|
||||||
|
|
||||||
setup_licenses($app);
|
setup_licenses($app);
|
||||||
@ -83,13 +87,27 @@ sub handle_files {
|
|||||||
my($filename, $directories, $suffix) = fileparse($file, qr/\.[^.]*/);
|
my($filename, $directories, $suffix) = fileparse($file, qr/\.[^.]*/);
|
||||||
|
|
||||||
if (exists $app->{'filetype_comments'}->{$suffix}) {
|
if (exists $app->{'filetype_comments'}->{$suffix}) {
|
||||||
my $rh = new FileHandle ($name);
|
my $rh = FileHandle->new($name);
|
||||||
my @contents = <$rh>;
|
my @contents = <$rh>;
|
||||||
|
|
||||||
print "Handling... $filename - $directories - $suffix\n";
|
print "Handling... $filename - $directories - $suffix ----- " .
|
||||||
|
ref($app->{'filetype_comments'}->{$suffix}) . "\n";
|
||||||
|
|
||||||
|
my $stub = get_license_stub($app, $suffix);
|
||||||
|
|
||||||
if ((defined $contents[0]) && ($contents[0] =~ /^\s*#!/)) {
|
if ((defined $contents[0]) && ($contents[0] =~ /^\s*#!/)) {
|
||||||
print " ... has #! line\n";
|
print " ... has #! line\n";
|
||||||
|
|
||||||
|
$contents[0] = $contents[0] . "\n" . $stub . "\n";
|
||||||
|
} else {
|
||||||
|
$contents[0] = $stub . "\n" . $contents[0] . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($app->{'options'}->{'dry'} == 0) {
|
||||||
|
copy($name, $name . ".licensor_backup") or die "Could not create backup file";
|
||||||
|
|
||||||
|
my $wh = FileHandle->new($name, O_WRONLY);
|
||||||
|
print $wh @contents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -97,6 +115,29 @@ sub handle_files {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_license_stub {
|
||||||
|
my ($app, $suffix) = @_;
|
||||||
|
|
||||||
|
my $stub = $app->{'licenses'}->{$app->{'options'}->{'license'}}->{'header_stub'};
|
||||||
|
if (ref($app->{'filetype_comments'}->{$suffix}) eq '') {
|
||||||
|
$stub =~ s/^(.)/$app->{'filetype_comments'}->{$suffix} $1/msg;
|
||||||
|
$stub = $app->{'filetype_comments'}->{$suffix} . " -----\n" .
|
||||||
|
"$stub\n" .
|
||||||
|
$app->{'filetype_comments'}->{$suffix} . " -----\n";
|
||||||
|
} elsif (ref($app->{'filetype_comments'}->{$suffix}) eq 'ARRAY') {
|
||||||
|
$stub =~ s/^(.)/ $1/msg;
|
||||||
|
$stub = $app->{'filetype_comments'}->{$suffix}[0] .
|
||||||
|
" -----\n$stub\n ----- " .
|
||||||
|
$app->{'filetype_comments'}->{$suffix}[1];
|
||||||
|
} else {
|
||||||
|
# not an option
|
||||||
|
}
|
||||||
|
|
||||||
|
$stub =~ s/\s+$//msg;
|
||||||
|
|
||||||
|
return $stub;
|
||||||
|
}
|
||||||
|
|
||||||
sub setup_licenses {
|
sub setup_licenses {
|
||||||
my ($app) = @_;
|
my ($app) = @_;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user