Main Page/Stuff/OLGA

From phurvitz
Jump to: navigation, search

Olga archive processing

  1. Download everything from http://www.mothership.co.za/download/olga
    wget -nd -np -r http://www.mothership.co.za/download/olga
  2. Unzip the [0-9][a-z] (version 1 data) into main
  3. Unzip the updates into updates (use unzip with -n so as not to overwrite)
  4. The script below can help with renaming upper/lowercase and dealing with file modes. The gist is to unzip existing zip files into the updates folders and then to zip them again so they will be sorted alphabetically. You can add files to a zip archive but they are appended rather than being added by alphabetical order.

<source lang="perl">

  1. ! /usr/bin/perl

use File::Find; use File::Copy; use File::Basename; use Cwd; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use Archive::Extract;

$zipdir = "o:/olga/main"; $mode = 0777;

@origdirs = "$zipdir"; @renamedirs = "o:/olga"; @updateddirs = "o:/olga/updated"; $outdir = "o:/olga/updated";


  1. dirs to zip (these contain all original and updated files)

opendir(DIR, "o:/olga/updates"); @dirs_to_zip = grep(/^[0-9]|^[a-z]$/, readdir(DIR)); closedir(DIR); print "@dirs_to_zip\n";

  1. exit;


  1. rename & chmod
  2. find(\&rename, @renamedirs);
  1. process unzip
  2. find(\&unzip, @origdirs);
  1. process each updated folder

foreach $d (@dirs_to_zip) { $fulldir = "o:/olga/updates/$d"; @fulldir = "o:/olga/updates/$d"; print "FD: $fulldir\n"; chdir $fulldir; # get folders in this dir opendir(DIR, "$fulldir"); @asrtistdirs = grep(/[0-9]|[a-z]/, readdir(DIR));

  1. @asrtistdirs = readdir(DIR);

closedir(DIR); foreach $artistdir (@asrtistdirs) { print "AD: $artistdir\n"; $dir_to_process = "$fulldir/$artistdir"; @dir_to_process = $dir_to_process; chdir $dir_to_process; print "\nprocessing ARTISTDIR $dir_to_process @dir_to_process\n"; my $outputfile = "o:/olga/updated/$artistdir.zip"; print "zipping $outputfile\n"; my $zip = Archive::Zip->new(); opendir(DIR, $dir_to_process); @files_to_zip = grep(/..*\...*/, readdir(DIR)); print "FTZ: @files_to_zip\n"; closedir(DIR); foreach $file_to_zip (@files_to_zip){ my($filename, $directories, $suffix) = fileparse($file_to_zip, qr/\.[^.]*/); if($suffix eq ".btab") { next;} my $lcfile = lc($file_to_zip); rename($file, $lcfile); chmod $mode, $lcfile; print "adding $file_to_zip to $outputfile\n"; my $member = $zip->addFile("$lcfile"); } # Save the Zip file unless ( $zip->writeToFileNamed("$outputfile") == AZ_OK ) { die 'write error'; } } }


sub rename{ # filename my $filename = $File::Find::name; # change to lowercase my $newfilename = lc($filename); #if($filename != $newfilename) { print "renaming $filename to $newfilename\n"; rename ($filename, $newfilename); chmod $mode, "$newfilename"; #} }

sub unzip { my $file = $File::Find::name; my($filename, $directories, $suffix) = fileparse($file, qr/\.[^.]*/); if($suffix ne '.zip') { next; } #print "--$filename $suffix--\n"; #exit; # output zip file my $outputfile = "$outdir/$filename.zip"; # first letter of name my $firstletter = lc(substr($filename, 0, 1)); # first letter dir my $firstletterdir = "o:/olga/updates/$firstletter"; # updates dir my $updatesdir = "o:/olga/updates/$firstletter/$filename"; # does the firstletter dir exist? if(!-e $firstletterdir) { mkdir $firstletterdir; } # does the updates folder exist? if(!-e $updatesdir) { print "making $updatesdir\n"; mkdir $updatesdir; } # unzip it to its updates folder print "unzipping $file\n"; my $ae = Archive::Extract->new( archive => "$file" ); my $ok = $ae->extract( to => "$updatesdir" ) or die $ae->error; } </source>