diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2016-11-13 16:52:38 -0800 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2016-11-13 16:52:38 -0800 |
commit | 5ca7e7cffc53b2378d3d9eb5168458935ca21627 (patch) | |
tree | 701bb640236cf08a5bd9c9c23c6a5bcbfe3f723e /tests/archive.pl | |
parent | c5223be4341ec8c679dad64c8c7bd3ce315d06cc (diff) |
Rewrite archive script into Python
Perl version needed Archive::Zip that for some reason is not installed on WSL by
default. Use this as an opportunity to remove the last Perl script.
Diffstat (limited to 'tests/archive.pl')
-rw-r--r-- | tests/archive.pl | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/tests/archive.pl b/tests/archive.pl deleted file mode 100644 index 76484f7..0000000 --- a/tests/archive.pl +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/perl - -use Archive::Tar; -use Archive::Zip; -use File::Basename; - -my $target = shift @ARGV; -my @sources = @ARGV; - -my $basedir = basename($target, ('.zip', '.tar.gz', '.tgz')) . '/'; - -my $zip = $target =~ /\.zip$/; -my $arch = $zip ? Archive::Zip->new : Archive::Tar->new; - -for $source (sort {$a cmp $b} @sources) -{ - my $contents = &readfile_contents($source); - my $meta = &readfile_meta($source); - my $file = $basedir . $source; - - if (-T $source) - { - # convert all newlines to Unix format - $contents =~ s/\r//g; - - if ($zip) - { - # convert all newlines to Windows format for .zip distribution - $contents =~ s/\n/\r\n/g; - } - } - - if ($zip) - { - my $path = $file; - $arch->addDirectory($path) if $path =~ s/\/[^\/]+$/\// && !defined($arch->memberNamed($path)); - - my $member = $arch->addString($contents, $file); - - $member->desiredCompressionMethod(COMPRESSION_DEFLATED); - $member->desiredCompressionLevel(9); - - $member->setLastModFileDateTimeFromUnix($$meta{mtime}); - } - else - { - $arch->add_data($file, $contents, $meta); - } -} - -$zip ? $arch->overwriteAs($target) : $arch->write($target, 9); - -sub readfile_contents -{ - my $file = shift; - - open FILE, $file or die "Can't open $file: $!"; - binmode FILE; - my @contents = <FILE>; - close FILE; - - return join('', @contents); -} - -sub readfile_meta -{ - my $file = shift; - - my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($file); - - return {mtime => $mtime}; -} |