notice and save changes to graph name / stemma identifier (tla/stemmaweb#28)
[scpubgit/stemmatology.git] / analysis / idp_server / idpinit.pl
CommitLineData
e3bf7a69 1#!/usr/bin/env perl
2
3use lib 'lib';
4use feature 'say';
5use strict;
6use warnings;
7use Text::Tradition::Directory;
8
9binmode STDOUT, ':utf8';
10binmode STDERR, ':utf8';
11eval { no warnings; binmode $DB::OUT, ':utf8'; $DB::deep = 1000 };
12
13my %VARS = (
14 DBTYPE => 'mysql',
15 DBHOST => '127.0.0.1',
16 DBPORT => '3006',
17 DBNAME => 'idpresult',
18 DSN => undef,
19 DBUSER => undef,
20 DBPASS => undef,
21);
22
23if( -f "/etc/graphcalc.conf" ) {
24 # Read the variables in from here.
25 open( GCCONF, "/etc/graphcalc.conf" )
26 or die "Could not open configuration file /etc/graphcalc.conf";
27 while(<GCCONF>) {
28 chomp;
29 s/^\s+//;
30 my( $name, $val ) = split( /\s*\=\s*/, $_ );
31 if( exists $VARS{$name} ) {
32 $VARS{$name} = $val;
33 }
34 }
35 close GCCONF;
36}
37unless( $VARS{DSN} ) {
38 $VARS{DSN} = sprintf( "dbi:%s:dbname=%s;host=%s;port=%s",
39 $VARS{DBTYPE}, $VARS{DBNAME}, $VARS{DBHOST}, $VARS{DBPORT} );
40}
41
42my $dirargs = { create => 1 };
43$dirargs->{user} = $VARS{DBUSER} if $VARS{DBUSER};
44$dirargs->{password} = $VARS{DBPASS} if $VARS{DBPASS};
45my $dir = Text::Tradition::Directory->new(
46 'dsn' => $VARS{DSN}, 'extra_args' => $dirargs );
47my $scope = $dir->new_scope();
48
49say "Initialized database at " . $VARS{DSN};