summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@ens-lyon.org>2011-12-17 21:28:12 +0100
committerGuilhem Moulin <guilhem.moulin@ens-lyon.org>2011-12-17 21:28:12 +0100
commitf3808627873cfaf19d879446fd807548b50bc78d (patch)
tree3d5b534b967a38081c40ef1316430dcaef6df8dc
parent888e6963a1e64adf77ba3c1a897fd1cea7a2d8b7 (diff)
videodb.rc
-rwxr-xr-xvideodb-check.pl27
-rw-r--r--videodb.rc13
2 files changed, 27 insertions, 13 deletions
diff --git a/videodb-check.pl b/videodb-check.pl
index 9ed1540..d266244 100755
--- a/videodb-check.pl
+++ b/videodb-check.pl
@@ -17,21 +17,22 @@ use strict;
################################################################################
# Configuration
-my $symlinks = File::Spec->catdir($HOME,'video','MOVIES'); # Symlinks 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;
-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";
+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;
################################################################################
# Connect to database
-my $dsn = "DBI:$driver:database=$database;host=$hostname;port=$port";
-my $dbh = DBI->connect($dsn, $user, $password)
+my $dsn = "DBI:$config{driver}:database=$config{database};host=$config{hostname};port=$config{port}";
+my $dbh = DBI->connect($dsn, $config{user}, $config{password})
or die "Can't connect do database\n";
$dbh->do( "set names utf8" ) or die;
@@ -40,7 +41,7 @@ $dbh->do( "set names utf8" ) or die;
# Check that all entries in the DB have a symlink, that in turn have a
# valid target
-my $res = $dbh->selectall_arrayref ( "SELECT filename FROM $videodata" )
+my $res = $dbh->selectall_arrayref ( "SELECT filename FROM $config{videodata}" )
or die "Can't select: " .$dbh->errstr. "\n";
my @links;
@@ -104,7 +105,7 @@ closedir(DIR) or die "Can't close: $!\n";
undef @files;
-my $sth = $dbh->prepare ( "SELECT id FROM $videodata WHERE filename = ?" )
+my $sth = $dbh->prepare ( "SELECT id FROM $config{videodata} WHERE filename = ?" )
or die "Error: " .$dbh->errstr;
foreach (@filelist) {
$sth->execute ($_) or die "Can't select: " .$dbh->errstr. "\n";
@@ -118,7 +119,7 @@ $dbh->disconnect;
if (@files) {
- print STDERR "* The following files have <> 0 corresponding entries in the DB:\n";
+ print STDERR "* The following files have <> 1 corresponding entries in the DB:\n";
foreach (@files) {
print STDERR " ", $_, "\n";
}
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",