summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-11-12 11:18:59 +0100
committerYorhel <git@yorhel.nl>2008-11-12 11:18:59 +0100
commitfadb037c536c60c91bf978c2604ca9eab818f3ff (patch)
treeafaac4e3e463efb7dacba58c0e975d59ab04d59c
parentcbedf4b542cb3ebc10374eba0a41585eb2f2cc95 (diff)
Fixed Multi to use relative paths and to use the new configuration files
-rw-r--r--data/global.pl16
-rw-r--r--lib/Multi/Anime.pm26
-rw-r--r--lib/Multi/Core.pm13
-rw-r--r--lib/Multi/IRC.pm14
-rw-r--r--lib/Multi/Image.pm13
-rw-r--r--lib/Multi/Maintenance.pm8
-rwxr-xr-xutil/multi.pl25
7 files changed, 74 insertions, 41 deletions
diff --git a/data/global.pl b/data/global.pl
index 0c520717..e6702d6f 100644
--- a/data/global.pl
+++ b/data/global.pl
@@ -27,6 +27,22 @@ our %S = (
[qw| mod hist board boardmod edit mod lock del |], # 3
[qw| admin hist board boardmod edit mod lock del usermod |], # 4
],
+ sharedmem_key => 'VNDB',
+);
+
+
+# Multi-specific options (Multi also uses some options in %S and %O)
+our %M = (
+ log_dir => $ROOT.'/data/log',
+ log_level => 3, # 3: dbg, 2: wrn, 1: err
+ modules => {
+ RG => {},
+ Image => {},
+ Sitemap => {},
+ #Anime => {}, # disabled by default, requires AniDB username/pass
+ Maintenance => {},
+ #IRC => {}, # disabled by default, no need to run an IRC bot when debugging
+ },
);
diff --git a/lib/Multi/Anime.pm b/lib/Multi/Anime.pm
index 42bd52bf..0a7f5a08 100644
--- a/lib/Multi/Anime.pm
+++ b/lib/Multi/Anime.pm
@@ -66,6 +66,17 @@ sub spawn {
timeoutdelay => 0.4, # $delay = $msgdelay ^ (1 + $tm*$timeoutdelay)
maxtimeoutdelay => 2*3600, # two hours
cachetime => 30*24*3600, # one month
+ # AniDB anime types:
+ types => [
+ [ 'unknown', 'unknown', ],
+ [ 'TV', 'TV Series' ],
+ [ 'OVA', 'OVA' ],
+ [ 'Movie', 'Movie' ],
+ [ 'unknown', 'Other' ],
+ [ 'unknown', 'Web' ],
+ [ 'TV Special', 'TV Special' ],
+ [ 'unknown', 'Music Video' ],
+ ],
@_,
w => undef,
@@ -125,7 +136,7 @@ sub cmd_anime { # cmd, arg
}
if(@push) {
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
$s->lock(LOCK_EX);
my @q = $s{anime} ? @{$s{anime}} : ();
push @q, grep {
@@ -143,7 +154,7 @@ sub cmd_anime { # cmd, arg
sub nextcmd {
return if $_[HEAP]{lm};
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
my @q = $s{anime} ? @{$s{anime}} : ();
undef $s;
@@ -188,8 +199,8 @@ sub nextcmd {
$_.'='.$cmd{$_}
} keys %cmd);
$_[HEAP]{w}->put({ payload => [ $cmd ]});
- $VNDB::DEBUG && printf " > %s\n", $cmd;
-
+
+ #$_[KERNEL]->call(core => log => 3, '> %s', $cmd);
$_[KERNEL]->delay(receivepacket => $_[HEAP]{timeout}, { payload => [ $_[HEAP]{tag}.' 100 TIMEOUT' ] });
$_[HEAP]{lm} = time;
}
@@ -208,7 +219,6 @@ sub receivepacket { # input, wheelid
} else {
$_[KERNEL]->call(core => log => 3, 'Received from AniDB after %.2fs: %d %s',
time-$_[HEAP]{lm}, $code, $msg);
- $VNDB::DEBUG && print ' < '.join("\n < ", @r)."\n";
}
# just handle anime data, even if the tag is not correct
@@ -263,8 +273,8 @@ sub updateanime { # aid, data|'notfound'
$_ =~ s/`/'/g;
}
$col[3] = $1 if $col[3] =~ /^([0-9]+)/; # remove multi-year stuff
- for(0..$#$VNDB::ANITYPE) {
- $col[4] = $_ if lc($VNDB::ANITYPE->[$_][1]) eq lc($col[4]);
+ for(0..$#{$_[HEAP]{types}}) {
+ $col[4] = $_ if lc($_[HEAP]{types}[$_][1]) eq lc($col[4]);
}
$col[4] = 0 if $col[4] !~ /^[0-9]+$/;
$col[2] = '' if $col[2] =~ /^0,/;
@@ -286,7 +296,7 @@ sub updateanime { # aid, data|'notfound'
undef, @col) if $r < 1;
# remove from queue
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
$s->lock(LOCK_EX);
my @q = grep $_ != $_[ARG0], ($s{anime} ? @{$s{anime}} : ());
$s{anime} = \@q;
diff --git a/lib/Multi/Core.pm b/lib/Multi/Core.pm
index 74706910..7b2ae24b 100644
--- a/lib/Multi/Core.pm
+++ b/lib/Multi/Core.pm
@@ -56,7 +56,7 @@ sub heartbeat { # last beat
sub queue { # cmd
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
$s->lock(LOCK_EX);
my @q = ( ($s{queue} ? @{$s{queue}} : ()), $_[ARG0] );
$s{queue} = \@q;
@@ -70,7 +70,7 @@ sub queue { # cmd
sub prepare { # determines whether to execute a new cmd
return if $Multi::STOP || $_[HEAP]{running};
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
$s->lock(LOCK_SH);
if($s{queue} && @{$s{queue}}) {
$_[KERNEL]->yield(execute => $s{queue}[0]);
@@ -100,7 +100,7 @@ sub finish { # cmd
$_[KERNEL]->call(core => log => 2, "Unqueuing '%s' after %.2fs.",
$_[ARG0], tv_interval($_[HEAP]{starttime}));
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
$s->lock(LOCK_EX);
my @q = grep { $_ ne $_[ARG0] } $s{queue} ? @{$s{queue}} : ();
$s{queue} = \@q;
@@ -111,19 +111,16 @@ sub finish { # cmd
sub log { # level, msg
- return if $_[ARG0] > $Multi::LOGLVL;
+ return if $_[ARG0] > $VNDB::M{log_level};
(my $p = eval { $_[SENDER][2]{$_[CALLER_STATE]}[0] } || '') =~ s/^Multi:://;
my $msg = sprintf '(%s) %s::%s: %s',
(qw|WRN ACT DBG|)[$_[ARG0]-1], $p, $_[CALLER_STATE],
$_[ARG2] ? sprintf($_[ARG1], @_[ARG2..$#_]) : $_[ARG1];
- open(my $F, '>>', $Multi::LOGDIR.'/multi.log');
+ open(my $F, '>>', $VNDB::M{log_dir}.'/multi.log');
printf $F "[%s] %s\n", scalar localtime, $msg;
close $F;
-
- # (debug) log to stdout as well...
- $VNDB::DEBUG && printf "[%s] %s\n", scalar localtime, $msg;
}
diff --git a/lib/Multi/IRC.pm b/lib/Multi/IRC.pm
index 4a60f324..224b35d4 100644
--- a/lib/Multi/IRC.pm
+++ b/lib/Multi/IRC.pm
@@ -61,7 +61,7 @@ sub _start {
$_[HEAP]{irc}->plugin_add(
Logger => POE::Component::IRC::Plugin::Logger->new(
- Path => $Multi::LOGDIR,
+ Path => $VNDB::M{log_dir},
Private => 0,
Public => 1,
));
@@ -70,7 +70,7 @@ sub _start {
);
$_[HEAP]{irc}->plugin_add(
CTCP => POE::Component::IRC::Plugin::CTCP->new(
- version => $_[HEAP]{o}{ircname}.' v'.$VNDB::VERSION,
+ version => $_[HEAP]{o}{ircname}.' v'.$VNDB::S{version},
userinfo => $_[HEAP]{o}{ircname},
));
if($_[HEAP]{o}{pass}) {
@@ -175,9 +175,9 @@ sub vndbid { # dest, msg, force
# nf (normal format): x+ : x, id, title
# sf (sub format): x+.+ : x, id, subid, title, action2, title2
# ef (extended format): x+.+ : x, id, subid, action, title, action2, title2
- my $nf = BOLD.RED.'['.NORMAL.BOLD.'%s%d' .RED.']' .NORMAL.' %s ' .RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::VNDBopts{root_url}.'/%1$s%2$d'.NORMAL;
- my $sf = BOLD.RED.'['.NORMAL.BOLD.'%s%d.%d'.RED.']' .NORMAL.' %s '.RED.'%s'.NORMAL.' %s '.RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::VNDBopts{root_url}.'/%1$s%2$d.%3$d'.NORMAL;
- my $ef = BOLD.RED.'['.NORMAL.BOLD.'%s%d.%d'.RED.']'.NORMAL.RED.' %s'.NORMAL.' %s '.RED.'%s'.NORMAL.' %s '.RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::VNDBopts{root_url}.'/%1$s%2$d.%3$d'.NORMAL;
+ my $nf = BOLD.RED.'['.NORMAL.BOLD.'%s%d' .RED.']' .NORMAL.' %s ' .RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::S{url}.'/%1$s%2$d'.NORMAL;
+ my $sf = BOLD.RED.'['.NORMAL.BOLD.'%s%d.%d'.RED.']' .NORMAL.' %s '.RED.'%s'.NORMAL.' %s '.RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::S{url}.'/%1$s%2$d.%3$d'.NORMAL;
+ my $ef = BOLD.RED.'['.NORMAL.BOLD.'%s%d.%d'.RED.']'.NORMAL.RED.' %s'.NORMAL.' %s '.RED.'%s'.NORMAL.' %s '.RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::S{url}.'/%1$s%2$d.%3$d'.NORMAL;
# get a list of possible IDs (a la sub summary in defs.pl)
my @id; # [ type, id, ref ]
@@ -272,7 +272,7 @@ sub shutdown {
sub cmd_info {
$_[KERNEL]->post(circ => privmsg => $_[DEST],
- 'Hello, I am HMX-12 Multi v'.$VNDB::VERSION.' made by the great Yorhel!');
+ 'Hello, I am HMX-12 Multi v'.$VNDB::S{version}.' made by the great Yorhel!');
}
@@ -316,7 +316,7 @@ sub cmd_vn { # $arg = search string
sprintf 'No results found for %s', $_[ARG]) if !@$res;
return $_[KERNEL]->post(circ => privmsg => $_[DEST],
sprintf 'Too many results found, see %s/v/search?q=%s',
- $VNDB::VNDBopts{root_url}, uri_escape_utf8($_[ARG])) if @$res > 5;
+ $VNDB::S{url}, uri_escape_utf8($_[ARG])) if @$res > 5;
$_[KERNEL]->yield(vndbid => $_[DEST], join(' ', map 'v'.$_->[0], @$res), 1);
}
diff --git a/lib/Multi/Image.pm b/lib/Multi/Image.pm
index fb712afd..fe3d411e 100644
--- a/lib/Multi/Image.pm
+++ b/lib/Multi/Image.pm
@@ -25,6 +25,9 @@ sub spawn {
heap => {
cvsize => [ 256, 400 ],
scrsize => [ 136, 102 ],
+ cvpath => $VNDB::ROOT.'/static/cv',
+ sfpath => $VNDB::ROOT.'/static/sf',
+ stpath => $VNDB::ROOT.'/static/st',
},
);
}
@@ -60,7 +63,7 @@ sub cmd_coverimage {
sub cv_process { # id
my $start = time;
- my $img = sprintf '%s/%02d/%d.jpg', $VNDB::VNDBopts{imgpath}, $_[ARG0]%100, $_[ARG0];
+ my $img = sprintf '%s/%02d/%d.jpg', $_[HEAP]{cvpath}, $_[ARG0]%100, $_[ARG0];
my $os = -s $img;
my $im = Image::Magick->new;
@@ -150,8 +153,8 @@ sub cmd_screenshot {
sub scr_process { # id
my $start = time;
- my $sf = sprintf '%s/%02d/%d.jpg', $VNDB::VNDBopts{sfpath}, $_[ARG0]%100, $_[ARG0];
- my $st = sprintf '%s/%02d/%d.jpg', $VNDB::VNDBopts{stpath}, $_[ARG0]%100, $_[ARG0];
+ my $sf = sprintf '%s/%02d/%d.jpg', $_[HEAP]{sfpath}, $_[ARG0]%100, $_[ARG0];
+ my $st = sprintf '%s/%02d/%d.jpg', $_[HEAP]{stpath}, $_[ARG0]%100, $_[ARG0];
# convert/compress full-size image
my $os = -s $sf;
@@ -208,8 +211,8 @@ sub scr_clean {
my($bytes, $items, $id) = (0, 0, 0);
while(($id) = $q->fetchrow_array) {
- my $f = sprintf '%s/%02d/%d.jpg', $VNDB::VNDBopts{stpath}, $id%100, $id;
- my $t = sprintf '%s/%02d/%d.jpg', $VNDB::VNDBopts{stpath}, $id%100, $id;
+ my $f = sprintf '%s/%02d/%d.jpg', $_[HEAP]{sfpath}, $id%100, $id;
+ my $t = sprintf '%s/%02d/%d.jpg', $_[HEAP]{stpath}, $id%100, $id;
$bytes += -s $f;
$bytes += -s $t;
$items++;
diff --git a/lib/Multi/Maintenance.pm b/lib/Multi/Maintenance.pm
index b5d51ea3..3c2cd042 100644
--- a/lib/Multi/Maintenance.pm
+++ b/lib/Multi/Maintenance.pm
@@ -114,10 +114,10 @@ sub unkanime {
sub logrotate {
- my $dir = sprintf '%s/old', $Multi::LOGDIR;
+ my $dir = sprintf '%s/old', $VNDB::M{log_dir};
mkdir $dir if !-d $dir;
- for (glob sprintf '%s/*', $Multi::LOGDIR) {
+ for (glob sprintf '%s/*', $VNDB::M{log_dir}) {
next if /^\./ || /~$/ || !-f;
my $f = /([^\/]+)$/ ? $1 : $_;
my $n = sprintf '%s/%s.%04d-%02d-%02d.gz', $dir, $f, (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3];
@@ -125,12 +125,12 @@ sub logrotate {
$_[KERNEL]->call(core => log => 1, 'Logs already rotated earlier today!');
return;
}
- open my $I, '<', sprintf '%s/%s', $Multi::LOGDIR, $f;
+ open my $I, '<', sprintf '%s/%s', $VNDB::M{log_dir}, $f;
open my $O, '>:gzip', $n;
print $O $_ while <$I>;
close $O;
close $I;
- open $I, '>', sprintf '%s/%s', $Multi::LOGDIR, $f;
+ open $I, '>', sprintf '%s/%s', $VNDB::M{log_dir}, $f;
close $I;
}
}
diff --git a/util/multi.pl b/util/multi.pl
index 6ec3dd02..e234534d 100755
--- a/util/multi.pl
+++ b/util/multi.pl
@@ -21,25 +21,32 @@ package Multi;
use strict;
use warnings;
+no warnings 'once';
use Tie::ShareLite ':lock';
use Time::HiRes;
use POE;
use DBI;
+use Cwd 'abs_path';
-use lib '/www/vndb/lib';
-use Multi::Core;
-BEGIN { require 'global.pl' }
+# loading & initialization
+
+our $ROOT;
+BEGIN { ($ROOT = abs_path $0) =~ s{/util/multi\.pl$}{}; *VNDB::ROOT = \$ROOT }
+use lib $VNDB::ROOT.'/lib';
+use Multi::Core;
+require $VNDB::ROOT.'/data/global.pl';
-our $LOGDIR = '/www/vndb/data/log';
-our $LOGLVL = 3; # 3:DEBUG, 2:ACTIONS, 1:WARN
our $STOP = 0;
our $DAEMONIZE = (grep /^-c$/, @ARGV) ? 1 : (grep /^-s$/, @ARGV) ? 2 : 0;
+
+# only add commands with the -a argument
+
if(grep /^-a$/, @ARGV) {
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
$s->lock(LOCK_EX);
my @q = ( ($s{queue} ? @{$s{queue}} : ()), (grep !/^-/, @ARGV) );
$s{queue} = \@q;
@@ -48,15 +55,15 @@ if(grep /^-a$/, @ARGV) {
}
# one shared pgsql connection for all sessions
-our $SQL = DBI->connect(@VNDB::DBLOGIN,
+our $SQL = DBI->connect(@{$VNDB::O{db_login}},
{ PrintError => 1, RaiseError => 0, AutoCommit => 1, pg_enable_utf8 => 1 });
Multi::Core->spawn();
# dynamically load and spawn modules
-for (0..(@$VNDB::MULTI/2+1)) {
- my($mod, $args) = @{$VNDB::MULTI}[$_*2, $_*2+1];
+for (keys %{$VNDB::M{modules}}) {
+ my($mod, $args) = ($_, $VNDB::M{modules}{$_});
next if !$args || ref($args) ne 'HASH';
require "Multi/$mod.pm";
# I'm surprised the strict pagma isn't complaining about this