Benutzer-Werkzeuge

Webseiten-Werkzeuge


users:werner:getrepolist2

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
users:werner:getrepolist2 [2008-02-09 1431]
werner verkürzte allfiles
users:werner:getrepolist2 [2008-02-09 2256] (aktuell)
werner funktionierender Code :-)
Zeile 1: Zeile 1:
 +====== Suche im openSUSE Build Repository ======
  
 +Den begleitenden Text findest Du auf [[users:werner:getrepolist]], hier nur der Versuch, das Script in Perl umzusetzen:
 +
 +<code perl>
 +#!/usr/bin/perl -w
 +
 +use strict;
 +use warnings;
 +use Net::FTP;
 +
 +# set some variables
 +our $debug = 0;
 +my $ftpserver = 'ftp5.gwdg.de';
 +our $searchbase   = 'pub/opensuse/repositories';
 +my $verzname = "ftp://$ftpserver/$searchbase";
 +# get date and time (used for logging) and print them
 +my @dots;
 +my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
 +$year += 1900;
 +$mon++;
 +my $datstempel = sprintf("%04d%02d%02d", $year, $mon, $mday);
 +my $jetztzeit  = sprintf("%02d:%02d:%02d", $hour, $min, $sec);
 +print "starting script on $datstempel at $jetztzeit.\n";
 +# where to put the data - logfiles with timestamp in their names
 +my $logfilename = ">>findrepo$datstempel\_$jetztzeit.log";
 +our %allfiles = ('LOG' => $logfilename);
 +my @versionen = ('101', '102', '103', 'S09', 'S10');
 +for my $vers (@versionen) {
 + $allfiles{"{$vers}apt"       = ">>aptrepo_$vers\_$datstempel\_$jetztzeit.list";
 + $allfiles{"{$vers}home" = ">>aptrepo_$vers\_$datstempel\_$jetztzeit\_home.list";
 + $allfiles{"{$vers}smart"} = ">>smart_$vers\_$datstempel\_$jetztzeit.sh";
 +} # for $vers (@versionen)
 +mkdir 'zypprepos.d';
 +# the real start :-)
 +our $ftp = Net::FTP->new($ftpserver, Passive => 1)
 +           or die "Cannot access FTP server $ftpserver: $@";
 +print "Access to FTP server $ftpserver is possible\n" if ($debug & 2);
 +$ftp->login("anonymous",'-anonymous@')
 +            or die "Cannot login: ", $ftp->message;
 +print "anonymous login is possible :-)\n" if ($debug & 1);
 +scan1dir($searchbase);
 +# post work - write out the time again so one can see how long it takes
 +($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
 +$year += 1900;
 +$mon++;
 +$datstempel = sprintf("%04d%02d%02d", $year, $mon, $mday);
 +$jetztzeit  = sprintf("%02d:%02d:%02d", $hour, $min, $sec);
 +print "script ending on $datstempel at $jetztzeit.\n";
 +
 +sub scan1dir {
 + our %allfiles;
 + our $searchbase;
 + our $ftp;
 + our $debug;
 + my ($thisdir) = @_;
 + print "now working on $thisdir\n" if ($debug & 4);
 + my $right6  = substr($thisdir, -6);
 + my $right5  = substr($thisdir, -5);
 + my $right4  = substr($thisdir, -4);
 + my $right3  = substr($thisdir, -3);
 + my $forget  = length("$searchbase");
 + my $shorter = substr($thisdir, $forget);
 + my $legible = $shorter;
 + my $itsfor  = 'xxx';
 + my $usehome = ($thisdir =~ /home:\//);
 + # $thisdir is s.th. like home:/dings/openSUSE_10.3 or X11:/XGL/openSUSE_10.3
 + # now snip from the last / onward:
 + if (length($shorter)) {
 + $legible =~ s|(.*)/(.+)|$1|;
 + $legible =~ s/\///g;
 + $right4  = substr($thisdir, -4);
 + $right3  = substr($thisdir, -3);
 + $itsfor  = '101' if ( ($right4 eq '10.1' ) or ($right3 eq '101'   ) );
 + $itsfor  = '102' if ( ($right4 eq '10.2' ) or ($right3 eq '102'   ) );
 + $itsfor  = '103' if ( ($right4 eq '10.3' ) or ($right3 eq '103'   ) );
 + $itsfor  = 'S09' if ( ($right5 eq 'SLES9') or ($right6 eq 'SLES_9') );
 + $itsfor  = 'S10' if ( ($right5 eq 'SLE10') or ($right6 eq 'SLES10') or ($right6 eq 'SLE_10') );
 + } # if (length($shorter))
 + $ftp->cwd("/$thisdir")
 + or die "Cannot change into working directory $thisdir: ", $ftp->message;
 + my @dircontent = $ftp->dir();
 + my @unterverz = ();
 + my $ftpelem;
 + for $ftpelem (@dircontent) {
 + my ($rechte, $num, $user, $group, $size, $mon, $day, $time, $name) = split / +/, $ftpelem, 9;
 + if (substr($rechte, 0, 1) eq 'd') {
 + print "guessed directory: '$name' (itsfor=$itsfor, shorter=$shorter, legible=$legible)\n" if ($debug & 1);
 + if (("$itsfor" ne 'xxx') and ("$name" eq 'repodata')) {
 + my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
 + $year += 1900;
 + $mon++;
 + my $jetztzeit  = sprintf("%02d:%02d:%02d", $hour, $min, $sec);
 + my $MYTOFILE = $allfiles{"LOG"};
 + open THISHANDLE, $allfiles{"LOG"}
 +      or die "$jetztzeit: Cannot open logfile";
 + print THISHANDLE "$jetztzeit: now writing $legible for $thisdir\n";
 + close THISHANDLE;
 + open THISHANDLE, $allfiles{"{$itsfor}smart"}
 +      or die "$jetztzeit: Cannot open smart output file for $itsfor\n";
 + print THISHANDLE "smart channel --add $legible ",
 +                  "type=repomd name=$legible ",
 +                  "baseurl=http://software.opensuse.org/repositories$shorter\n";
 + close THISHANDLE;
 + if ($usehome) {
 + open THISHANDLE, $allfiles{"{$itsfor}home"}
 +      or die "$jetztzeit: Cannot open apt-home output file for $itsfor\n";
 + print THISHANDLE "repomd http://software.opensuse.org/repositories $shorter\n";
 + close THISHANDLE;
 + } # if ($usehome)
 + my $meld = "Cannot open apt output file »" . $allfiles{"{$itsfor}apt"};
 + open THISHANDLE, $allfiles{"{$itsfor}apt"}
 +      or die "$jetztzeit: $meld « for $itsfor ($shorter)\n";
 + print THISHANDLE "repomd http://software.opensuse.org/repositories $shorter\n";
 + close THISHANDLE;
 + if ("$itsfor" eq '103') {
 + open ZYPPFILE, ">zypprepos.d/$legible"
 +                or die "Cannot create file zypprepos.d/$legible: $!";
 + print ZYPPFILE "[$legible]\n";
 + print ZYPPFILE "name=$legible\n";
 + print ZYPPFILE "baseurl=http://software.opensuse.org/repositories$shorter\n";
 + print ZYPPFILE "type=rpm-md\n";
 + print ZYPPFILE "enabled=1\n";
 + print ZYPPFILE "autorefresh=1\n";
 + print ZYPPFILE "gpgcheck=1\n";
 + close ZYPPFILE;
 + } # if ("$itsfor" eq '103')
 + } # if (($itsfor ne 'xxx') and ("$name" eq 'repodata'))
 + else {
 + print ("adding $thisdir/$name to unterverz\n") if ($debug & 2);
 + @unterverz = (@unterverz, "$thisdir/$name") if ("$name" ne 'lost+found');
 + }
 + } # if (substr($rechte, 0, 1) eq 'd')
 + } # foreach $elem (@dircontent)
 + if ((my $unterverz = @unterverz) > 0) {
 + for my $untvz (@unterverz) {
 + scan1dir($untvz);
 + } # for $untvz (@unterverz)
 + } # if (($unterverz = @unterverz) > 0)
 + 1;
 +} # sub scan1dir
 +</code>
 +
 +Übrigens läuft das Script bei mir in genau einer Stunde durch:
 +
 +  starting script on 20080209 at 16:48:09.
 +  script ending on 20080209 at 18:48:05.
users/werner/getrepolist2.txt · Zuletzt geändert: 2008-02-09 2256 von werner