chore(utils): configurable file extensions for renamer util
This commit is contained in:
parent
51a3a25042
commit
5200d88f75
@ -1,4 +1,5 @@
|
||||
{
|
||||
"/defaultExtension": "svg",
|
||||
"seedling": "new",
|
||||
"check": "ok",
|
||||
"xmark": "not-ok",
|
||||
|
||||
@ -19,6 +19,7 @@ usage() unless -f $renamefile;
|
||||
mkdir $todir;
|
||||
|
||||
my %did = ();
|
||||
my %params = ();
|
||||
|
||||
my @errNex = ();
|
||||
|
||||
@ -29,10 +30,26 @@ close $fh;
|
||||
if($cont!~m#^\s*\{(.*)\}\s*$#s) { die "'$renamefile' not in an expected format; it should be an json-object" }
|
||||
my $core = $1;
|
||||
|
||||
while($core=~s#^\s*,?\s*"([^"/]+)"\s*:\s*"([^"/]+)"##) {
|
||||
my %toRename = ();
|
||||
|
||||
while($core=~s#^\s*,?\s*"(/?[^"/]+)"\s*:\s*"([^"/]+)"##) {
|
||||
my ($from, $to) = ($1, $2);
|
||||
my $pfrom = "$fromdir/$from.svg";
|
||||
my $pto = "$todir/$to.svg";
|
||||
if ($from =~ m#^/#) {
|
||||
$params{$from} = $to;
|
||||
} else {
|
||||
$toRename{$from} = $to;
|
||||
}
|
||||
}
|
||||
|
||||
my $defaultExtension = $params{"/defaultExtension"};
|
||||
|
||||
for my $from (keys %toRename) {
|
||||
my $to = $toRename{$from};
|
||||
my $pfrom = "$fromdir/$from";
|
||||
my $pto = "$todir/$to";
|
||||
if (defined $defaultExtension and $from !~ m#\.#) {
|
||||
$_ .= ".$defaultExtension" for $pfrom, $pto;
|
||||
}
|
||||
if(-e $pfrom) {
|
||||
print "Renaming '$pfrom' to '$pto'\n";
|
||||
system("cp", $pfrom, $pto);
|
||||
|
||||
Reference in New Issue
Block a user