summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@ens-lyon.org>2011-12-17 21:27:42 +0100
committerGuilhem Moulin <guilhem.moulin@ens-lyon.org>2011-12-17 21:27:42 +0100
commitb31a12dfa02dc30ead4850f0222688de5ac3c1ff (patch)
tree8fb08a4ec9a158e5afe395cb70b12070b7fd234b
parentd8e2daec70222199767b19b2d37a91657aa46cfc (diff)
videodb.rc
-rw-r--r--videodb.rc13
-rwxr-xr-xvideomv.pl30
2 files changed, 30 insertions, 13 deletions
diff --git a/videodb.rc b/videodb.rc
new file mode 100644
index 0000000..dad2f22
--- /dev/null
+++ b/videodb.rc
@@ -0,0 +1,13 @@
+#########################################################################
+# This is a sample configuration file for video-*. Extend it and rename #
+# it to `~/.videodb.rc' #
+#########################################################################
+
+videodir => catdir($HOME,'video'),
+driver => 'mysql',
+database => 'videodb',
+hostname => '127.0.0.1',
+user => 'username',
+port => 3306,
+password => '******',
+videodata => "videodb_videodata",
diff --git a/videomv.pl b/videomv.pl
index 02ebedb..1d192c8 100755
--- a/videomv.pl
+++ b/videomv.pl
@@ -23,16 +23,20 @@ use strict;
################################################################################
# Configuration
-my $symlinks = catdir($HOME,'video','MOVIES'); # Symlinks folder
-my $directors = catdir($HOME,'video','DIRECTORS'); # Directors folder
+my $confile = catfile ($HOME, '.videodb.rc');
+die "Can't read `" .$confile. "'\n" unless -f $confile;
+my %config = do $confile;
+die "Error in `" .$confile. "'\n" if $@ || not %config;
+
+map { exists $config{$_} || die "Error: Missing `${_}'.\n" }
+ qw /videodir driver database hostname user port password videodata/;
+
+my $symlinks = catdir($config{videodir},'MOVIES'); # Symlinks folder
+die "Error: No such directory: `" .$symlinks. "'.\n" unless -d $symlinks;
+
+my $directors = catdir($config{videodir},'DIRECTORS'); # Directors folder
+die "Error: No such directory: `" .$directors. "'.\n" unless -d $symlinks;
-my $driver = "mysql";
-my $database = "videodb";
-my $hostname = "127.0.0.1";
-my $user = "videodb";
-my $port = 3306;
-my $password = "videodb";
-my $videodata = "videodb_videodata";
################################################################################
@@ -316,15 +320,15 @@ my @real_directors = splitdir($real_directors);
# Connect to database
my ($dsn, $dbh, $RES, $nRES, $id);
unless (defined $ignoredb_flag) {
- $dsn = "DBI:$driver:database=$database;host=$hostname;port=$port";
- $dbh = DBI->connect($dsn, $user, $password)
+ $dsn = "DBI:$config{driver}:database=$config{database};host=$config{hostname};port=$config{port}";
+ $dbh = DBI->connect($dsn, $config{user}, $config{password})
or die "Can't connect do database";
$dbh->do( "set names utf8" ) or die;
# Lookup for the file in the videodb database
$RES =
- $dbh->selectall_hashref ( "SELECT id,director,title FROM $videodata
+ $dbh->selectall_hashref ( "SELECT id,director,title FROM $config{videodata}
WHERE filename = ?",
'id', undef, $old_filename
)
@@ -499,7 +503,7 @@ unless (defined $ignoredb_flag || $old_filename eq $new_filename) {
&revert(@actions);
}
else {
- my $rv = $dbh->do ( "UPDATE $videodata SET filename = ? WHERE id = ?",
+ my $rv = $dbh->do ( "UPDATE $config{videodata} SET filename = ? WHERE id = ?",
undef, $new_filename, $id
);
&ack (\$r, $rv);