From f3808627873cfaf19d879446fd807548b50bc78d Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 17 Dec 2011 21:28:12 +0100 Subject: videodb.rc --- videodb-check.pl | 27 ++++++++++++++------------- videodb.rc | 13 +++++++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 videodb.rc 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", -- cgit v1.2.3