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",
|
"seedling": "new",
|
||||||
"check": "ok",
|
"check": "ok",
|
||||||
"xmark": "not-ok",
|
"xmark": "not-ok",
|
||||||
|
|||||||
@ -19,6 +19,7 @@ usage() unless -f $renamefile;
|
|||||||
mkdir $todir;
|
mkdir $todir;
|
||||||
|
|
||||||
my %did = ();
|
my %did = ();
|
||||||
|
my %params = ();
|
||||||
|
|
||||||
my @errNex = ();
|
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" }
|
if($cont!~m#^\s*\{(.*)\}\s*$#s) { die "'$renamefile' not in an expected format; it should be an json-object" }
|
||||||
my $core = $1;
|
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 ($from, $to) = ($1, $2);
|
||||||
my $pfrom = "$fromdir/$from.svg";
|
if ($from =~ m#^/#) {
|
||||||
my $pto = "$todir/$to.svg";
|
$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) {
|
if(-e $pfrom) {
|
||||||
print "Renaming '$pfrom' to '$pto'\n";
|
print "Renaming '$pfrom' to '$pto'\n";
|
||||||
system("cp", $pfrom, $pto);
|
system("cp", $pfrom, $pto);
|
||||||
|
|||||||
Reference in New Issue
Block a user