summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authoryorhel <yorhel@1fe2e327-d9db-4752-bcf7-ef0cb4a1748b>2008-04-24 17:48:59 +0000
committeryorhel <yorhel@1fe2e327-d9db-4752-bcf7-ef0cb4a1748b>2008-04-24 17:48:59 +0000
commitd2efb163c11a11e02abd7251fdfde3cb54c710ef (patch)
tree848de5db61c434d38adc8871f4999ea344b196fe /util
parent491d871612f7e4d351d533d30fe942332132ea41 (diff)
See the diff for lib/ChangeLog...
git-svn-id: svn://vndb.org/vndb@4 1fe2e327-d9db-4752-bcf7-ef0cb4a1748b
Diffstat (limited to 'util')
-rw-r--r--util/cleanimg.pl11
-rwxr-xr-xutil/multi.pl96
-rw-r--r--[-rwxr-xr-x]util/relgraph.pl26
-rw-r--r--[-rwxr-xr-x]util/sitemap.pl5
-rw-r--r--[-rwxr-xr-x]util/updates/update_1.14.pl3
5 files changed, 125 insertions, 16 deletions
diff --git a/util/cleanimg.pl b/util/cleanimg.pl
index 527fdb3a..45032106 100644
--- a/util/cleanimg.pl
+++ b/util/cleanimg.pl
@@ -1,5 +1,12 @@
#!/usr/bin/perl
+
+
+#
+# O L D - D O N O T U S E !
+#
+
+
use strict;
use warnings;
use Time::HiRes 'gettimeofday', 'tv_interval';
@@ -12,9 +19,11 @@ use Image::MetaData::JPEG;
use File::Copy 'cp', 'mv';
use Digest::MD5;
+require '/www/vndb/lib/global.pl';
+
our $ST;
-my $sql = DBI->connect('dbi:Pg:dbname=vndb', 'vndb', 'passwd',
+my $sql = DBI->connect(@VNDB::DBLOGIN,
{ RaiseError => 1, PrintError => 0, AutoCommit => 1, pg_enable_utf8 => 1 });
my $imgpath = '/www/vndb/static/img';
diff --git a/util/multi.pl b/util/multi.pl
new file mode 100755
index 00000000..b4b4cad2
--- /dev/null
+++ b/util/multi.pl
@@ -0,0 +1,96 @@
+#!/usr/bin/perl
+
+# This is just a small script to test and play around with a
+# processing queue for actions on VNDB that do not have a
+# strict time limit. i.e. resizing and optimizing cover images
+# and (re)generating the relation graphs. Because I'm using
+# the POE framework, it will also be possible to integrate
+# Multi the IRC bot in the same process.
+#
+# The queue is an array of commands, and should be executed
+# in chronological order. Commands are in the form of
+# [cmd] [arguments]
+# where [cmd] is an internal command, and [arguments] a
+# whitespace seperated list of arguments.
+#
+# Commands can be added from the web interface using shared
+# memory, or from IRC if Multi is going to integrated in here.
+
+
+# Usage:
+# ./multi.pl [-c] [-s] [cmd1] [cmd2] ..
+# -c Do not daemonize, just execute the commands specified
+# on the command line and exit.
+# -s Same as -c, but also execute commands in the shared
+# memory processing queue.
+# -a Don't do anything, just add the commands specified on
+# the command line to the shared memory processing queue.
+
+
+# TODO: error handling
+
+#
+# Multi - core namespace for initialisation and global variables
+#
+
+package Multi;
+
+use strict;
+use warnings;
+use Time::HiRes;
+use POE;
+use Storable 'freeze', 'thaw';
+use IPC::ShareLite ':lock';
+use DBI;
+
+use lib '/www/vndb/lib';
+use Multi::Core;
+use Multi::RG;
+use Multi::Sitemap;
+use Multi::IRC;
+
+BEGIN { require 'global.pl' }
+
+
+ $ENV{PATH} = '/usr/bin';
+our $VERSION = '0.9';
+our $LOGDIR = '/www/vndb/data/log';
+our $LOGLVL = 3; # 3:DEBUG, 2:ACTIONS, 1:WARN
+our $RESTART = 0;
+our $DAEMONIZE = (grep /^-c$/, @ARGV) ? 1 : (grep /^-s$/, @ARGV) ? 2 : 0;
+our %MODULES = ();
+
+
+if(grep /^-a$/, @ARGV) {
+ my $s = IPC::ShareLite->new(-key => $VNDB::SHMKEY,-create => 1, -destroy => 0);
+ $s->lock(LOCK_EX);
+ my $l = $s->fetch();
+ my @queue = ($l?@{thaw($l)}:(), grep !/^-/, @ARGV);
+ $s->store(freeze(\@queue));
+ $s->unlock();
+ exit;
+}
+
+
+# one shared pgsql connection for all sessions
+our $SQL = DBI->connect(@VNDB::DBLOGIN,
+ { PrintError => 1, RaiseError => 0, AutoCommit => 1, pg_enable_utf8 => 1 });
+
+
+Multi::Core->spawn();
+Multi::RG->spawn();
+Multi::Sitemap->spawn();
+Multi::IRC->spawn(
+ server => 'irc.synirc.net',
+ user => 'Multi_'.$$,
+ channel => '#vndb_test'
+) if 0;
+
+
+$SIG{__WARN__} = sub {(local$_=shift)=~s/\r?\n//;$poe_kernel->call(core=>log=>1,'__WARN__: '.$_)};
+
+$poe_kernel->run();
+exec $0, grep /^-/, @ARGV if $RESTART;
+
+
+
diff --git a/util/relgraph.pl b/util/relgraph.pl
index cdbd022b..a4ae486d 100755..100644
--- a/util/relgraph.pl
+++ b/util/relgraph.pl
@@ -7,6 +7,7 @@ $ENV{PATH} = '/usr/bin'; # required for GraphViz
use strict;
use warnings;
+no warnings 'once';
use Text::Unidecode;
#use Time::HiRes 'gettimeofday', 'tv_interval';
#BEGIN { $S = [ gettimeofday ]; }
@@ -23,7 +24,6 @@ require '/www/vndb/lib/global.pl';
my $font = 's'; #Comic Sans MSssss';
my @fsize = ( 9, 7, 10 ); # nodes, edges, node_title
-my $tmpfile = '/tmp/vndb_graph.gif';
my $destdir = '/www/vndb/static/rg';
my $datdir = '/www/vndb/data/rg';
my $DEBUG = 0;
@@ -67,8 +67,7 @@ my @edge_rel = map {
-my $sql = DBI->connect('dbi:Pg:dbname=vndb', 'vndb', 'passwd',
- { RaiseError => 1, PrintError => 0, AutoCommit => 0, pg_enable_utf8 => 1 });
+my $sql = DBI->connect(@VNDB::DBLOGIN, { RaiseError => 1, PrintError => 0, AutoCommit => 0, pg_enable_utf8 => 1 });
my %ids; my %nodes;
my %rels; # "v1-v2" => 1
my @done;
@@ -95,9 +94,9 @@ sub createGraph { # vid
$sql->do(q|UPDATE vn SET rgraph = 0 WHERE id = ?|, undef, $id);
return 0;
}
-
+
# correct order!
- for (sort { $a->[2] cmp $b->[2] } values %nodes) {
+ for (sort { $a->[2] <=> $b->[2] } values %nodes) {
$DEBUG && printf "ADD: %d\n", $_->[0];
$_->[2] =~ s#^([0-9]{4})([0-9]{2}).+#$1==0?'N/A':$1==9999?'TBA':(($2&&$2>0?($Time::CTime::MoY[$2-1].' '):'').$1)#e;
$g->add_node($_->[0], %nodes_all, URL => '/v'.$_->[0], tooltip => $_->[1], label => sprintf
@@ -110,10 +109,11 @@ sub createGraph { # vid
# make sure to sort the edges on node release dates
my @rel = map { [ split(/-/, $_), $rels{$_} ] } keys %rels;
- for (sort { ($ids{$a->[0]}gt$ids{$a->[1]}?$ids{$a->[1]}:$ids{$a->[0]})
- cmp ($ids{$b->[0]}gt$ids{$b->[1]}?$ids{$b->[1]}:$ids{$b->[0]}) } @rel) {
+ for (sort { ($ids{$a->[0]} > $ids{$a->[1]} ? $ids{$a->[1]} : $ids{$a->[0]})
+ cmp ($ids{$b->[0]} > $ids{$b->[1]} ? $ids{$b->[1]} : $ids{$b->[0]}) } @rel) {
- if($ids{$_->[1]} gt $ids{$_->[0]}) {
+ # [older game] -> [newer game]
+ if($ids{$_->[1]} > $ids{$_->[0]}) {
($_->[0], $_->[1]) = ($_->[1], $_->[0]);
$_->[2] = reverseRel($_->[2]);
}
@@ -121,7 +121,6 @@ sub createGraph { # vid
$DEBUG && printf "ADD %d -> %d\n", $_->[1], $_->[0];
}
-
$DEBUG && print "IMAGE\n";
# get a new number
@@ -158,20 +157,21 @@ sub createGraph { # vid
sub getRel { # gobj, vid
my($g, $id) = @_;
- $ids{$id} = 0; # false but defined
+ #$ids{$id} = 0; # false but defined
$DEBUG && printf "GET: %d\n", $id;
my $s = $sql->prepare(q|
SELECT vr1.vid AS vid1, r.vid2, r.relation, vr1.title AS title1, vr2.title AS title2,
v1.c_released AS date1, v2.c_released AS date2, v1.c_languages AS lang1, v2.c_languages AS lang2
FROM vn_relations r
JOIN vn_rev vr1 ON r.vid1 = vr1.id
- JOIN vn v1 ON v1.id = vr1.vid
+ JOIN vn v1 ON v1.latest = vr1.id
JOIN vn v2 ON r.vid2 = v2.id
- JOIN vn_rev vr2 ON v2.id = vr2.vid
- WHERE (r.vid2 = ? OR vr1.vid = ?) AND v1.latest = vr1.id|
+ JOIN vn_rev vr2 ON v2.latest = vr2.id
+ WHERE (r.vid2 = ? OR vr1.vid = ?)|
);
$s->execute($id, $id);
for my $r (@{$s->fetchall_arrayref({})}) {
+ $DEBUG && printf " %d: %d - %d\n", $id, $r->{vid1}, $r->{vid2};
if($r->{vid1} < $r->{vid2}) {
$rels{$r->{vid1}.'-'.$r->{vid2}} = reverseRel($r->{relation});
} else {
diff --git a/util/sitemap.pl b/util/sitemap.pl
index 64b0957a..6fde2f80 100755..100644
--- a/util/sitemap.pl
+++ b/util/sitemap.pl
@@ -8,13 +8,16 @@ my %chfr = qw( a always h hourly d daily w weekly m monthly y yearly n ne
# the code
use strict;
use warnings;
+no warnings 'once';
use DBI;
use POSIX; # for ceil();
use XML::Writer;
use PerlIO::gzip;
use DateTime;
-my $sql = DBI->connect('dbi:Pg:dbname=vndb', 'vndb', 'passwd',
+require '/www/vndb/lib/global.pl';
+
+my $sql = DBI->connect(@VNDB::DBLOGIN,
{ RaiseError => 1, PrintError => 0, AutoCommit => 1, pg_enable_utf8 => 1 });
my $urls = 0;
diff --git a/util/updates/update_1.14.pl b/util/updates/update_1.14.pl
index 1bfc517a..9c4e787d 100755..100644
--- a/util/updates/update_1.14.pl
+++ b/util/updates/update_1.14.pl
@@ -2,6 +2,7 @@
use strict;
use warnings;
+no warnings 'once';
use File::Path;
use DBI;
@@ -37,7 +38,7 @@ system('util/relgraph.pl');
# rename cover images
-my $sql = DBI->connect('dbi:Pg:dbname=vndb', 'vndb', 'passwd',
+my $sql = DBI->connect(@VNDB::DBLOGIN,
{ RaiseError => 0, PrintError => 1, AutoCommit => 1, pg_enable_utf8 => 1 });
$sql->do('CREATE SEQUENCE covers_seq');
$sql->do('ALTER TABLE vn_rev ADD COLUMN image_id integer NOT NULL DEFAULT 0');