diff --git a/phosta.pl b/phosta.pl
index 2aa70317e9cb9c7f56b4a355790057bddd11e6ed..0f80acfa13c46199617fc978fe38d3c10a917d45 100755
--- 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,12 +31,16 @@ 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);
@@ -55,6 +63,20 @@ if ( ! ($_ ~~ @select_params) ) { return 0; }
}
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
@@ -194,14 +216,20 @@ say 'Afterwards query some stats from the selected data.';
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';
}