]> Frank Brehm's Git Trees - cookbook.git/commitdiff
Initialen Import von KReceips begonnen
authorFrank Brehm <frank@brehm-online.com>
Wed, 8 Aug 2007 12:06:10 +0000 (12:06 +0000)
committerFrank Brehm <frank@brehm-online.com>
Wed, 8 Aug 2007 12:06:10 +0000 (12:06 +0000)
git-svn-id: http://svn.brehm-online.com/svn/cookbook/trunk@7 191103c4-1d37-0410-b3e5-d8c2315c0aac

cookbook.yml
sbin/initial_import.pl [new file with mode: 0755]

index c2f5dab7230079c523bf60675c1419b456ae0128..8409f106c81ad3decafb0760535e283d7fa5cf3f 100644 (file)
@@ -1,2 +1,14 @@
 ---
-name: CookBook
+name: Kochbuch
+database:
+   host:   localhost
+   port:   3306
+   schema: cookbook
+   user:   cookbook
+   # passwd:
+kreceipes-database:
+   host:   localhost
+   port:   3306
+   schema: rezepte
+   user:   cookbook
+   # passwd:
diff --git a/sbin/initial_import.pl b/sbin/initial_import.pl
new file mode 100755 (executable)
index 0000000..fc693ae
--- /dev/null
@@ -0,0 +1,110 @@
+#!/usr/bin/perl
+
+# $Id: show_sessions.pl 74 2007-06-28 09:28:55Z fbrehm $
+# $URL$
+
+use strict;
+use warnings;
+
+use File::Spec;
+use Cwd 'abs_path';
+use YAML 'LoadFile';
+use Data::Dumper;
+
+$Data::Dumper::Indent   = 1;
+$Data::Dumper::Sortkeys = 1;
+
+# Own modules
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+use CookBook::Common;
+
+##################
+
+my $debug = $ENV{'COOKBOOK_DEBUG'} ? 1 : 0;
+
+my $home_dir = abs_path( File::Spec->canonpath( $FindBin::Bin . "/.." ) );
+print "Home-Dir: '$home_dir'\n";
+
+my $global_conf_file = $home_dir . "/cookbook.yml";
+my $local_conf_file  = $home_dir . "/cookbook_local.yml";
+
+my $global_conf = {};
+my $local_conf  = {};
+
+unless ( -f $global_conf_file ) {
+    warn "Konfigurationsdatei '$global_conf_file' nicht gefunden.\n";
+    exit 1;
+}
+
+# Konfiguration einlesen ...
+print "Lese globale Konfiguration '$global_conf_file' ein ... ";
+eval { ($global_conf) = LoadFile($global_conf_file); };
+if ($@) {
+    print "NOT OK\n";
+    warn $@ . "\n";
+    exit 5;
+}
+print "OK\n";
+print "Globale Konfiguration: " . Dumper($global_conf) if $debug;
+
+if ( -f $local_conf_file ) {
+    print "Lese lokale Konfiguration '$local_conf_file' ein ... ";
+    eval { ($local_conf) = LoadFile($local_conf_file); };
+    if ($@) {
+        print "NOT OK\n";
+        warn $@ . "\n";
+        exit 5;
+    }
+    print "OK\n";
+} ## end if ( -f $local_conf_file )
+print "Lokale Konfiguration: " . Dumper($local_conf) if $debug;
+
+# DSN's und Nutzerangaben ermitteln:
+
+my ( $target_dsn, $target_user, $target_passwd, $source_dsn, $source_user, $source_passwd );
+
+my $port;
+
+$target_dsn = 'dbi:mysql:host=%s;database=%s';
+$target_dsn = sprintf( $target_dsn,
+    ( $local_conf->{'database'}{'host'}   || $global_conf->{'database'}{'host'}   || 'localhost' ),
+    ( $local_conf->{'database'}{'schema'} || $global_conf->{'database'}{'schema'} || 'cookbook' ) );
+$port = 3306;
+$port = to_int( $global_conf->{'database'}{'port'} ) if $global_conf->{'database'}{'port'} and to_int( $global_conf->{'database'}{'port'} );
+$port = to_int( $local_conf->{'database'}{'port'} ) if $local_conf->{'database'}{'port'} and to_int( $local_conf->{'database'}{'port'} );
+
+$target_dsn .= ';port=' . $port unless $port == 3306;
+
+$source_dsn = 'dbi:mysql:host=%s;database=%s';
+$source_dsn = sprintf( $source_dsn,
+    ( $local_conf->{'kreceipes-database'}{'host'}   || $global_conf->{'kreceipes-database'}{'host'}   || 'localhost' ),
+    ( $local_conf->{'kreceipes-database'}{'schema'} || $global_conf->{'kreceipes-database'}{'schema'} || 'cookbook' ) );
+$port = 3306;
+$port = to_int( $global_conf->{'kreceipes-database'}{'port'} )
+    if $global_conf->{'kreceipes-database'}{'port'} and to_int( $global_conf->{'kreceipes-database'}{'port'} );
+$port = to_int( $local_conf->{'kreceipes-database'}{'port'} )
+    if $local_conf->{'kreceipes-database'}{'port'} and to_int( $local_conf->{'kreceipes-database'}{'port'} );
+
+$source_dsn .= ';port=' . $port unless $port == 3306;
+
+$target_user = $local_conf->{'database'}{'user'}           || $global_conf->{'database'}{'user'}           || 'cookbook';
+$source_user = $local_conf->{'kreceipes-database'}{'user'} || $global_conf->{'kreceipes-database'}{'user'} || 'cookbook';
+
+$target_passwd = '';
+$target_passwd = $global_conf->{'database'}{'passwd'} if defined $global_conf->{'database'}{'passwd'};
+$target_passwd = $local_conf->{'database'}{'passwd'} if defined $local_conf->{'database'}{'passwd'};
+
+$source_passwd = '';
+$source_passwd = $global_conf->{'kreceipes-database'}{'passwd'} if defined $global_conf->{'kreceipes-database'}{'passwd'};
+$source_passwd = $local_conf->{'kreceipes-database'}{'passwd'} if defined $local_conf->{'kreceipes-database'}{'passwd'};
+
+if ($debug) {
+    printf "Quell-Datenbank: DSN='%s', User='%s', Pwd='%s'\n", $source_dsn, $source_user, $source_passwd;
+    printf "Ziel-Datenbank:  DSN='%s', User='%s', Pwd='%s'\n", $target_dsn, $target_user, $target_passwd;
+}
+
+print "\n";
+
+exit 0;