[vhffs-dev] [2055] Reworked downloads repository robots

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


Revision: 2055
Author:   gradator
Date:     2012-02-25 16:04:04 +0100 (Sat, 25 Feb 2012)
Log Message:
-----------
Reworked downloads repository robots

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Robots/Repository.pm
    trunk/vhffs-robots/Makefile.am

Added Paths:
-----------
    trunk/vhffs-robots/src/repository.pl

Removed Paths:
-------------
    trunk/vhffs-robots/src/repository_create.pl
    trunk/vhffs-robots/src/repository_delete.pl

Modified: trunk/vhffs-api/src/Vhffs/Robots/Repository.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Repository.pm	2012-02-25 14:57:09 UTC (rev 2054)
+++ trunk/vhffs-api/src/Vhffs/Robots/Repository.pm	2012-02-25 15:04:04 UTC (rev 2055)
@@ -31,92 +31,92 @@
 
 use strict;
 use utf8;
+use File::Path;
+use File::Basename;
 
-package Vhffs::Robots::Repository;
-
-use Vhffs::Services::Repository;
 use Vhffs::Constants;
 use Vhffs::Functions;
-use Vhffs::Group;
-use File::Path;
+use Vhffs::Robots;
+use Vhffs::Services::Repository;
 
+package Vhffs::Robots::Repository;
 
-sub create_repository
-{
-	my $repo = shift;
+sub create {
+	my $repository = shift;
+	return undef unless defined $repository and $repository->get_status == Vhffs::Constants::WAITING_FOR_CREATION;
 
-	if( defined $repo )
-	{
-		if( create_repositoryondisk( $repo ) > 0 )
-		{
-			$repo->set_status( Vhffs::Constants::ACTIVATED );
-			$repo->commit;
-			$repo->add_history("Download repository is now created !" );
-		}
-		else
-		{
-			$repo->add_history("The bot encounter an error during creation of this download repository, the repository is NOT created !" );
-		}
+	my $vhffs = $repository->get_main;
+	my $dir = $repository->get_dir;
+
+	if( -e $dir ) {
+		$repository->set_status( Vhffs::Constants::CREATION_ERROR );
+		$repository->commit();
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while creating downloads repository '.$repository->get_name.' to the filesystem' );
+		return undef;
 	}
-}
 
+	File::Path::make_path( $dir, { error => \my $errors });
+	if(@$errors) {
+		$repository->set_status( Vhffs::Constants::CREATION_ERROR );
+		$repository->commit;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while creating downloads repository '.$repository->get_name.' to the filesystem: '.join(', ', @$errors) );
+		return undef;
+	}
 
-sub delete_repository
-{
-	my $repo = shift;
+	chown( $repository->get_owner_uid, $repository->get_owner_gid, $dir );
+	chmod( 02775, $dir );
 
-	if( defined $repo )
-	{
-		my $vhffs = $repo->{'main'};
+	unless( Vhffs::Robots::link_to_group( $repository->get_group, $repository->get_name.'-repository', $dir ) ) {
+		$repository->set_status( Vhffs::Constants::CREATION_ERROR );
+		$repository->commit;
+		return undef;
+	}
 
-		Vhffs::Robots::archive_targz( $repo, $repo->get_dir );
+	Vhffs::Robots::vhffs_log( $vhffs, 'Created downloads repository '.$repository->get_name );
+	$repository->set_status( Vhffs::Constants::ACTIVATED );	
+	$repository->commit;
+}
 
-		File::Path::remove_tree( $repo->get_dir, { error => \my $errors });
-		if(@$errors) {
-			Vhffs::Robots::vhffs_log( $vhffs, sprintf( 'Something went wrong during %s download repository deletion: %s', $repo->get_name, join(', ', @$errors) ) );
-		}
+sub delete {
+	my $repository = shift;
+	return undef unless defined $repository and $repository->get_status == Vhffs::Constants::WAITING_FOR_DELETION;
 
-		# remove the link in group directory
-		my $group = Vhffs::Group::get_by_gid( $vhffs , $repo->get_owner_gid );
-		Vhffs::Robots::unlink_from_group( $group, $repo->get_name.'-repository' );
+	my $vhffs = $repository->get_main;
+	my $dir = $repository->get_dir;
 
-		$repo->delete;
+	unless( Vhffs::Robots::unlink_from_group( $repository->get_group, $repository->get_name.'-repository' ) ) {
+		$repository->set_status( Vhffs::Constants::DELETION_ERROR );
+		$repository->commit;
+		return undef;
 	}
-}
 
+	Vhffs::Robots::archive_targz( $repository, $dir );
 
+	File::Path::remove_tree( $dir, { error => \my $errors });
+	if(@$errors) {
+		$repository->set_status( Vhffs::Constants::DELETION_ERROR );
+		$repository->commit;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while removing downloads repository '.$repository->get_name.' from the filesystem: '.join(', ', @$errors) );
+		return undef;
+	}
 
-sub create_repositoryondisk
-{
-	my $repo = shift;
-	return if( ! defined $repo );
-	my $name = $repo->get_name;
-	my $vhffs = $repo->{'main'};
-
-	my $datadir = $vhffs->get_config->get_datadir;
-
-	my $repodir = $repo->get_dir;
-	return -1 if( $repodir =~ /\./ );
-
-	File::Path::make_path( $repodir, { error => \my $errors });
-	return -2 if @$errors;
-
-	chown( $repo->get_owner_uid , $repo->get_owner_gid , $repodir );
-	chmod( 02775 , $repodir );
-
-	my $group = Vhffs::Group::get_by_gid( $vhffs , $repo->get_owner_gid );
-
-	if(Vhffs::Robots::link_to_group( $group, $repo->get_name.'-repository', $repodir ) < 0) {
-		$repo->add_history( "Can't link the download repository to the specified group");
-		return -3;
+	if( $repository->delete ) {
+		Vhffs::Robots::vhffs_log( $vhffs, 'Deleted downloads repository '.$repository->get_name );
+	} else {
+		$repository->set_status( Vhffs::Constants::DELETION_ERROR );
+		$repository->commit;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while deleting downloads repository '.$repository->get_name.' object' );
+		return undef;
 	}
-	else
-	{
-		$repo->add_history( "OK, download repository is now linked with the group");
-	}
 
 	return 1;
 }
 
+sub modify {
+	my $repository = shift;
+	return undef unless defined $repository and $repository->get_status == Vhffs::Constants::WAITING_FOR_MODIFICATION;
+	$repository->set_status( Vhffs::Constants::ACTIVATED );
+	$repository->commit;
+}
+
 1;
-

Modified: trunk/vhffs-robots/Makefile.am
===================================================================
--- trunk/vhffs-robots/Makefile.am	2012-02-25 14:57:09 UTC (rev 2054)
+++ trunk/vhffs-robots/Makefile.am	2012-02-25 15:04:04 UTC (rev 2055)
@@ -42,8 +42,7 @@
 	src/pgsql_delete.pl \
 	src/pgsql_dump.pl \
 	src/pgsql_modify.pl \
-	src/repository_create.pl \
-	src/repository_delete.pl \
+	src/repository.pl \
 	src/repository_quota.pl \
 	src/repository_stats.pl \
 	src/cvs.pl \

Copied: trunk/vhffs-robots/src/repository.pl (from rev 2052, trunk/vhffs-robots/src/repository_create.pl)
===================================================================
--- trunk/vhffs-robots/src/repository.pl	                        (rev 0)
+++ trunk/vhffs-robots/src/repository.pl	2012-02-25 15:04:04 UTC (rev 2055)
@@ -0,0 +1,61 @@
+#!%PERL%
+
+
+# Copyright (c) vhffs project and its contributors
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without 
+# modification, are permitted provided that the following conditions 
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright 
+#   notice, this list of conditions and the following disclaimer.
+#2. Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in 
+#   the documentation and/or other materials provided with the 
+#   distribution.
+#3. Neither the name of vhffs nor the names of its contributors 
+#   may be used to endorse or promote products derived from this 
+#   software without specific prior written permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
+#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
+#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+# POSSIBILITY OF SUCH DAMAGE.
+
+use strict;
+use utf8;
+
+use lib '%VHFFS_LIB_DIR%';
+use Vhffs::Robots::Repository;
+
+my $vhffs = init Vhffs::Main;
+exit 1 unless defined $vhffs;
+
+Vhffs::Robots::lock( $vhffs, 'repository' );
+
+my $repos = Vhffs::Services::Repository::getall( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
+foreach ( @{$repos} ) {
+	Vhffs::Robots::Repository::create( $_ );
+}
+
+$repos = Vhffs::Services::Repository::getall( $vhffs, Vhffs::Constants::WAITING_FOR_DELETION );
+foreach ( @{$repos} ) {
+	Vhffs::Robots::Repository::delete( $_ );
+}
+
+$repos = Vhffs::Services::Repository::getall( $vhffs, Vhffs::Constants::WAITING_FOR_MODIFICATION );
+foreach ( @{$repos} ) {
+	Vhffs::Robots::Repository::modify( $_ );
+}
+
+Vhffs::Robots::unlock( $vhffs, 'repository' );
+exit 0;

Deleted: trunk/vhffs-robots/src/repository_create.pl
===================================================================
--- trunk/vhffs-robots/src/repository_create.pl	2012-02-25 14:57:09 UTC (rev 2054)
+++ trunk/vhffs-robots/src/repository_create.pl	2012-02-25 15:04:04 UTC (rev 2055)
@@ -1,63 +0,0 @@
-#!%PERL%
-
-
-# Copyright (c) vhffs project and its contributors
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without 
-# modification, are permitted provided that the following conditions 
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright 
-#   notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in 
-#   the documentation and/or other materials provided with the 
-#   distribution.
-#3. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
-# POSSIBILITY OF SUCH DAMAGE.
-
-use strict;
-use utf8;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Robots::Repository;
-use Vhffs::Robots;
-use Vhffs::Main;
-
-my $vhffs = init Vhffs::Main;
-
-Vhffs::Robots::lock( $vhffs , "repository" );
-
-my $repos = Vhffs::Services::Repository::getall( $vhffs , Vhffs::Constants::WAITING_FOR_CREATION , undef , undef  );
-my $repo;
-
-foreach $repo ( @{$repos} )
-{
-		if( Vhffs::Robots::Repository::create_repository( $repo ) > 0 )
-		{
-			Vhffs::Robots::vhffs_log( $vhffs, sprintf( "REPOSITORY: Download repository %s is created" , $repo->get_name ) );
-		}
-		else
-		{
-			Vhffs::Robots::vhffs_log( $vhffs, sprintf( "REPOSITORY: Cannot create download repository %s" , $repo->get_name ) );
-		}
-}
-
-Vhffs::Robots::unlock( $vhffs , "repository" );
-
-exit 0;

Deleted: trunk/vhffs-robots/src/repository_delete.pl
===================================================================
--- trunk/vhffs-robots/src/repository_delete.pl	2012-02-25 14:57:09 UTC (rev 2054)
+++ trunk/vhffs-robots/src/repository_delete.pl	2012-02-25 15:04:04 UTC (rev 2055)
@@ -1,77 +0,0 @@
-#!%PERL%
-# Copyright (c) vhffs project and its contributors
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without 
-# modification, are permitted provided that the following conditions 
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright 
-#   notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in 
-#   the documentation and/or other materials provided with the 
-#   distribution.
-#3. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
-# POSSIBILITY OF SUCH DAMAGE.
-
-use strict;
-use utf8;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Robots::Repository;
-use Vhffs::Services::Repository;
-use Vhffs::Constants;
-use Vhffs::Robots;
-use Vhffs::Main;
-
-
-my $vhffs = init Vhffs::Main;
-
-Vhffs::Robots::lock( $vhffs , "repository" );
-
-my $repos = Vhffs::Services::Repository::getall( $vhffs , Vhffs::Constants::WAITING_FOR_DELETION );
-my $repo;
-
-foreach $repo ( @{$repos} )
-{
-    if( defined $repo )
-    {
-        if( Vhffs::Robots::Repository::delete_repository( $repo ) > 0 )
-		{
-			Vhffs::Robots::vhffs_log( $vhffs, sprintf( "Delete files from %s", $repo->get_name ));
-		}
-		else
-		{
-			Vhffs::Robots::vhffs_log( $vhffs, sprintf( "Cannot delete files from %s", $repo->get_name ));
-		}
-		
-		if( $repo->delete > 0 )
-		{
-			Vhffs::Robots::vhffs_log( $vhffs, sprintf( "Deleted download repository object %s", $repo->get_name ));
-		}
-		else
-		{
-			Vhffs::Robots::vhffs_log( $vhffs, sprintf( "Cannot delete download repository object %s", $repo->get_name ));
-		}
-    }
-}
-
-
-Vhffs::Robots::unlock( $vhffs , "repository" );
-
-exit 0;


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