From: naoki i. <am...@us...> - 2008-04-16 13:08:10
|
Update of /cvsroot/popfile/engine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22400 Modified Files: bayes.pl insert.pl pipe.pl Added Files: import.pl Log Message: Change Log 1. Added the UI to rename user's name UI/HTML.pm Classifier/Bayes.pm POPFile/API.pm skins/default/users-page.thtml languages/English.msg languages/Nihongo.msg tests/TestBayes.tst 2. Save the current piddir and restore in the utility scripts bayes.pl insert.pl pipe.pl 3. TestXMLRPC's child process (xmlrpc server) now terminates tests/TestXMLRPC.tst 4. Use the place holders in preparing SQL statements UI/HTML.pm POPFile/History.pm 5. Copy the global language setting to the new user's default language Classifier/Bayes.pm 6. New script to import old database to new database import.pl import.pl - import user data into the new database Usage: import.pl <old_user_dir> <user> [<newuser>] <old_user_dir> The path to the user data to import <user> The name of the user to import from Use 'admin' when upgrading from v1 <newuser> The name of the user to import into (optional) If not specified, assume newuser=user 7. Added multi user support tests tests/TestHistory.tst Current state of the test suite: TestBayesScript PASS TestBayes PASS TestConfiguration PASS * TestHistory PASS TestHTML PASS * TestHTTP PASS TestIMAP PASS TestInsertScript PASS * TestLogger PASS TestMailParse PASS TestModule PASS TestMQ PASS TestMutex PASS TestPipeScript PASS TestPOP3 PASS TestProxy PASS TestWordMangle PASS TestXMLRPC PASS * : TODO : needs to add tests for multi user support Index: pipe.pl =================================================================== RCS file: /cvsroot/popfile/engine/pipe.pl,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** pipe.pl 6 Feb 2006 15:09:54 -0000 1.17 --- pipe.pl 16 Apr 2008 13:08:04 -0000 1.18 *************** *** 59,62 **** --- 59,63 ---- # Prevent the tool from finding another copy of POPFile running + my $current_piddir = $c->config_( 'piddir' ); $c->config_( 'piddir', $c->config_( 'piddir' ) . 'pipe.pl.' ); *************** *** 67,73 **** my $b = $POPFile->get_module('Classifier::Bayes'); ! my $session = $b->get_session_key( 'admin', '' ); $b->classify_and_modify( $session, \*STDIN, \*STDOUT, 1, '', 0, 1, "\n" ); $b->release_session_key( $session ); $POPFile->CORE_stop(); --- 68,76 ---- my $b = $POPFile->get_module('Classifier::Bayes'); ! my $session = $b->get_administrator_session_key(); $b->classify_and_modify( $session, \*STDIN, \*STDOUT, 1, '', 0, 1, "\n" ); + + $c->config_( 'piddir', $current_piddir ); $b->release_session_key( $session ); $POPFile->CORE_stop(); Index: bayes.pl =================================================================== RCS file: /cvsroot/popfile/engine/bayes.pl,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** bayes.pl 6 Feb 2006 15:09:54 -0000 1.41 --- bayes.pl 16 Apr 2008 13:08:04 -0000 1.42 *************** *** 59,62 **** --- 59,63 ---- my $c = $POPFile->get_module('POPFile::Config'); + my $current_piddir = $c->config_( 'piddir' ); $c->config_( 'piddir', $c->config_( 'piddir' ) . 'bayes.pl.' ); *************** *** 67,71 **** my $b = $POPFile->get_module('Classifier::Bayes'); ! my $session = $b->get_session_key( 'admin', '' ); foreach my $file (@files) { --- 68,72 ---- my $b = $POPFile->get_module('Classifier::Bayes'); ! my $session = $b->get_administrator_session_key(); foreach my $file (@files) { *************** *** 87,90 **** --- 88,92 ---- } + $c->config_( 'piddir', $current_piddir ); $b->release_session_key( $session ); $POPFile->CORE_stop(); --- NEW FILE: import.pl --- #!/usr/bin/perl # ---------------------------------------------------------------------------- # # import.pl --- Imports the old database into the new database # # Copyright (c) 2001-2008 John Graham-Cumming # # This file is part of POPFile # # POPFile is free software; you can redistribute it and/or modify it # under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # POPFile is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with POPFile; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # ---------------------------------------------------------------------------- use strict; use File::Copy; use lib defined($ENV{POPFILE_ROOT})?$ENV{POPFILE_ROOT}:'./'; my $code = 0; if ( $#ARGV > 0 ) { my ( $user_dir, $username, $newusername ) = @ARGV; $newusername = $username if ( !defined($newusername) ); # $user_dir = "../corpus_import"; # $username = "admin"; # $newusername = "test_dummy3"; use POPFile::Loader; my $POPFile = POPFile::Loader->new(); # $POPFile->{debug__} = 1; $POPFile->CORE_loader_init(); $POPFile->CORE_signals(); my %valid = ( 'POPFile/Database' => 1, 'POPFile/Logger' => 1, 'POPFile/MQ' => 1, 'Classifier/Bayes' => 1, 'POPFile/Configuration' => 1 ); $POPFile->CORE_load( 0, \%valid ); $POPFile->CORE_initialize(); $POPFile->CORE_config( 1 ); my $b = $POPFile->get_module( 'Classifier/Bayes' ); my $c = $POPFile->get_module( 'POPFile/Configuration' ); my $l = $POPFile->get_module( 'POPFile/Logger' ); $c->{popfile_user__} = $user_dir; $c->load_configuration(); # $l->config_( 'level' ,2 ); # Backup the database and the setting file copy ( $c->get_user_path( 'popfile.cfg' ), $c->get_user_path( 'popfile.cfg.bak' ) ); copy ( $c->get_user_path( 'popfile.db' ), $c->get_user_path( 'popfile.db.bak' ) ); # Convert the database $POPFile->CORE_start(); my $POPFile2 = POPFile::Loader->new(); # $POPFile2->{debug__} = 1; $POPFile2->CORE_loader_init(); $POPFile2->CORE_signals(); $POPFile2->CORE_load( 0, \%valid ); $POPFile2->CORE_initialize(); $POPFile2->CORE_config( 1 ); my $b2 = $POPFile2->get_module( 'Classifier/Bayes' ); my $c2 = $POPFile2->get_module( 'POPFile/Configuration' ); $POPFile2->CORE_start(); # Fetch the database version my $h = $b->db_()->prepare( "select version from popfile;" ); $h->execute; my $row = $h->fetchrow_arrayref; my $version = $row->[0]; $h->finish; my $import_db = $c->get_user_path( 'popfile.db' ); print "Import from database '$import_db'\n"; # Fetch the old user $h = $b->db_()->prepare( "select id from users where name = ?;" ); $h->execute( $username ); $row = $h->fetchrow_arrayref; my $userid = $row->[0]; $h->finish; # Create a new user my $session = $b2->get_administrator_session_key(); my ( $result, $password ) = $b2->create_user( $session, $newusername ); if ( defined($result) && ( $result eq 0 ) && defined($password ) ) { my $user_session = $b2->get_session_key( $newusername, $password ); my $newuserid = $b2->get_user_id_from_session( $user_session ); print " New user '$newusername' is created. The user's initial password is '$password'\n"; # Fetch the parameters for the user my %user_params; $h = $b->db_()->prepare( "select user_template.name, user_params.val from user_template, user_params where user_template.id = user_params.utid and user_params.userid = ?;" ); $h->execute( $userid ); while ( my $row = $h->fetchrow_arrayref ) { # Should not copy the admin flag next if ( $row->[0] eq 'GLOBAL_can_admin' ); my $parameter = $row->[0]; $parameter =~ m/^([^_]+)_(.*)$/; my $module = $1; my $config = $2; $c2->user_module_config_( $newuserid, $module, $config, $row->[1] ); } # Fetch the buckets for the user my %buckets; $b->{db_get_buckets__}->execute( $userid ); while ( my $row = $b->{db_get_buckets__}->fetchrow_arrayref ) { $buckets{$row->[0]}{id} = $row->[1]; $buckets{$row->[0]}{pseudo} = $row->[2]; } # Create buckets for the new user foreach my $bucket ( keys %buckets ) { next if ( $buckets{$bucket}{pseudo} ); $b2->create_bucket( $user_session, $bucket ); print " Created a bucket '$bucket'\n"; } # Fetch the bucket parameters for user my %bucket_params; $h = $b->db_()->prepare( "select bucket_template.name, bucket_params.val from bucket_template, bucket_params where bucket_params.btid = bucket_template.id and bucket_params.bucketid = ?;" ); foreach my $bucket ( keys %buckets ) { $h->execute( $buckets{$bucket}{id} ); while ( my $row = $h->fetchrow_arrayref ) { $b2->set_bucket_parameter( $user_session, $bucket, $row->[0], $row->[1] ); } } $h->finish; # Fetch the magnets for user my %magnets; $h = $b->db_()->prepare( "select magnet_types.mtype, magnets.val from magnet_types, magnets where magnet_types.id = magnets.mtid and magnets.bucketid = ?;" ); foreach my $bucket ( keys %buckets ) { $h->execute( $buckets{$bucket}{id} ); while ( my $row = $h->fetchrow_arrayref ) { $b2->create_magnet( $user_session, $bucket, $row->[0], $row->[1] ); } } $h->finish; # Fetch the words in the bucket $h = $b->db_()->prepare( "select words.word, matrix.times from words, matrix where words.id = matrix.wordid and matrix.bucketid = ?;" ); foreach my $bucket ( keys %buckets ) { next if ( $buckets{$bucket}{pseudo} ); # Word list $b2->{parser__}{words__} = (); $h->execute( $buckets{$bucket}{id} ); while ( my $row = $h->fetchrow_arrayref ) { $b2->{parser__}{words__}{$row->[0]} = $row->[1]; } # Add words to bucket print " Importing words into the bucket '$bucket'...\n"; $b2->add_words_to_bucket__( $user_session, $bucket, 1 ); } $h->finish; print "Imported the database successfully\n"; } else { print "Failed to create a user '$newusername'\n"; } $POPFile2->CORE_stop(); $POPFile->CORE_stop(); } else { print "import.pl - import user data into the new database\n\n"; print "Usage: import.pl <old_user_dir> <user> [<newuser>]\n"; print " <old_user_dir> The path to the user data to import\n"; print " <user> The name of the user to import from\n"; print " Use 'admin' when upgrading from v1\n"; print " <newuser> The name of the user to import into (optional)\n"; print " If not specified, assume newuser=user\n"; $code = 1; } exit $code; Index: insert.pl =================================================================== RCS file: /cvsroot/popfile/engine/insert.pl,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** insert.pl 6 Apr 2008 08:27:07 -0000 1.42 --- insert.pl 16 Apr 2008 13:08:04 -0000 1.43 *************** *** 52,55 **** --- 52,56 ---- my $c = $POPFile->get_module('POPFile::Config'); + my $current_piddir = $c->config_( 'piddir' ); $c->config_( 'piddir', $c->config_( 'piddir' ) . 'insert.pl.' ); *************** *** 72,76 **** $c->{save_needed__} = 0; ! my $b = $POPFile->get_module('Classifier::Bayes'); my $session = $b->get_administrator_session_key(); --- 73,77 ---- $c->{save_needed__} = 0; ! my $b = $POPFile->get_module( 'Classifier::Bayes' ); my $session = $b->get_administrator_session_key(); *************** *** 113,116 **** --- 114,118 ---- } + $c->config_( 'piddir', $current_piddir ); $b->release_session_key( $user_session ) if ( $multiuser_mode && defined($user_session) ); $b->release_session_key( $session ); |