=================================================================== RCS file: /cvs/wpscripts/ztransfer/send.pm,v retrieving revision 1.2 retrieving revision 1.8 diff -u -r1.2 -r1.8 --- wpscripts/ztransfer/send.pm 2011/06/03 11:03:41 1.2 +++ wpscripts/ztransfer/send.pm 2012/04/01 06:52:10 1.8 @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: send.pm,v 1.2 2011/06/03 11:03:41 yason Exp $ +# $Id: send.pm,v 1.8 2012/04/01 06:52:10 yason Exp $ package send; use fetch; use db; @@ -10,6 +10,9 @@ # spool path constants (without leading slash) our $SPOOL_ZAYAVKI = "/mnt/archive/archive/wp/zayavki"; our $SPOOL_PROBAS = "/mnt/archive/archive/wp/proba"; +our $SPOOL_TT = "/mnt/archive/archive/wp/tt"; +our $SPOOL_ZJPEG = "/mnt/archive/archive/wp/zjpeg"; +our $SPOOL_PJPEG = "/mnt/archive/archive/wp/pjpeg"; our $SPOOL_TMPDIR = "/mnt/archive/archive/temp"; # temp variables for map table lookup @@ -85,21 +88,16 @@ else { # hardcoded - # how maket/rmt_maket could be used there? - $remotepaths[$i] =~ s/V(1)/zV7/; - $remotepaths[$i] =~ s/V(2)/zV8/; - $remotepaths[$i] =~ s/V(3)/zV6/; - $remotepaths[$i] =~ s/V(4)/zV7/; - $remotepaths[$i] =~ s/V(5)/zV7/; + $remotepaths[$i] =~ s/\/mnt\/maket/\/mnt\/rmt_maket/; } - if(-e $remotepaths[$i] || -e $remotepaths[$i] . '.rar') - { - log::error("Remote file $remotepaths[$i] or $remotepaths[$i].rar already exists"); - db::change_status($dbids[$i], 1); - } - else - { +# if(-e $remotepaths[$i] || -e $remotepaths[$i] . '.rar') +# { +# log::error("Remote file $remotepaths[$i] or $remotepaths[$i].rar already exists"); +# db::change_status($dbids[$i], 1); +# } +# else +# { # In this place we must be sure that local file is ok if( -e $localpaths[$i] ) { @@ -115,7 +113,7 @@ log::zayavki("compressing '$localpaths[$i]' -> '$spool/$curfile'"); - `/usr/local/bin/rar a -rr10% -ep '$spool/$curfile' '$localpaths[$i]'`; + `/usr/bin/rar a -rr10% -ep '$spool/$curfile' '$localpaths[$i]'`; if( ($? >> 8) == 0) { # rar exited successfully @@ -209,7 +207,7 @@ log::zayavki("Can not open local file $localpaths[$i]"); } - } +# } # next iteration of 'while' and increment of $i $i++; @@ -224,101 +222,6 @@ -sub jpegs() -{ - my @dbids; - my @localpaths; - my @remotepaths; - my $dbids_ref; - my $localpaths_ref; - my $i = 0; - my $okay = 0; - - my $size_orig; - - ($dbids_ref, $localpaths_ref) = fetch::jpegs_list(); - - @dbids = @$dbids_ref; - @localpaths = @$localpaths_ref; - log::main("Fetched " . scalar(@localpaths) . " jpegs from database"); - log::jpegs("<< Starting transfer process >>"); - - @remotepaths = @localpaths; # clone - - while($localpaths[$i]) - { - # lookup in table first - chomp( $tmpf = `basename $remotepaths[$i]` ); - chomp( $_ = `dirname $remotepaths[$i]` ); - $tmpd = hash::lookup($_); - if ( $tmpd ne '' ) - { - $remotepaths[$i] = $tmpd. "/". $tmpf; - } - else - { - # hardcoded - $remotepaths[$i] =~ s/V(1)/zV7/; - $remotepaths[$i] =~ s/V(2)/zV8/; - $remotepaths[$i] =~ s/V(3)/zV6/; - $remotepaths[$i] =~ s/V(4)/zV7/; - $remotepaths[$i] =~ s/V(5)/zV7/; - } - - if(-e $remotepaths[$i]) - { - log::error("Remote file $remotefile[$i] already exists"); - db::change_status($dbids[$i], 1); - } - else - { - if( -e $localpaths[$i] ) - { - fileops::checkdir($remotepaths[$i]); - # set $size_orig - $size_orig = -s "$localpaths[$i]"; - - log::jpegs("transferring $localpaths[$i] -> $remotepaths[$i]"); - if( system("cp '$localpaths[$i]' '$remotepaths[$i]'") == 0 ) - { - log::jpegs("saved $localpaths[$i] -> $remotepaths[$i] [size_orig=$size_orig]"); - # update database - db::change_status($dbids[$i], 1); - db::write_size_orig($dbids[$i], $size_orig); - - # - # WE SHOULD NOT FILL ux_rpath FIELD FOR jpeg-types - # - # db::write_ux_rpath($dbids[$i], "$remotepaths[$i]"); - - $okay++; - - } - else - { - # error in the copy process - log::jpegs("error in copy process (see error log)"); - log::error("error in copy process: $?"); - } - } - else - { - # error, local file doesn't exists - log::error("Can not open local file $localpaths[$i]"); - log::jpegs("Can not open local file $localpaths[$i]"); - } - } - - # next iteration of 'while' and increment of $i - $i++; - } - - log::main("Saved $okay jpegs on remote host"); - log::jpegs("<< End transfer process >>"); -} - - - sub probas() { my @dbids; @@ -386,8 +289,9 @@ } else { - # /V5/probas/* goes on /zV7/probas/ - substr($remotepaths[$i], 1, 2, 'zV7'); + # /mnt/maket/proba/* goes on /mnt/rmt_maket/proba/ +# substr($remotepaths[$i], 1, 2, 'mnt/rmt_maket'); + $remotepaths[$i] =~ s/\/mnt\/maket/\/mnt\/rmt_maket/; } if(-e $remotepaths[$i] || -e $remotepaths[$i] . '.rar') @@ -412,7 +316,7 @@ log::probas("compressing '$localpaths[$i]' -> '$spool/$curfile'"); - `/usr/local/bin/rar a -rr10% -ep '$spool/$curfile' '$localpaths[$i]'`; + `/usr/bin/rar a -rr10% -ep '$spool/$curfile' '$localpaths[$i]'`; if( ($? >> 8) == 0) { # rar exited successfully @@ -502,101 +406,266 @@ log::probas("<< End transfer process >>"); } -sub tpps() -{ - my @dbids; - my @localpaths; - my @remotepaths; - my $dbids_ref; - my $localpaths_ref; - my $i = 0; - my $okay = 0; +sub tt() + { + my @dbids; + my @localpaths; + my @remotepaths; + my $dbids_ref; + my $localpaths_ref; + my $i = 0; + my $okay = 0; - my $size_orig; + my $size_orig; - ($dbids_ref, $localpaths_ref) = fetch::tpps_list(); - - @dbids = @$dbids_ref; - @localpaths = @$localpaths_ref; - log::main("Fetched " . scalar(@localpaths) . " tpps from database"); - log::tpps("<< Starting transfer process >>"); + ($dbids_ref, $localpaths_ref) = fetch::tt_list(); - @remotepaths = @localpaths; # clone + @dbids = @$dbids_ref; + @localpaths = @$localpaths_ref; + log::main("Fetched " . scalar(@localpaths) . " tt from database"); + log::tt("<< Starting transfer process >>"); + + @remotepaths = @localpaths; # clone + + while($localpaths[$i]) + { + # lookup in table first + chomp( $tmpf = `basename $remotepaths[$i]` ); + chomp( $_ = `dirname $remotepaths[$i]` ); + $tmpd = hash::lookup($_); + if ( $tmpd ne '' ) + { + $remotepaths[$i] = $tmpd. "/". $tmpf; + } + else + { + # hardcoded + $remotepaths[$i] =~ s/\/mnt\/maket/\/mnt\/rmt_maket/; + } + + if(-e $remotepaths[$i]) + { + log::error("Remote file $remotefile[$i] already exists"); + db::change_status($dbids[$i], 1); + } + else + { + if( -e $localpaths[$i] ) + { + fileops::checkdir($remotepaths[$i]); + # set $size_orig + $size_orig = -s "$localpaths[$i]"; + + log::tt("transferring $localpaths[$i] -> $remotepaths[$i]"); + if( system("cp '$localpaths[$i]' '$remotepaths[$i]'") == 0 ) + { + log::tt("saved $localpaths[$i] -> $remotepaths[$i] [size_orig=$size_orig]"); + # update database + db::change_status($dbids[$i], 1); + db::write_size_orig($dbids[$i], $size_orig); + + # + # WE SHOULD NOT FILL ux_rpath FIELD FOR tpp-types + # + # XXX Please explain me why? + # + # db::write_ux_rpath($dbids[$i], "$remotepaths[$i]"); + + $okay++; + + } + else + { + # error in the copy process + log::tt("error in copy process (see error log)"); + log::error("error in copy process: $?"); + } + } + else + { + # error, local file doesn't exists + log::error("Can not open local file $localpaths[$i]"); + log::tt("Can not open local file $localpaths[$i]"); + } + } + + # next iteration of 'while' and increment of $i + $i++; + } + + log::main("Saved $okay tt on remote host"); + log::tt("<< End transfer process >>"); + } - while($localpaths[$i]) - { - # lookup in table first - chomp( $tmpf = `basename $remotepaths[$i]` ); - chomp( $_ = `dirname $remotepaths[$i]` ); - $tmpd = hash::lookup($_); - if ( $tmpd ne '' ) - { - $remotepaths[$i] = $tmpd. "/". $tmpf; - } - else - { - # hardcoded - $remotepaths[$i] =~ s/V(1)/zV7/; - $remotepaths[$i] =~ s/V(2)/zV8/; - $remotepaths[$i] =~ s/V(3)/zV6/; - $remotepaths[$i] =~ s/V(4)/zV7/; - $remotepaths[$i] =~ s/V(5)/zV7/; - } - if(-e $remotepaths[$i]) - { - log::error("Remote file $remotefile[$i] already exists"); - db::change_status($dbids[$i], 1); - } - else - { - if( -e $localpaths[$i] ) - { - fileops::checkdir($remotepaths[$i]); - # set $size_orig - $size_orig = -s "$localpaths[$i]"; - - log::tpps("transferring $localpaths[$i] -> $remotepaths[$i]"); - if( system("cp '$localpaths[$i]' '$remotepaths[$i]'") == 0 ) - { - log::tpps("saved $localpaths[$i] -> $remotepaths[$i] [size_orig=$size_orig]"); - # update database - db::change_status($dbids[$i], 1); - db::write_size_orig($dbids[$i], $size_orig); - - # - # WE SHOULD NOT FILL ux_rpath FIELD FOR tpp-types - # - # XXX Please explain me why? - # - # db::write_ux_rpath($dbids[$i], "$remotepaths[$i]"); +sub zjpeg() + { + my @dbids; + my @localpaths; + my @remotepaths; + my $dbids_ref; + my $localpaths_ref; + my $i = 0; + my $okay = 0; - $okay++; - - } - else - { - # error in the copy process - log::tpps("error in copy process (see error log)"); - log::error("error in copy process: $?"); - } - } - else - { - # error, local file doesn't exists - log::error("Can not open local file $localpaths[$i]"); - log::tpps("Can not open local file $localpaths[$i]"); - } - } - - # next iteration of 'while' and increment of $i - $i++; - } - - log::main("Saved $okay tpps on remote host"); - log::tpps("<< End transfer process >>"); -} + my $size_orig; + ($dbids_ref, $localpaths_ref) = fetch::zjpeg_list(); + @dbids = @$dbids_ref; + @localpaths = @$localpaths_ref; + log::main("Fetched " . scalar(@localpaths) . " zjpeg from database"); + log::zjpeg("<< Starting transfer process >>"); + + @remotepaths = @localpaths; # clone + + while($localpaths[$i]) + { + # lookup in table first + chomp( $tmpf = `basename $remotepaths[$i]` ); + chomp( $_ = `dirname $remotepaths[$i]` ); + $tmpd = hash::lookup($_); + if ( $tmpd ne '' ) + { + $remotepaths[$i] = $tmpd. "/". $tmpf; + } + else + { + # hardcoded + $remotepaths[$i] =~ s/\/mnt\/maket/\/mnt\/rmt_maket/; + } + + if(-e $remotepaths[$i]) + { + log::error("Remote file $remotefile[$i] already exists"); + db::change_status($dbids[$i], 1); + } + else + { + if( -e $localpaths[$i] ) + { + fileops::checkdir($remotepaths[$i]); + # set $size_orig + $size_orig = -s "$localpaths[$i]"; + + log::zjpeg("transferring $localpaths[$i] -> $remotepaths[$i]"); + if( system("cp '$localpaths[$i]' '$remotepaths[$i]'") == 0 ) + { + log::zjpeg("saved $localpaths[$i] -> $remotepaths[$i] [size_orig=$size_orig]"); + # update database + db::change_status($dbids[$i], 1); + db::write_size_orig($dbids[$i], $size_orig); + + + $okay++; + + } + else + { + # error in the copy process + log::zjpeg("error in copy process (see error log)"); + log::error("error in copy process: $?"); + } + } + else + { + # error, local file doesn't exists + log::error("Can not open local file $localpaths[$i]"); + log::zjpeg("Can not open local file $localpaths[$i]"); + } + } + + # next iteration of 'while' and increment of $i + $i++; + } + + log::main("Saved $okay zjpeg on remote host"); + log::zjpeg("<< End transfer process >>"); + } + +sub pjpeg() + { + my @dbids; + my @localpaths; + my @remotepaths; + my $dbids_ref; + my $localpaths_ref; + my $i = 0; + my $okay = 0; + + my $size_orig; + + ($dbids_ref, $localpaths_ref) = fetch::pjpeg_list(); + + @dbids = @$dbids_ref; + @localpaths = @$localpaths_ref; + log::main("Fetched " . scalar(@localpaths) . " pjpeg from database"); + log::pjpeg("<< Starting transfer process >>"); + + @remotepaths = @localpaths; # clone + + while($localpaths[$i]) + { + # lookup in table first + chomp( $tmpf = `basename $remotepaths[$i]` ); + chomp( $_ = `dirname $remotepaths[$i]` ); + $tmpd = hash::lookup($_); + if ( $tmpd ne '' ) + { + $remotepaths[$i] = $tmpd. "/". $tmpf; + } + else + { + # hardcoded + $remotepaths[$i] =~ s/\/mnt\/maket/\/mnt\/rmt_maket/; + } + + if(-e $remotepaths[$i]) + { + log::error("Remote file $remotefile[$i] already exists"); + db::change_status($dbids[$i], 1); + } + else + { + if( -e $localpaths[$i] ) + { + fileops::checkdir($remotepaths[$i]); + # set $size_orig + $size_orig = -s "$localpaths[$i]"; + + log::pjpeg("transferring $localpaths[$i] -> $remotepaths[$i]"); + if( system("cp '$localpaths[$i]' '$remotepaths[$i]'") == 0 ) + { + log::pjpeg("saved $localpaths[$i] -> $remotepaths[$i] [size_orig=$size_orig]"); + # update database + db::change_status($dbids[$i], 1); + db::write_size_orig($dbids[$i], $size_orig); + + + $okay++; + + } + else + { + # error in the copy process + log::pjpeg("error in copy process (see error log)"); + log::error("error in copy process: $?"); + } + } + else + { + # error, local file doesn't exists + log::error("Can not open local file $localpaths[$i]"); + log::pjpeg("Can not open local file $localpaths[$i]"); + } + } + + # next iteration of 'while' and increment of $i + $i++; + } + + log::main("Saved $okay pjpeg on remote host"); + log::pjpeg("<< End transfer process >>"); + } return(1);