[vhffs-dev] [1421] full rewrite of svn robots

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


Revision: 1421
Author:   gradator
Date:     2009-05-29 23:59:13 +0200 (Fri, 29 May 2009)

Log Message:
-----------
full rewrite of svn robots

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Robots/Svn.pm
    trunk/vhffs-robots/src/svn_create.pl
    trunk/vhffs-robots/src/svn_delete.pl
    trunk/vhffs-robots/src/svn_public.pl


Modified: trunk/vhffs-api/src/Vhffs/Robots/Svn.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Svn.pm	2009-05-29 06:05:10 UTC (rev 1420)
+++ trunk/vhffs-api/src/Vhffs/Robots/Svn.pm	2009-05-29 21:59:13 UTC (rev 1421)
@@ -40,12 +40,13 @@
 
 sub change_conf
 {
-	my $svn	=	shift;
-	my $file = $svn->get_dir."/conf/svnserve.conf";
-	my @lines;
-	my $line;
-	return -1 if( ! -f $file );
+	my $svn	= shift;
+	return -1 unless defined $svn;
 
+	my $file = $svn->get_dir.'/conf/svnserve.conf';
+	return -1 unless -f $file;
+
+	my @lines;
 	open( FILE , $file );
 	while( <FILE> )
 	{
@@ -54,23 +55,23 @@
 	close( FILE );
 
 
-	open( FILE , ">$file" );
-	foreach $line ( @lines )
+	open( FILE , '>'.$file );
+	foreach my $line ( @lines )
 	{
 		if( $line =~ /.*anon\-access.*/ )
 		{
 			if( $svn->is_public == 1 )
 			{
-				$line = "anon-access = read\n";
+				$line = 'anon-access = read'."\n";
 			}
 			else
 			{
-				$line = "anon-access = none\n";
+				$line = 'anon-access = none'."\n";
 			}
 		}
 		if( $line =~ /.*\[general\].*/ )
 		{
-			$line = "[general]\n";
+			$line = '[general]'."\n";
 		}
 		print FILE $line;
 	}
@@ -84,7 +85,6 @@
 	if( defined $mailfrom && defined $mailto )  {
 
 		my @lines;
-		my $line;
 
 		# read template file
 		open( POSTCOMMIT , '%VHFFS_BOTS_DIR%/misc/svn_post-commit.pl' );
@@ -96,7 +96,7 @@
 		# write hook
 		unlink ( $svn->get_dir().'/hooks/post-commit' );
 		open ( POSTCOMMIT , '>'.$svn->get_dir().'/hooks/post-commit' );
-		foreach $line ( @lines )  {
+		foreach my $line ( @lines )  {
 
 			# remplace some parameters
 			$line =~ s/%MAILNOTIFYFROM%/$mailfrom/g;
@@ -108,64 +108,55 @@
 		chmod 0755 , $svn->get_dir().'/hooks/post-commit';
 	}
 	
-	$svn->add_history( "Change configuration of SVN repository" );
+	$svn->add_history( 'Changed configuration of SVN repository' );
 
-	return 1;
+	return 0;
 }
 
 
 sub create_repo
 {
-	my( $main , $svn ) = @_;
+	my $svn = shift;
+	return -1 unless defined $svn;
+	return -1 if $svn->get_status != Vhffs::Constants::WAITING_FOR_CREATION;
 
+	my $dir = $svn->get_dir;
 
-	my $dir;
-	my $dir2;
-	my $apache_file;
-	my $user_file;
+	if( -e $dir ) {
+		$svn->set_status( Vhffs::Constants::CREATING_ERROR );
+		$svn->commit();
+		$svn->add_history('Error, directory of this svn repository already exists! Administrators must fix the problem.');
+		return -1;
+	}
 
-	if( defined $svn ) 
-	{
-	    $dir = $svn->get_dir;
-	    
-	    if( $svn->get_status == Vhffs::Constants::WAITING_FOR_CREATION )
-	    {
-    		my $ok = 1;
-		
-	    	if( ! -e $dir ) {
-		        Vhffs::Functions::create_dir( $dir ) if( ! -d $dir );
-		        $svn->add_history("Ok, robots find the empty directory and will create subversion repository");
-    			system("svnadmin create --fs-type fsfs $dir");
+	Vhffs::Functions::create_dir( $dir );
+	Vhffs::Functions::chmod_recur( $dir , 0664 , 02775 );
+	Vhffs::Functions::change_owner_recur( $dir , $svn->get_owner_uid , $svn->get_owner_gid );
+	$svn->add_history('Ok, robots find the empty directory and will create svn repository');
 
-	    		Vhffs::Functions::chmod_recur( $dir , 0664 , 02775 );
-		        Vhffs::Functions::change_owner_recur( $dir , $svn->get_owner_uid , $svn->get_owner_gid );
+	system('svnadmin create --fs-type fsfs '.$dir);
 
-			# .'/hooks' directory must be owned by root to prevent abuse of servers
-	    		Vhffs::Functions::chmod_recur( $dir.'/hooks' , 0644 , 0755 );
-		        Vhffs::Functions::change_owner_recur( $dir.'/hooks' , 0 , 0 );
+	unless( -f $dir.'/format' ) {
+		$svn->set_status( Vhffs::Constants::CREATING_ERROR );
+		$svn->commit();
+		$svn->add_history('Error, nothing was created after calling the svnadmin binary, something is wrong.');
+		return -1;
+	}	
 
-			change_conf( $svn );
-    			$svn->add_history("The Robots created the subversion repository");
-                } else {
-	    		$ok = 0;
-			#TODO support syslog
-			$svn->set_status( Vhffs::Constants::CREATING_ERROR );
-    			$svn->commit();
-	    		$svn->add_history("Error, directory of this subversion already exists ! Administrators must fix the problem");
-	        }
-		if( $ok == 1 ) {
-			$svn->set_status( Vhffs::Constants::ACTIVATED );
-		    
-			if( $svn->commit < 0 ) {
-				$svn->add_history( "Cannot commit changes on the object ! ");
-	    	  	} else {
-		   	 	$svn->add_history( "Subversion repository is now active");
-		        }
-		} else {
-		        $svn->add_history("Object is not created, problem while creating it");
-    		}
-            }
-	}
+	Vhffs::Functions::chmod_recur( $dir , 0664 , 02775 );
+	Vhffs::Functions::change_owner_recur( $dir , $svn->get_owner_uid , $svn->get_owner_gid );
+
+	# './hooks' directory must be owned by root to prevent abuse of servers
+	Vhffs::Functions::chmod_recur( $dir.'/hooks' , 0644 , 0755 );
+	Vhffs::Functions::change_owner_recur( $dir.'/hooks' , 0 , 0 );
+	
+	change_conf( $svn );
+
+	$svn->add_history('The Robots created the subversion repository');
+	$svn->set_status( Vhffs::Constants::ACTIVATED );
+	$svn->commit();
+
+	return 0;
 }
 
 
@@ -173,23 +164,17 @@
 
 sub delete_repo
 {
-	my $main = shift;
 	my $svn = shift;
+	return -1 unless defined $svn;
 
-	my $dir;
-	my $dir2;
+	my $dir = $svn->get_dir;
+	system('rm -rf '.$dir.' 2>/dev/null');
 
-	if( defined $svn ) {
-	    $dir = $svn->get_dir;
-	    system("rm -rf $dir 2>/dev/null");
-	    $svn->delete;
-    } else {
-	    return -1;
-	}
+	# TODO: is it a good idea here ?
+	$svn->delete;
 	
-	return 1;
+	return 0;
 }
 
 
 1;
-

Modified: trunk/vhffs-robots/src/svn_create.pl
===================================================================
--- trunk/vhffs-robots/src/svn_create.pl	2009-05-29 06:05:10 UTC (rev 1420)
+++ trunk/vhffs-robots/src/svn_create.pl	2009-05-29 21:59:13 UTC (rev 1421)
@@ -42,19 +42,18 @@
 
 my $vhffs = init Vhffs::Main;
 
-Vhffs::Robots::lock( $vhffs , "svn" );
+Vhffs::Robots::lock( $vhffs , 'svn' );
 
-my $repos = Vhffs::Services::Svn::getall( $vhffs , Vhffs::Constants::WAITING_FOR_CREATION);
-my $svn;
-foreach $svn ( @{$repos} )
+my $repos = Vhffs::Services::Svn::getall( $vhffs , Vhffs::Constants::WAITING_FOR_CREATION );
+foreach my $svn ( @{$repos} )
 {
-	if( Vhffs::Robots::Svn::create_repo( $vhffs , $svn ) < 0 ) {
-    		Vhffs::Robots::vhffs_log( sprintf( "Cannot create SVN %s" , $svn->get_reponame ), $vhffs);
+	if( Vhffs::Robots::Svn::create_repo( $svn ) != 0 ) {
+    		Vhffs::Robots::vhffs_log( sprintf( 'Cannot create SVN %s' , $svn->get_reponame ), $vhffs );
 	} else {
-		Vhffs::Robots::vhffs_log( sprintf( "Create SVN %s" , $svn->get_reponame ), $vhffs);
+		Vhffs::Robots::vhffs_log( sprintf( 'Created SVN %s' , $svn->get_reponame ), $vhffs );
 	}
 }
 
 
-Vhffs::Robots::unlock( $vhffs , "svn" );
+Vhffs::Robots::unlock( $vhffs , 'svn' );
 exit 0;

Modified: trunk/vhffs-robots/src/svn_delete.pl
===================================================================
--- trunk/vhffs-robots/src/svn_delete.pl	2009-05-29 06:05:10 UTC (rev 1420)
+++ trunk/vhffs-robots/src/svn_delete.pl	2009-05-29 21:59:13 UTC (rev 1421)
@@ -42,24 +42,23 @@
 
 my $vhffs = init Vhffs::Main;
 
-Vhffs::Robots::lock( $vhffs , "svn" );
+Vhffs::Robots::lock( $vhffs , 'svn' );
 
 my $repos = Vhffs::Services::Svn::getall( $vhffs , Vhffs::Constants::TO_DELETE);
-my $svn;
-foreach $svn ( @{$repos} )
+foreach my $svn ( @{$repos} )
 {
-	if( Vhffs::Robots::Svn::delete_repo( $vhffs , $svn ) < 0 )	{
-		Vhffs::Robots::vhffs_log( sprintf( "Cannot delete files from SVN repository %s" , $svn->get_reponame ), $vhffs);
+	if( Vhffs::Robots::Svn::delete_repo( $svn ) != 0 )	{
+		Vhffs::Robots::vhffs_log( sprintf( 'Cannot delete files from SVN repository %s' , $svn->get_reponame ), $vhffs );
 	} else {
-		Vhffs::Robots::vhffs_log( sprintf( "Delete files from SVN repository %s" , $svn->get_reponame ), $vhffs);
+		Vhffs::Robots::vhffs_log( sprintf( 'Delete files from SVN repository %s' , $svn->get_reponame ), $vhffs );
 	}
 
 	if( $svn->delete < 0 ) {
-		Vhffs::Robots::vhffs_log( sprintf( "Cannot delete SVN repository object %s" , $svn->get_reponame ), $vhffs);
+		Vhffs::Robots::vhffs_log( sprintf( 'Cannot delete SVN repository object %s' , $svn->get_reponame ), $vhffs );
 	} else {
-		Vhffs::Robots::vhffs_log( sprintf( "Delete SVN repository object %s" , $svn->get_reponame ), $vhffs);
+		Vhffs::Robots::vhffs_log( sprintf( 'Delete SVN repository object %s' , $svn->get_reponame ), $vhffs );
 	}
 }
 
-Vhffs::Robots::unlock( $vhffs , "svn" );
+Vhffs::Robots::unlock( $vhffs , 'svn' );
 exit 0;

Modified: trunk/vhffs-robots/src/svn_public.pl
===================================================================
--- trunk/vhffs-robots/src/svn_public.pl	2009-05-29 06:05:10 UTC (rev 1420)
+++ trunk/vhffs-robots/src/svn_public.pl	2009-05-29 21:59:13 UTC (rev 1421)
@@ -42,44 +42,30 @@
 
 my $vhffs = init Vhffs::Main;
 
-Vhffs::Robots::lock( $vhffs , "svn" );
+Vhffs::Robots::lock( $vhffs , 'svn' );
 
 my $repos = Vhffs::Services::Svn::getall( $vhffs , Vhffs::Constants::WAITING_FOR_MODIFICATION );
-my $svn;
-foreach $svn ( @{$repos} )
+foreach my $svn ( @{$repos} )
 {
-	my $user = $svn->get_user;
-	my $group = $svn->get_group;
-	#First, update uid and gid informations on files
-	if( ( defined $user ) && ( defined $group ) ) {
-			Vhffs::Robots::vhffs_log( sprintf( "SVN change owner/group to %s/%s for repository %s" , $user->get_username , $group->get_groupname , $svn->get_dir ) , $vhffs);
-			Vhffs::Functions::change_owner_recur( $svn->get_dir , $user->get_uid , $group->get_gid );
-
-			Vhffs::Functions::chmod_recur( $svn->get_dir.'/hooks' , 0644 , 0755 );
-			Vhffs::Functions::change_owner_recur( $svn->get_dir.'/hooks' , 0 , 0 );
-	}
-
 	if( $svn->is_public == 1 ) {
-		Vhffs::Robots::vhffs_log( sprintf( "SVN change status %s is now public" , $svn->get_dir ) , $vhffs);
-		Vhffs::Functions::chmod_recur( $svn->get_dir , 0664 , 02775 );
+		chmod 02775 , $svn->get_dir;
+		Vhffs::Robots::vhffs_log( sprintf( 'SVN status %s is now public' , $svn->get_dir ) , $vhffs);
 	} else {
-		Vhffs::Robots::vhffs_log( sprintf( "SVN change status %s is now private" , $svn->get_dir ) , $vhffs);
-		Vhffs::Functions::chmod_recur( $svn->get_dir , 0660 , 02770 );
-		chmod ( 02771 , $svn->get_dir );
-		chmod ( 02771 , $svn->get_dir.'/hooks' );
+		chmod 02770 , $svn->get_dir;
+		Vhffs::Robots::vhffs_log( sprintf( 'SVN status %s is now private' , $svn->get_dir ) , $vhffs);
 	}
 
 	Vhffs::Robots::Svn::change_conf( $svn );
 	$svn->set_status( Vhffs::Constants::ACTIVATED );
 	
 	if( $svn->commit < 0 ) {
-		$svn->add_history( "Error while updating repository configuration");
+		$svn->add_history( 'Error while updating repository configuration' );
 	} else {
-		$svn->add_history( "Successfully modify repository configuration");
+		$svn->add_history( 'Successfully modify repository configuration' );
 	}
 }
 
 
-Vhffs::Robots::unlock( $vhffs , "svn" );
+Vhffs::Robots::unlock( $vhffs , 'svn' );
 
 exit 0;


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