photo-stats

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/photo-stats.git
Log | Files | Refs | README | LICENSE

commit 9f8bb9eb4bb362c53cb0da72bae87c98bd8dc39a
parent 4dff1ffa9535e8cfff4d472194c76204df03c0ed
Author: René Wagner <rwagner@rw-net.de>
Date:   Sat, 15 Aug 2020 08:27:54 +0200

persist path to db in user conf

Diffstat:
Mphosta.pl | 40++++++++++++++++++++++++++++++++++------
1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/phosta.pl b/phosta.pl @@ -14,12 +14,16 @@ use Scalar::Util qw(looks_like_number); use Cwd; use DBI; use Getopt::Std; +use File::Spec::Functions; +use File::HomeDir; $Getopt::Std::STANDARD_HELP_VERSION = 'true'; my $VERSION = '0.5'; my $PROGRAM = 'Photo Stats'; +my $configfile = catfile(File::HomeDir->my_home, '.phosta.conf'); + # read commandline switches our $opt_D=getcwd . "/photo_stats.db"; our $opt_p=''; @@ -27,13 +31,17 @@ our $opt_c=0; our $opt_s=''; our $opt_g=''; -getopts('cp:g:s:d:') or die "Invalid parameters provided! See 'phosta --help' for more details."; +getconfig($configfile); + +getopts('cp:g:s:D:') or die "Invalid parameters provided! See 'phosta --help' for more details."; validate() or die "Invalid parameters provided! See 'phosta --help' for more details."; my $dsn = "DBI:SQLite:dbname=$opt_D"; if ($opt_c) { unlink $opt_D; } if ( !-e $opt_D ) { create_db($opt_D) or die 'database could not be created'; } +writeconfig($configfile); + if ( $opt_p ne '' ) { populate_db($opt_p); exit 0; @@ -57,6 +65,20 @@ sub validate return 1; } +sub getconfig +{ + my ( $config_filename ) = @_; + if ( -f $config_filename ) { do $config_filename; } +} + +sub writeconfig +{ + my ( $config_filename ) = @_; + open(my $filehandle, '>', $config_filename) or die "Could not open file '$config_filename': $!"; + say $filehandle '$opt_D="'. $opt_D .'";'; + close $filehandle; +} + sub create_db { my ($dbfile) = @_; @@ -194,14 +216,20 @@ sub main::HELP_MESSAGE say ''; say 'usage: phosta(.pl) [options]'; say ''; - say 'options:'; - say ' -D <file> : path and name of the db file to use'; - say ' -p <folder> : populate database from the files in the specified folder'; + say 'generic options:'; + say ' -D <file> : path and name of the db file to use, defaults to <workingdir>/photo_stats.db'; + say ' This option is automatically saved in the user conf, you can omit this option if you always use the same db'; say ' -c : clear the database before populating with data from the folder'; - say ' -g : (query mode) group by time range, defaults to total (which means no grouping by time range)'; + say ' --help : show this help'; + say ''; + say 'data gathering:'; + say ' -p <folder> : populate database from the files in the specified folder'; + say ' Media files in the given folder and every subfolder are scanned, EXIF data extracted and pulled into the database'; + say ''; + say 'stats querying:'; + say ' -g : (query mode) group by time range, defaults to total (which means no grouping by time range)'; say ' allowed values: year, month, week'; say ' -s : (query mode) specify the information you want to select, defaults to none (just show number of images)'; say ' allowed values: maker, model, lens, aperture, exposuretime, iso, focallength, focallength35mm'; say ' multiple fields should be listed comma-separated'; - say ' --help : show this help'; }