From 5290ad264eef743569029cd45b05a2d9698f6984 Mon Sep 17 00:00:00 2001 From: Flavio Poletti Date: Wed, 3 Dec 2014 13:31:12 +0100 Subject: [PATCH] perltidy --- deployable | 108 ++++++++++++++++++++++++------------------------ remote | 137 +++++++++++++++++++++++++++++++------------------------------ 2 files changed, 125 insertions(+), 120 deletions(-) diff --git a/deployable b/deployable index 0b2c3e1..4cfa215 100755 --- a/deployable +++ b/deployable @@ -18,14 +18,14 @@ use Data::Dumper; use Encode; my %config = ( - output => '-', - remote => catfile(dirname(realpath(__FILE__)), 'remote'), - tarfile => [], - heredir => [], - rootdir => [], - root => [], - tarfile => [], - deploy => [], + output => '-', + remote => catfile(dirname(realpath(__FILE__)), 'remote'), + tarfile => [], + heredir => [], + rootdir => [], + root => [], + tarfile => [], + deploy => [], passthrough => 0, ); GetOptions( @@ -72,8 +72,8 @@ if ($config{'include-archive-tar'}) { chdir dirname realpath __FILE__; system {'make'} qw( make remote-at ); chdir $startdir; - } ## end if (!-e $config{remote... -} ## end if ($config{'include-archive-tar'... + } ## end if (!-e $config{remote...}) +} ## end if ($config{'include-archive-tar'...}) # Establish output channel my $out_fh = \*STDOUT; @@ -111,28 +111,31 @@ sub header { sub print_configuration { # FIXME my ($fh, $config) = @_; my %general_configuration; - for my $name (qw( workdir cleanup bundle deploy - gzip bzip2 passthrough tempdir-mode )) { + for my $name ( + qw( workdir cleanup bundle deploy + gzip bzip2 passthrough tempdir-mode ) + ) + { $general_configuration{$name} = $config->{$name} if exists $config->{$name}; - } + } ## end for my $name (qw( workdir cleanup bundle deploy...)) my $configuration = Dumper \%general_configuration; print {$fh} header(name => 'config.pl', size => length($configuration)), - "\n", $configuration, "\n\n"; -} ## end sub freeze_configuration + "\n", $configuration, "\n\n"; +} ## end sub print_configuration # Process files and directories. All these will be reported in the # extraction directory, i.e. basename() will be applied to them. For # directories, they will be re-created sub print_here_stuff { - my $fh = shift; + my $fh = shift; my $config = shift; - my @ARGV = @_; + my @ARGV = @_; my $ai = Deployable::Tar->new($config); $ai->add( '.' => \@ARGV, - map { $_ => [ '.' ] } @{$config->{heredir}} + map { $_ => ['.'] } @{$config->{heredir}} ); print {$fh} header(name => 'here', size => $ai->size()), "\n"; @@ -140,7 +143,7 @@ sub print_here_stuff { print {$fh} "\n\n"; return; -} ## end sub get_here_tar +} ## end sub print_here_stuff sub print_root_stuff { my ($fh, $config) = @_; @@ -149,7 +152,7 @@ sub print_root_stuff { $ai->add( '.' => $config->{rootdir}, (undef, $config->{tarfile}), - map { $_ => [ '.' ] } @{$config->{root}} + map { $_ => ['.'] } @{$config->{root}} ); print {$fh} header(name => 'root', size => $ai->size()), "\n"; @@ -157,7 +160,7 @@ sub print_root_stuff { print {$fh} "\n\n"; return; -} ## end sub get_root_tar +} ## end sub print_root_stuff sub get_remote_script { open my $fh, '<', $config{remote} @@ -175,19 +178,18 @@ package Deployable::Tar; sub new { my $package = shift; - my $self = { ref $_[0] ? %{$_[0]} : @_ }; + my $self = {ref $_[0] ? %{$_[0]} : @_}; $package = 'Deployable::Tar::Internal'; - if (! $self->{'no-tar'}) { + if (!$self->{'no-tar'}) { if ((exists $self->{tar}) || (open my $fh, '-|', 'tar', '--help')) { $package = 'Deployable::Tar::External'; $self->{tar} ||= 'tar'; - } - } + } + } ## end if (!$self->{'no-tar'}) bless $self, $package; $self->initialise(); return $self; -} - +} ## end sub new package Deployable::Tar::External; use File::Temp qw( :seekable ); @@ -198,14 +200,14 @@ our @ISA = qw( Deployable::Tar ); sub initialise { my $self = shift; - $self->{_temp} = File::Temp->new(); + $self->{_temp} = File::Temp->new(); $self->{_filename} = Cwd::abs_path($self->{_temp}->filename()); return $self; -} +} ## end sub initialise sub add { my $self = shift; - my $tar = $self->{tar}; + my $tar = $self->{tar}; delete $self->{_compressed}; while (@_) { my ($directory, $stuff) = splice @_, 0, 2; @@ -214,19 +216,18 @@ sub add { while (@stuff) { my @chunk = splice @stuff, 0, 50; system {$tar} $tar, 'rvf', $self->{_filename}, - '-C', $directory, '--', @chunk; + '-C', $directory, '--', @chunk; } - } - else { # it's another TAR file, concatenate + } ## end if (defined $directory) + else { # it's another TAR file, concatenate while (@stuff) { my @chunk = splice @stuff, 0, 50; - system {$tar} $tar, 'Avf', $self->{_filename}, - '--', @chunk; + system {$tar} $tar, 'Avf', $self->{_filename}, '--', @chunk; } - } - } + } ## end else [ if (defined $directory)] + } ## end while (@_) return $self; -} +} ## end sub add sub _compress { my $self = shift; @@ -240,7 +241,7 @@ sub _compress { # double-quotes needed to force usage of filename # instead of filehandle IO::Compress::Bzip2::bzip2($self->{_temp}, "$self->{_compressed}"); - } + } ## end if ($self->{bzip2}) elsif ($self->{gzip}) { require IO::Compress::Gzip; $self->{_compressed} = File::Temp->new(); @@ -248,13 +249,13 @@ sub _compress { # double-quotes needed to force usage of filename # instead of filehandle IO::Compress::Gzip::gzip($self->{_temp}, "$self->{_compressed}"); - } + } ## end elsif ($self->{gzip}) else { $self->{_compressed} = $self->{_temp}; } return $self; -} +} ## end sub _compress sub size { my ($self) = @_; @@ -272,14 +273,13 @@ sub copy_to { croak "sysread(): $OS_ERROR" unless defined $nread; last unless $nread; print {$out_fh} $buffer; - } + } ## end while ('true') return $self; -} - +} ## end sub copy_to package Deployable::Tar::Internal; -use Archive::Tar (); -use Cwd (); +use Archive::Tar (); +use Cwd (); use File::Find::Rule (); use Carp qw< croak >; our @ISA = qw( Deployable::Tar ); @@ -303,25 +303,27 @@ sub add { $tar->add_files($_) for File::Find::Rule->in($item); } chdir $cwd; - } + } ## end if (defined $directory) else { croak 'unsupported TAR files concatenation with internal'; } - } + } ## end while (@_) return $self; -} +} ## end sub add sub size { my ($self) = @_; - $self->{_string} = $self->{_tar}->write() unless exists $self->{_string}; + $self->{_string} = $self->{_tar}->write() + unless exists $self->{_string}; return length $self->{_string}; -} +} ## end sub size sub copy_to { my ($self, $out_fh) = @_; - $self->{_string} = $self->{_tar}->write() unless exists $self->{_string}; + $self->{_string} = $self->{_tar}->write() + unless exists $self->{_string}; print {$out_fh} $self->{_string}; -} +} ## end sub copy_to __END__ diff --git a/remote b/remote index 4bef8a6..50b1327 100755 --- a/remote +++ b/remote @@ -25,37 +25,37 @@ my %default_config = ( # default values verbose => 0, ); -my $DATA_POSITION = tell DATA; # GLOBAL VARIABLE +my $DATA_POSITION = tell DATA; # GLOBAL VARIABLE my %script_config = (%default_config, get_config()); my %config = %script_config; -if ($ENV{DEPLOYABLE_DISABLE_PASSTHROUGH} || (! $config{passthrough})) { +if ($ENV{DEPLOYABLE_DISABLE_PASSTHROUGH} || (!$config{passthrough})) { my %cmdline_config; GetOptions( \%cmdline_config, qw( - usage|help|man! - version! - - bundle|all-exec|X! - cleanup|c! - dryrun|dry-run|n! - filelist|list|l! - heretar|here-tar|H! - inspect|i=s - no-exec! - no-tar! - roottar|root-tar|R! - show|show-options|s! - tar|t=s - tempdir! - tempdir-mode|m=s - verbose! - workdir|work-directory|deploy-directory|w=s - ), + usage|help|man! + version! + + bundle|all-exec|X! + cleanup|c! + dryrun|dry-run|n! + filelist|list|l! + heretar|here-tar|H! + inspect|i=s + no-exec! + no-tar! + roottar|root-tar|R! + show|show-options|s! + tar|t=s + tempdir! + tempdir-mode|m=s + verbose! + workdir|work-directory|deploy-directory|w=s + ), ) or short_usage(); %config = (%config, %cmdline_config); -} +} ## end if ($ENV{DEPLOYABLE_DISABLE_PASSTHROUGH...}) usage() if $config{usage}; version() if $config{version}; @@ -107,18 +107,21 @@ if ($config{filelist}) { mkpath($config{workdir}); chdir($config{workdir}); print {*STDERR} "### Got into working directory '$config{workdir}'\n\n" - if $config{verbose}; + if $config{verbose}; my $tempdir; if ($config{'tempdir'}) { # Only if allowed my $me = basename(__FILE__) || 'deploy'; my $now = strftime('%Y-%m-%d_%H-%M-%S', localtime); - $tempdir = tempdir(join('-', $me, $now, ('X' x 10)), - DIR => '.', CLEANUP => $config{cleanup}); + $tempdir = tempdir( + join('-', $me, $now, ('X' x 10)), + DIR => '.', + CLEANUP => $config{cleanup} + ); if ($config{'tempdir-mode'}) { chmod oct($config{'tempdir-mode'}), $tempdir - or die "chmod('$tempdir'): $OS_ERROR\n"; + or die "chmod('$tempdir'): $OS_ERROR\n"; } chdir $tempdir @@ -129,10 +132,10 @@ if ($config{'tempdir'}) { # Only if allowed "### Created and got into temporary directory '$tempdir'\n"; print {*STDERR} "### (will clean it up later)\n" if $config{cleanup}; print {*STDERR} "\n"; - } + } ## end if ($config{verbose}) } ## end if ($config{'tempdir'}) -eval { # Not really needed, but you know... +eval { # Not really needed, but you know... $ENV{PATH} = '/bin:/usr/bin:/sbin:/usr/sbin'; save_files(); execute_deploy_programs() unless $config{'no-exec'}; @@ -142,21 +145,20 @@ warn "$EVAL_ERROR\n" if $EVAL_ERROR; # Get back so that cleanup can successfully happen, if requested chdir '..' if defined $tempdir; - sub locate_file { my ($filename) = @_; my $fh = \*DATA; seek $fh, $DATA_POSITION, SEEK_SET; - while (! eof $fh) { + while (!eof $fh) { chomp(my $sizes = <$fh>); my ($name_size, $file_size) = split /\s+/, $sizes; my $name = full_read($fh, $name_size); - full_read($fh, 1); # "\n" + full_read($fh, 1); # "\n" return ($fh, $file_size) if $name eq $filename; - seek $fh, $file_size + 2, SEEK_CUR; # includes "\n\n" - } + seek $fh, $file_size + 2, SEEK_CUR; # includes "\n\n" + } ## end while (!eof $fh) die "could not find '$filename'"; -} +} ## end sub locate_file sub full_read { my ($fh, $size) = @_; @@ -168,9 +170,9 @@ sub full_read { die "unexpected end of file" unless $nread; $retval .= $buffer; $size -= $nread; - } + } ## end while ($size) return $retval; -} +} ## end sub full_read sub copy { my ($ifh, $ofh, $size) = @_; @@ -181,15 +183,15 @@ sub copy { die "unexpected end of file" unless $nread; print {$ofh} $buffer; $size -= $nread; - } + } ## end while ($size) return; -} +} ## end sub copy sub get_sub_tar { my ($filename) = @_; my ($fh, $size) = locate_file($filename); return Deployable::Tar->new(%config, fh => $fh, size => $size); -} ## end sub get_sub_tar +} sub get_config { my ($fh, $size) = locate_file('config.pl'); @@ -219,7 +221,7 @@ sub execute_deploy_programs { if ($config{bundle}) { # add all executable scripts in current directory print {*STDERR} "### Auto-deploying all executables in main dir\n\n" - if $config{verbose}; + if $config{verbose}; my %flag_for = map { $_ => 1 } @deploy_programs; opendir my $dh, '.'; for my $item (sort readdir $dh) { @@ -227,7 +229,7 @@ sub execute_deploy_programs { next unless ((-f $item) || (-l $item)) && (-x $item); $flag_for{$item} = 1; push @deploy_programs, $item; - } ## end for my $item (sort readdir... + } ## end for my $item (sort readdir...) closedir $dh; } ## end if ($config{bundle}) @@ -237,15 +239,15 @@ sub execute_deploy_programs { unless file_name_is_absolute($deploy); if (!-x $deploy) { print {*STDERR} "### Skipping '$deploy', not executable\n\n" - if $config{verbose}; + if $config{verbose}; next DEPLOY; } - print {*STDERR} "### Executing '$deploy'...\n" - if $config{verbose}; + print {*STDERR} "### Executing '$deploy'...\n" + if $config{verbose}; system {$deploy} $deploy, @ARGV; - print {*STDERR} "\n" - if $config{verbose}; - } ## end for my $deploy (@deploy_programs) + print {*STDERR} "\n" + if $config{verbose}; + } ## end DEPLOY: for my $deploy (@deploy_programs) return; } ## end sub execute_deploy_programs @@ -259,7 +261,7 @@ $progname version $VERSION - for help on calling and options, run: $0 --usage END_OF_USAGE exit 1; -} +} ## end sub short_usage sub usage { my $progname = basename($0); @@ -339,55 +341,55 @@ sub version { exit 1; } - package Deployable::Tar; sub new { my $package = shift; - my $self = { ref $_[0] ? %{$_[0]} : @_ }; + my $self = {ref $_[0] ? %{$_[0]} : @_}; $package = 'Deployable::Tar::Internal'; - if (! $self->{'no-tar'}) { + if (!$self->{'no-tar'}) { if ((exists $self->{tar}) || (open my $fh, '-|', 'tar', '--help')) { $package = 'Deployable::Tar::External'; $self->{tar} ||= 'tar'; } - } + } ## end if (!$self->{'no-tar'}) bless $self, $package; $self->initialise() if $self->can('initialise'); return $self; -} +} ## end sub new package Deployable::Tar::External; use English qw( -no_match_vars ); sub initialise { my $self = shift; - my $compression = $self->{bzip2} ? 'j' - : $self->{gzip} ? 'z' - : ''; - $self->{_list_command} = 'tv' . $compression . 'f'; + my $compression = + $self->{bzip2} ? 'j' + : $self->{gzip} ? 'z' + : ''; + $self->{_list_command} = 'tv' . $compression . 'f'; $self->{_extract_command} = 'x' . $compression . 'f'; -} +} ## end sub initialise sub print_filelist { my $self = shift; if ($self->{size}) { open my $tfh, '|-', $self->{tar}, $self->{_list_command}, '-' - or die "open() on pipe to tar: $OS_ERROR"; + or die "open() on pipe to tar: $OS_ERROR"; main::copy($self->{fh}, $tfh, $self->{size}); } return $self; -} +} ## end sub print_filelist sub extract { my $self = shift; if ($self->{size}) { open my $tfh, '|-', $self->{tar}, $self->{_extract_command}, '-' - or die "open() on pipe to tar: $OS_ERROR"; + or die "open() on pipe to tar: $OS_ERROR"; main::copy($self->{fh}, $tfh, $self->{size}); } return $self; -} +} ## end sub extract package Deployable::Tar::Internal; use English qw( -no_match_vars ); @@ -397,15 +399,16 @@ sub initialise { if ($self->{size}) { my $data = main::full_read($self->{fh}, $self->{size}); - open my $fh, '<', \$data or die "open() on internal variable: $OS_ERROR"; + open my $fh, '<', \$data + or die "open() on internal variable: $OS_ERROR"; require Archive::Tar; $self->{_tar} = Archive::Tar->new(); $self->{_tar}->read($fh); - } + } ## end if ($self->{size}) return $self; -} +} ## end sub initialise sub print_filelist { my $self = shift; @@ -413,7 +416,7 @@ sub print_filelist { print {*STDOUT} " $_\n" for $self->{_tar}->list_files(); } return $self; -} +} ## end sub print_filelist sub extract { my $self = shift; @@ -421,6 +424,6 @@ sub extract { $self->{_tar}->extract(); } return $self; -} +} ## end sub extract __END__ -- 2.11.4.GIT