Added replacement tags in headers + Misc updates
This commit is contained in:
parent
e3b5ca3754
commit
88e2659c6d
75
licapp.pl
75
licapp.pl
@ -3,6 +3,7 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use File::Find;
|
||||
use File::Basename;
|
||||
use FileHandle;
|
||||
use Data::Dumper;
|
||||
use Getopt::Long;
|
||||
@ -14,24 +15,92 @@ my $app = {};
|
||||
# Defaults
|
||||
$app->{'options'}->{'directory'} = getcwd;
|
||||
$app->{'options'}->{'license'} = 'mit';
|
||||
$app->{'options'}->{'user'} = $ENV{'USER'};
|
||||
$app->{'options'}->{'date'} = (localtime(time))[5] + 1900;
|
||||
$app->{'options'}->{'about'} = "This is an open-source software";
|
||||
$app->{'state'}->{'license_stub'} = "NON EXISTANT";
|
||||
$app->{'state'}->{'app_dir'} = dirname($0);
|
||||
|
||||
# Command line options
|
||||
my $correct_usage = GetOptions (
|
||||
'directory=s' => \$app->{'options'}->{'directory'},
|
||||
'license=s' => \$app->{'options'}->{'license'});
|
||||
'directory=s' => \$app->{'options'}->{'directory'},
|
||||
'license=s' => \$app->{'options'}->{'license'},
|
||||
'about=s' => \$app->{'options'}->{'about'},
|
||||
'user=s' => \$app->{'options'}->{'user'},
|
||||
'date=s' => \$app->{'options'}->{'date'},
|
||||
);
|
||||
|
||||
setup_license_pretty_names($app);
|
||||
setup_filetype_comment_mapping($app);
|
||||
setup_license_stub($app);
|
||||
|
||||
print "Applying '"
|
||||
. $app->{'license_pretty_names'}->{$app->{'options'}->{'license'}}
|
||||
. "' license to files in '"
|
||||
. $app->{'options'}->{'directory'}
|
||||
."' directory\n";
|
||||
. "' directory\n\n";
|
||||
|
||||
print "Copyright: Copyright (C) "
|
||||
. $app->{'options'}->{'date'}
|
||||
. " " . $app->{'options'}->{'user'}
|
||||
. "\n\n";
|
||||
|
||||
print "About: " . $app->{'options'}->{'about'}
|
||||
. "\n\n";
|
||||
|
||||
print "Stub:\n-----\n$app->{'state'}->{'license_stub'}\n-----\n";
|
||||
|
||||
find (sub {
|
||||
find_files($app, ${File::Find::name}, $_)
|
||||
}, $app->{'options'}->{'directory'});
|
||||
|
||||
#
|
||||
# Subroutines
|
||||
#
|
||||
sub find_files {
|
||||
my ($app, $file, $name) = @_;
|
||||
|
||||
#
|
||||
# Opportunity to filter any file types befrore any processing starts
|
||||
#
|
||||
handle_files ($app, $file, $name);
|
||||
}
|
||||
|
||||
sub handle_files {
|
||||
my ($app, $file, $name) = @_;
|
||||
|
||||
my $rh = new FileHandle ($name);
|
||||
my @contents = <$rh>;
|
||||
|
||||
print "Handling... $file\n";
|
||||
|
||||
if ((defined $contents[0]) && ($contents[0] =~ /^\s*#!/)) {
|
||||
print " ... has #! line\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub setup_license_stub {
|
||||
my ($app) = @_;
|
||||
my $header_file = $app->{'state'}->{'app_dir'}
|
||||
."/licenses/"
|
||||
. $app->{'options'}->{'license'} . ".header";
|
||||
|
||||
if (-e $header_file) {
|
||||
my $rh = new FileHandle ($header_file);
|
||||
$app->{'state'}->{'license_stub'} = do {local $/; <$rh>};
|
||||
|
||||
$app->{'state'}->{'license_stub'} =~
|
||||
s/###DESCRIPTION###/$app->{'options'}->{'about'}/;
|
||||
$app->{'state'}->{'license_stub'} =~
|
||||
s/###DATE###/$app->{'options'}->{'date'}/;
|
||||
$app->{'state'}->{'license_stub'} =~
|
||||
s/###NAME###/$app->{'options'}->{'user'}/;
|
||||
}
|
||||
else {
|
||||
warn "[WARN] License Header '$header_file' does not exist";
|
||||
}
|
||||
}
|
||||
|
||||
sub setup_license_pretty_names {
|
||||
my ($app) = @_;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
Copyright ###DATE### ###NAME###
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
###DESCRIPTION###
|
||||
Copyright (C) ###DATE### ###NAME###
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -1,4 +1,4 @@
|
||||
Copyright (c) <year> <copyright holders>
|
||||
Copyright (c) ###DATE### ###NAME###
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
|
Loading…
Reference in New Issue
Block a user