[vhffs-dev] [svn] commit: r103 - in /trunk: vhffs-api/src/Vhffs/Robots/ vhffs-robots/src/ vhffs-robots/src/old/

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Author: soda
Date: Fri Dec  9 17:53:30 2005
New Revision: 103

Log:
Clean code, improve bots (vhffs_log, lock, ...)


Added:
    trunk/vhffs-robots/src/old/
    trunk/vhffs-robots/src/old/dns.pl   (with props)
    trunk/vhffs-robots/src/old/mailing
      - copied unchanged from r101, trunk/vhffs-robots/src/mailing
    trunk/vhffs-robots/src/old/svn_apache.pl
      - copied unchanged from r101, trunk/vhffs-robots/src/svn_apache.pl
    trunk/vhffs-robots/src/old/svn_users.pl
      - copied unchanged from r101, trunk/vhffs-robots/src/svn_users.pl
Removed:
    trunk/vhffs-robots/src/dns.pl
    trunk/vhffs-robots/src/mailing
    trunk/vhffs-robots/src/svn_apache.pl
    trunk/vhffs-robots/src/svn_users.pl
Modified:
    trunk/vhffs-api/src/Vhffs/Robots/Mysql.pm
    trunk/vhffs-api/src/Vhffs/Robots/Postgres.pm
    trunk/vhffs-robots/src/delete_mail.pl
    trunk/vhffs-robots/src/delete_ml.pl
    trunk/vhffs-robots/src/delete_mysql.pl
    trunk/vhffs-robots/src/delete_pgsql.pl
    trunk/vhffs-robots/src/delete_svn.pl
    trunk/vhffs-robots/src/delete_users.pl
    trunk/vhffs-robots/src/delete_web.pl
    trunk/vhffs-robots/src/mailing.pl
    trunk/vhffs-robots/src/modify_mysql.pl
    trunk/vhffs-robots/src/modify_pgsql.pl
    trunk/vhffs-robots/src/user_group.pl

Modified: trunk/vhffs-api/src/Vhffs/Robots/Mysql.pm
==============================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Mysql.pm (original)
+++ trunk/vhffs-api/src/Vhffs/Robots/Mysql.pm Fri Dec  9 17:53:30 2005
@@ -58,9 +58,9 @@
 
 sub delete_db
 {
-	my ( $main , $dbname ) = @_;
-
-	my $db = new Vhffs::Services::Mysql( $main , $dbname );
+	my $main = shift;
+	my $db = shift;
+
 	my $query;
 		
 	if( $db->fetch > 0 )
@@ -166,9 +166,9 @@
 
 sub update_db
 {
-        my ( $main , $dbname ) = @_;
-
-        my $db = new Vhffs::Services::Mysql( $main , $dbname );
+		my $main = shift;
+		my $db = shift;
+
         my $query;
 
         if( $db->fetch > 0 )

Modified: trunk/vhffs-api/src/Vhffs/Robots/Postgres.pm
==============================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Postgres.pm (original)
+++ trunk/vhffs-api/src/Vhffs/Robots/Postgres.pm Fri Dec  9 17:53:30 2005
@@ -97,9 +97,9 @@
 
 sub delete_db
 {
-	my ( $main , $dbname ) = @_;
+	my $main = shift;
+	my $pg = shift;
 
-	my $pg = new Vhffs::Services::Postgres( $main , $dbname );
 	my $db = pgsql_admin_db_connect( $main );
 	
 	if( ( $pg->fetch > 0 ) && ( $pg->get_status == Vhffs::Constants::TO_DELETE )  )

Modified: trunk/vhffs-robots/src/delete_mail.pl
==============================================================================
--- trunk/vhffs-robots/src/delete_mail.pl (original)
+++ trunk/vhffs-robots/src/delete_mail.pl Fri Dec  9 17:53:30 2005
@@ -4,7 +4,10 @@
 use Vhffs::Robots::Mail;
 use Vhffs::Services::Mail;
 use Vhffs::Services::Mailing;
+use Vhffs::Robots;
 use Vhffs::Main;
+
+Vhffs::Robots::lock;
 
 
 my $main = init Vhffs::Main;
@@ -14,12 +17,10 @@
 my $list;
 foreach $mail ( @{$mails} )
 {
-	print "Will try to delete mail domain ". $mail->get_domain."\n";
-
     my $lists = Vhffs::Services::Mailing::getall( $main , undef , undef , undef , $mail->get_domain );
 	if( defined $lists )
 	{
-		print "\tRemains mailing-list for this domain\n";
+		vhffs_log( sprintf( "Cannot delete mail domain %s, remains lists" , $mail->get_domain ) );
 		foreach $list ( @{$lists} )
 		{
 			$list->set_status( Vhffs::Constants::TO_DELETE );
@@ -28,8 +29,11 @@
 	}
 	else
 	{
-		print "\tDelete mail domain ". $mail->get_domain."\n";
+		vhffs_log( sprintf( "Delete mail domain %s" , $mail->get_domain ) );
 		$mail->delete;
 	}
 }
 
+Vhffs::Robots::unlock;
+exit 0;
+

Modified: trunk/vhffs-robots/src/delete_ml.pl
==============================================================================
--- trunk/vhffs-robots/src/delete_ml.pl (original)
+++ trunk/vhffs-robots/src/delete_ml.pl Fri Dec  9 17:53:30 2005
@@ -3,7 +3,10 @@
 
 use Vhffs::Main;
 use Vhffs::Constants;
+use Vhffs::Robots;
 use Vhffs::Services::Mailing;
+
+Vhffs::Robots::lock;
 
 my $main = init Vhffs::Main;
 my $mls  = Vhffs::Services::Mailing::getall( $main , Vhffs::Constants::TO_DELETE );
@@ -11,7 +14,16 @@
 
 foreach $ml ( @{$mls} )
 {
-	print "Will delete mailing-list " . $ml->get_listname . "\n";
-	$ml->delete;
+	if( $ml->delete < 0 )
+	{
+		vhffs_log( sprintf( "Cannot delete list %s" , $ml->get_listname ) );
+	}
+	else
+	{
+		vhffs_log( sprintf( "Delete list %s" , $ml->get_listname ) );
+	}
 }
 
+Vhffs::Robots::unlock;
+
+exit 0;

Modified: trunk/vhffs-robots/src/delete_mysql.pl
==============================================================================
--- trunk/vhffs-robots/src/delete_mysql.pl (original)
+++ trunk/vhffs-robots/src/delete_mysql.pl Fri Dec  9 17:53:30 2005
@@ -1,17 +1,30 @@
 #!/usr/bin/perl
 
+use Vhffs::Robots;
+use Vhffs::Robots::Mysql;
+use Vhffs::Services::Mysql;
+use Vhffs::Main;
 
-use Vhffs::Robots::Mysql;
-use Vhffs::Main;
-use Data::Dumper;
+Vhffs::Robots::lock;
+
+my $main = init Vhffs::Main;
+my $dbs = Vhffs::Services::Mysql::getall( $main , Vhffs::Constants::TO_DELETE , undef , undef  );
+my $db;
 
 
-my $main = init Vhffs::Main;
-my $dbs = Vhffs::Robots::Mysql::get_all_db_to_delete( $main );
+foreach $db ( @{$dbs} )
+{
+	if( Vhffs::Robots::Mysql::delete_db( $main , $db ) < 0 )
+	{
+		vhffs_log( sprintf( "Cannot delete MySQL database %s" , $db->get_dbname ));
+	}
+	else
+	{
+		vhffs_log( sprintf( "Delete MySQL database %s" , $db->get_dbname ));
+	}
+}
 
 
-foreach( keys %{$dbs} )
-{
-	Vhffs::Robots::Mysql::delete_db( $main , $_ );
-}
+Vhffs::Robots::unlock;
 
+exit 0;

Modified: trunk/vhffs-robots/src/delete_pgsql.pl
==============================================================================
--- trunk/vhffs-robots/src/delete_pgsql.pl (original)
+++ trunk/vhffs-robots/src/delete_pgsql.pl Fri Dec  9 17:53:30 2005
@@ -1,17 +1,32 @@
 #!/usr/bin/perl
 
-
+use Vhffs::Robots;
+use Vhffs::Services::Postgres;
 use Vhffs::Robots::Postgres;
 use Vhffs::Main;
-use Data::Dumper;
 
 
+Vhffs::Robots::lock;
+
 my $main = init Vhffs::Main;
-my $dbs = Vhffs::Robots::Postgres::get_all_db_to_delete( $main );
+my $dbs = Vhffs::Services::Postgres::getall( $main , Vhffs::Constants::TO_DELETE , undef , undef  );
+my $db;
 
 
-foreach( keys %{$dbs} )
+foreach $db ( @{$dbs} )
 {
-	Vhffs::Robots::Postgres::delete_db( $main , $_ );
+	if(  Vhffs::Robots::Postgres::delete_db( $main , $db ) < 0 )
+	{
+		vhffs_log( "Cannot delete PostgreSQL database %s" , $db->get_dbname ));
+	}
+	else
+	{
+		vhffs_log( "Delete PostgreSQL database %s" , $db->get_dbname ));
+	}
+	}
 }
 
+Vhffs::Robots::unlock;
+
+exit 0;
+

Modified: trunk/vhffs-robots/src/delete_svn.pl
==============================================================================
--- trunk/vhffs-robots/src/delete_svn.pl (original)
+++ trunk/vhffs-robots/src/delete_svn.pl Fri Dec  9 17:53:30 2005
@@ -1,9 +1,12 @@
 #!/usr/bin/perl
 
 use Vhffs::Main;
+use Vhffs::Robots;
 use Vhffs::Robots::Svn;
 use Vhffs::Services::Svn;
 use Vhffs::Constants;
+
+Vhffs::Robots::lock;
 
 my $vhffs = init Vhffs::Main;
 my $repos = Vhffs::Services::Svn::getall( $vhffs , Vhffs::Constants::TO_DELETE);
@@ -12,8 +15,24 @@
 {
 	if( $svn->fetch >= 0)
 	{
-		Vhffs::Robots::Svn::delete_repo( $vhffs , $svn );
-		$svn->delete;
+		if( Vhffs::Robots::Svn::delete_repo( $vhffs , $svn ) < 0 )
+		{
+			vhffs_log( sprintf( "Delete files from SVN repository %s" , $svn->get_reponame ));
+		}
+		else
+		{
+			vhffs_log( sprintf( "Cannot delete files from SVN repository %s" , $svn->get_reponame ));
+		}
+		if( $svn->delete < 0 )
+		{
+			vhffs_log( sprintf( "Cannot delete SVN repository object %s" , $svn->get_reponame ));
+		}
+		else
+		{
+			vhffs_log( sprintf( "Delete SVN repository object %s" , $svn->get_reponame ));
+		}
 	}
 }
 
+Vhffs::Robots::unlock;
+exit 0;

Modified: trunk/vhffs-robots/src/delete_users.pl
==============================================================================
--- trunk/vhffs-robots/src/delete_users.pl (original)
+++ trunk/vhffs-robots/src/delete_users.pl Fri Dec  9 17:53:30 2005
@@ -1,11 +1,12 @@
 #!/usr/bin/perl
 
-
+use Vhffs::Robots;
 use Vhffs::Robots::User;
 use Vhffs::User;
 use Vhffs::Constants;
 use Vhffs::Main;
 
+Vhffs::Robots::lock;
 
 my $main = init Vhffs::Main;
 my $lol = Vhffs::User::getall( $main , Vhffs::Constants::TO_DELETE );
@@ -17,14 +18,13 @@
 	$ok = 1;
     if( ( defined $user ) && ( $user->fetch > 0 ))
     {
-		print sprintf( "Delete user %s \n" , $user->get_username ) ;
 		$groups =  $user->get_groups;
 
 		if( defined $groups )
 		{
 			foreach $group ( @{$groups} )
 			{
-				print sprintf("\tSuppression du groupe : %s\n", $group->get_groupname);
+				vhffs_log( sprintf("Delete %s, remains group(s) : will delete %s " , $user->get_username , $group->get_groupname ) );
 				if( $group->get_owneruid == $user->get_uid )
 				{
 					$ok = 0;
@@ -37,13 +37,30 @@
 		if( $ok == 1 )
 		{
 			printf "\tSuppression du user\n";
-        	Vhffs::Robots::User::delete( $vhffs, $user );
-			$user->delete;
+        	if( Vhffs::Robots::User::delete( $vhffs, $user ) < 0 )
+			{
+				vhffs_log( sprintf("Cannot delete user files %s" , $user->get_username ) );
+			}
+			else
+			{
+				vhffs_log( sprintf("Delete user files %s" , $user->get_username ) );
+			}
+
+			if( $user->delete < 0 )
+			{
+				vhffs_log( sprintf("Cannot delete object files %s" , $user->get_username ) );
+			}
+			else
+			{
+				vhffs_log( sprintf("Delete user object %s" , $user->get_username ) );
+			}
 		}
 		else
 		{
-			printf "\tUser encore actif, il reste des groupes\n";
+			vhffs_log( sprintf("Cannot remove user %s, remains group(s)" , $user->get_username ) );
 		}
     }
 }
 
+Vhffs::Robots::unlock;
+exit 0;

Modified: trunk/vhffs-robots/src/delete_web.pl
==============================================================================
--- trunk/vhffs-robots/src/delete_web.pl (original)
+++ trunk/vhffs-robots/src/delete_web.pl Fri Dec  9 17:53:30 2005
@@ -1,10 +1,12 @@
 #!/usr/bin/perl
 
-
+use Vhffs::Robots;
 use Vhffs::Robots::Web;
 use Vhffs::Services::Httpd;
 use Vhffs::Main;
 use Vhffs::Constants;
+
+Vhffs::Robots::lock;
 
 my $main = init Vhffs::Main;
 my $webs = Vhffs::Services::Httpd::getall( $main , Vhffs::Constants::TO_DELETE );
@@ -13,6 +15,16 @@
 
 foreach $web ( @{$webs} )
 {
-	Vhffs::Robots::Web::delete( $main , $web );
+	if( Vhffs::Robots::Web::delete( $main , $web ) < 0 )
+	{
+		vhffs_log( "Cannot delete web %s" , $web->get_servername );
+	}
+	else
+	{
+		vhffs_log( "Delete web %s" , $web->get_servername );
+	}
 }
 
+
+Vhffs::Robots::unlock;
+exit 0;

Modified: trunk/vhffs-robots/src/mailing.pl
==============================================================================
--- trunk/vhffs-robots/src/mailing.pl (original)
+++ trunk/vhffs-robots/src/mailing.pl Fri Dec  9 17:53:30 2005
@@ -24,7 +24,8 @@
 
 if( ! defined $from )
 {
-	print "Error in conf, the FROM: field is not present\n";
+	vhffs_log( "Cannot send mailing, from is not present in config file" );
+	Vhffs::Robots::unlock;
 	exit( -1 );
 }
 

Modified: trunk/vhffs-robots/src/modify_mysql.pl
==============================================================================
--- trunk/vhffs-robots/src/modify_mysql.pl (original)
+++ trunk/vhffs-robots/src/modify_mysql.pl Fri Dec  9 17:53:30 2005
@@ -1,17 +1,22 @@
 #!/usr/bin/perl
 
+use Vhffs::Robots;
+use Vhffs::Robots::Mysql;
+use Vhffs::Services::Mysql;
+use Vhffs::Main;
 
-use Vhffs::Robots::Mysql;
-use Vhffs::Main;
-use Data::Dumper;
+Vhffs::Robots::lock;
 
 
 my $main = init Vhffs::Main;
-my $dbs = Vhffs::Robots::Mysql::get_all_db_to_update( $main );
+my $dbs = Vhffs::Services:::Mysql::getall( $main , Vhffs::Constants::WAITING_FOR_MODIFICATION , undef , undef );
+my $db;
 
-
-foreach( keys %{$dbs} )
+foreach $db ( @{$dbs} )
 {
-        Vhffs::Robots::Mysql::update_db( $main , $_ );
+        Vhffs::Robots::Mysql::update_db( $main , $db );
 }
 
+Vhffs::Robots::unlock;
+exit 0;
+

Modified: trunk/vhffs-robots/src/modify_pgsql.pl
==============================================================================
--- trunk/vhffs-robots/src/modify_pgsql.pl (original)
+++ trunk/vhffs-robots/src/modify_pgsql.pl Fri Dec  9 17:53:30 2005
@@ -1,17 +1,22 @@
 #!/usr/bin/perl
 
 
+use Vhffs::Robots;
+use Vhffs::Services::Postgres;
 use Vhffs::Robots::Postgres;
 use Vhffs::Main;
-use Data::Dumper;
 
+Vhffs::Robots::lock;
 
 my $main = init Vhffs::Main;
-my $dbs = Vhffs::Robots::Postgres::get_all_db_to_update( $main );
+my $dbs = Vhffs::Services::Postgres::getall( $main , Vhffs::Constants::WAITING_FOR_MODIFICATION , undef , undef );
+my $db;
 
-
-foreach( keys %{$dbs} )
+foreach $db ( @{$dbs} )
 {
-	Vhffs::Robots::Postgres::update_db( $main , $_ );
+	Vhffs::Robots::Postgres::update_db( $main , $db );
 }
 
+Vhffs::Robots::lock;
+
+exit 0;

Modified: trunk/vhffs-robots/src/user_group.pl
==============================================================================
--- trunk/vhffs-robots/src/user_group.pl (original)
+++ trunk/vhffs-robots/src/user_group.pl Fri Dec  9 17:53:30 2005
@@ -4,7 +4,9 @@
 use Vhffs::User;
 use Vhffs::Group;
 use Vhffs::Robots::Group;
+use Vhffs::Robots;
 
+Vhffs::Robots::lock;
 
 
 my $user;
@@ -28,19 +30,22 @@
 		{
 			if( Vhffs::Robots::Group::add_user( $user , $group , $vhffs ) < 0 )
 			{
-				print "Error while join user " . $user->get_username . " with group ".$group->get_groupname."\n";
-
+				vhffs_log( "Error adding user %s to group %s" , $user->get_username , $group->get_groupname ));
+			}
+			else
+			{
+				vhffs_log( "Add user %s to group %s" , $user->get_username , $group->get_groupname ));
 			}
 			
 		}
 		else
 		{
-#			print "error while getting user$_\n";
+			vhffs_log( "Cannot get user %s" , $_ ));
 		}
 	}
 	else
 	{
-#		print "error while getting group $_ \n";
+		vhffs_log( "Cannot get user %s" , $_ ));
 	}
 }
 }
@@ -65,16 +70,21 @@
 
 		if( ( defined $user ) && ( $user->fetch > 0 ) )
 		{
+			vhffs_log( "Remove user %s from group %s" , $user->get_username , $group->get_groupname ));
 			Vhffs::Robots::Group::del_user( $user , $group , $vhffs );
 			
 		}
 		else
 		{
-#			print "error while getting user$_\n";
+			vhffs_log( "Cannot get user %s" , $name ));
 		}
 	}
 	else
 	{
-#		print "error while getting group $_ \n";
+		vhffs_log( "Cannot get group %s" , $_ ));
 	}
 }
+
+Vhffs::Robots::unlock;
+
+exit 0;




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/