art-helpers

simple helper scripts for managing images processed by ART
git clone https://git.clttr.info/art-helpers.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 83e1ce87cb589fa34c39f9da7ddd9e349d56f636
parent 1ae6feec2e683187e5eec76d163c0eecb2789d62
Author: René Wagner <apollo@rw-net.de>
Date:   Wed,  1 Jan 2020 18:02:14 +0100

use Getopt::Std for commandline parsing

Diffstat:
Mjpegdivider.pl | 47+++++++++++++++++++++++++++--------------------
Msilkypix_multiversion_sidecar_cleaner.pl | 53+++++++++++++++++++++++++++++++----------------------
Msilkypix_orphaned_sidecar_cleaner.pl | 53++++++++++++++++++++++++++++++-----------------------
3 files changed, 88 insertions(+), 65 deletions(-)

diff --git a/jpegdivider.pl b/jpegdivider.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# Copyright(c) René Wagner 2019 +# Copyright(c) René Wagner 2019-2020 # published under BSD 3-Clause License # https://www.codewolke.net/photo-helpers/ @@ -12,42 +12,45 @@ use File::Copy; use File::Find; use File::Find::Rule; use File::Spec::Functions; -use Switch; +use Getopt::Std; -my $VERSION = '0.4'; +$Getopt::Std::STANDARD_HELP_VERSION = 'true'; + +my $VERSION = '0.5'; my $PROGRAM = 'JpegDivider'; -my $SUBFOLDER = 'JPEG'; -# parse commandline args +# read commandline switches +our $opt_m = 0; +our $opt_f = 'JPEG'; + +if ( !getopts('mf:') ) +{ + die("Invalid parameters provided! See 'jpegdivider.pl --help' for more details."); +} + +# read remaining commandline args # last dir will win my $work_dir = getcwd; -my $move_flag = 0; - foreach my $arg ( @ARGV ) { - switch ( $arg ) - { - case '-h' { show_help(); exit; } - case '-m' { $move_flag = 1; } - else { if ( -d $arg ) { $work_dir = $arg } } - } + if ( -d $arg ) { $work_dir = $arg } } -main($work_dir, $move_flag); +move_files($work_dir, $opt_m); exit 0; -sub main +sub move_files { my ( $dir, $move_flag ) = @_; my $move_counter = 0; say "working directory: $dir"; say 'action : '. ($move_flag ? 'move' : 'list only'); - say "subfolder : $SUBFOLDER"; + say "subfolder : $opt_f"; say ''; - my $destination_dir = catdir($dir, $SUBFOLDER); + my $destination_dir = catdir($dir, $opt_f); if ( $move_flag && ! -d $destination_dir ) { mkdir $destination_dir or die "Could not create destination dir $_ : $!"; @@ -76,12 +79,16 @@ sub main say "\r\nfound $move_counter jpeg files to subfolder."; } -sub show_help +sub main::VERSION_MESSAGE() { say $PROGRAM . ' - version ' . $VERSION; say 'published under BSD 3 - Clause License'; - say 'Copyright(c) 2019 René Wagner'; + say 'Copyright(c) 2019-2020 René Wagner'; say 'https://www.codewolke.net/photo-helpers/'; +} + +sub main::HELP_MESSAGE +{ say ''; say 'Moves JPEG files to a designated subfolder, by default "JPEG"'; say ''; @@ -90,5 +97,5 @@ sub show_help say 'jpegdivider.pl -m - create a subfolder "JPEG" in the current working dir and move jpeg files in there'; say 'jpegdivider.pl <folder> - list all jpeg files in the given directory'; say 'jpegdivider.pl -m <folder> - create a subfolder "JPEG" in the given directory and move jpeg files in there'; - say 'jpegdivider.pl -h - show this help'; + say 'jpegdivider.pl --help - show this help'; } diff --git a/silkypix_multiversion_sidecar_cleaner.pl b/silkypix_multiversion_sidecar_cleaner.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# Copyright(c) René Wagner 2019 +# Copyright(c) René Wagner 2019-2020 # published under BSD 3-Clause License # https://www.codewolke.net/photo-helpers/ @@ -10,34 +10,39 @@ use Cwd; use File::Basename; use File::Find::Rule; use File::Find; -use Switch; +use Getopt::Std; -my $VERSION = '0.2'; +$Getopt::Std::STANDARD_HELP_VERSION = 'true'; + +my $VERSION = '0.3'; my $PROGRAM = 'Multiversion Sidecar Cleaner'; -my $delete_flag = 0; -my $delete_dir = getcwd; +# read commandline switches +our $opt_d = 0; +if ( !getopts('d') ) +{ + die("Invalid parameters provided! See 'silkypix_multiversion_sidecar_cleaner.pl --help' for more details."); +} + +# read remaining commandline args +# last dir will win +my $work_dir = getcwd; foreach my $arg ( @ARGV ) { - switch ( $arg ) - { - case '-h' { show_help(); exit; } - case '-d' { $delete_flag = 1; } - else { if ( -d $arg ) { $delete_dir = $arg } } - } + if ( -d $arg ) { $work_dir = $arg } } -main($delete_dir, $delete_flag); +delete_files($work_dir, $opt_d); exit 0; -sub main +sub delete_files { - my ( $dir, $delete ) = @_; - my ( $delcounter ) = 0; + my ( $dir, $delete_flag ) = @_; + my ( $file_counter ) = 0; - say "working directory: $delete_dir"; + say "working directory: $dir"; say 'action : '. ($delete_flag ? 'delete' : 'list only') . "\r\n"; say 'files with newer versions:'; @@ -50,8 +55,8 @@ sub main if ( exist_newer_file($file) ) { print $file .'...'; - $delcounter++; - if ( $delete ) + $file_counter++; + if ( $delete_flag ) { if ( unlink $file ) { @@ -66,7 +71,7 @@ sub main } } - say "\r\nfound $delcounter duplicate file versions."; + say "\r\nfound $file_counter duplicate file versions."; } sub exist_newer_file @@ -103,12 +108,16 @@ sub exist_newer_file return 0; } -sub show_help +sub main::VERSION_MESSAGE() { say $PROGRAM . ' - version ' . $VERSION; say 'published under BSD 3 - Clause License'; - say 'Copyright(c) 2019 René Wagner'; + say 'Copyright(c) 2019-2020 René Wagner'; say 'https://www.codewolke.net/photo-helpers/'; +} + +sub main::HELP_MESSAGE +{ say ''; say 'Deletes Silkypix Sidecar files when newer versions of the files are available.'; say 'This usually happens when a file is opened in a newer version of Silkypix, as the sidecar files are version specific.'; @@ -118,5 +127,5 @@ sub show_help say 'duplicate_sidecar_cleaner.pl -d - delete duplicate sidecar file versions in given directory and subfolders'; say 'duplicate_sidecar_cleaner.pl <folder> - list duplicate sidecar file versions in given directory and subfolders'; say 'duplicate_sidecar_cleaner.pl -d <folder> - delete duplicate sidecar file versions in given directory and subfolders'; - say 'duplicate_sidecar_cleaner.pl -h - show this help'; + say 'duplicate_sidecar_cleaner.pl --help - show this help'; } diff --git a/silkypix_orphaned_sidecar_cleaner.pl b/silkypix_orphaned_sidecar_cleaner.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# Copyright(c) René Wagner 2019 +# Copyright(c) René Wagner 2019-2020 # published under BSD 3-Clause License # https://www.codewolke.net/photo-helpers/ @@ -11,49 +11,52 @@ use File::Basename; use File::Find::Rule; use File::Find; use File::Spec::Functions; -use Switch; +use Getopt::Std; + +$Getopt::Std::STANDARD_HELP_VERSION = 'true'; my $VERSION = '0.3'; my $PROGRAM = 'Orphaned Sidecar Cleaner'; -# parse commandline args -# last dir will win -my $delete_flag = 0; -my $delete_dir = getcwd; +# read commandline switches +our $opt_d = 0; + +if ( !getopts('d') ) +{ + die("Invalid parameters provided! See 'silkypix_multiversion_sidecar_cleaner.pl --help' for more details."); +} +# read remaining commandline args +# last dir will win +my $work_dir = getcwd; foreach my $arg ( @ARGV ) { - switch ( $arg ) - { - case '-h' { show_help(); exit; } - case '-d' { $delete_flag = 1; } - else { if ( -d $arg ) { $delete_dir = $arg } } - } + if ( -d $arg ) { $work_dir = $arg } } -main($delete_dir, $delete_flag); +delete_files($work_dir, $opt_d); exit 0; -sub main +sub delete_files { - my ( $dir, $delete ) = @_; - my ( $delcounter ) = 0; + my ( $delete_dir, $delete_flag ) = @_; + my ( $file_counter ) = 0; say "working directory: $delete_dir"; say 'action : '. ($delete_flag ? 'delete' : 'list only') ."\r\n"; say 'files with missing raw:'; # alle Dateien in allen Unterordnern *.spd *.spf suchen - my @files = File::Find::Rule->file->name( qr/\.sp(d|f)$/i )->in( $dir ); + my @files = File::Find::Rule->file->name( qr/\.sp(d|f)$/i )->in( $delete_dir ); foreach my $file ( @files ) { if ( ! exists_raw_filename($file) ) { print $file .'...'; - $delcounter++; - if ( $delete ) + $file_counter++; + if ( $delete_flag ) { if ( unlink $file ) { @@ -68,7 +71,7 @@ sub main } } - say "\r\nfound $delcounter orphaned sidecar files found."; + say "\r\nfound $file_counter orphaned sidecar files found."; } sub exists_raw_filename @@ -85,12 +88,16 @@ sub exists_raw_filename return 0; } -sub show_help +sub main::VERSION_MESSAGE() { say $PROGRAM . ' - version ' . $VERSION; say 'published under BSD 3 - Clause License'; - say 'Copyright(c) 2019 René Wagner'; + say 'Copyright(c) 2019-2020 René Wagner'; say 'https://www.codewolke.net/photo-helpers/'; +} + +sub main::HELP_MESSAGE +{ say ''; say 'Deletes Silkypix Sidecar files when corresponding RAW files are missing.'; say ''; @@ -99,5 +106,5 @@ sub show_help say 'orphaned_sidecar_cleaner.pl -d - delete orphaned sidecar file in current working directory and subfolders'; say 'orphaned_sidecar_cleaner.pl <folder> - list orphaned sidecar file in given directory and subfolders'; say 'orphaned_sidecar_cleaner.pl -d <folder> - delete orphaned sidecar file in given directory and subfolders'; - say 'orphaned_sidecar_cleaner.pl -h - show this help'; + say 'orphaned_sidecar_cleaner.pl --help - show this help'; }