Mercurial > pub > Yours
changeset 5:45a84be3ebb1 default tip
added deltainfo (.drpm) packages support
author | sergey |
---|---|
date | Wed, 23 Oct 2013 16:24:52 +0400 |
parents | 8001dc056331 |
children | |
files | _test/repo.pl lib/Yours/FileValidator.pm lib/Yours/Model/Repository.pm lib/Yours/Parsers/DIMDParser.pm lib/Yours/Parsers/SaxParser.pm |
diffstat | 5 files changed, 115 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/_test/repo.pl Wed Oct 23 11:49:16 2013 +0400 +++ b/_test/repo.pl Wed Oct 23 16:24:52 2013 +0400 @@ -1,6 +1,8 @@ #!/usr/bin/perl use strict; + + use IMPL::require { Repository => 'Yours::Model::Repository', Sync => 'Yours::SyncRepository', @@ -10,23 +12,28 @@ my @repos = ( { + name => 'update', + dir => '_data/update', + location => 'http://mirror.yandex.ru/opensuse/update/12.3/', + }, + { name => 'gnome', - dir => 'gnome', + dir => '_data/gnome', location => 'http://download.opensuse.org/repositories/GNOME:/STABLE:/3.8/openSUSE_12.3/' }, { name => 'mono', - dir => 'mono', + dir => '_data/mono', location => 'http://download.opensuse.org/repositories/Mono/openSUSE_12.3/' }, { name => 'nvidia', - dir => 'nvidia', + dir => '_data/nvidia', location => 'ftp://download.nvidia.com/opensuse/12.3/' }, { name => 'broken', - dir => 'broken', + dir => '_data/broken', location => 'http://mirror.yandex.ru/opensuse/repositories/KDE:/Extra/KDE_Release_410_openSUSE_12.3/' } ); @@ -42,8 +49,8 @@ }) ->Update($repo); }; - if(my $err = $@) { - print eval { $err->message || $err }, "\n"; + if($@) { + warn $@; } else { print "done\n"; }
--- a/lib/Yours/FileValidator.pm Wed Oct 23 11:49:16 2013 +0400 +++ b/lib/Yours/FileValidator.pm Wed Oct 23 16:24:52 2013 +0400 @@ -67,7 +67,8 @@ } sub Log { - + shift; + warn @_; } 1; \ No newline at end of file
--- a/lib/Yours/Model/Repository.pm Wed Oct 23 11:49:16 2013 +0400 +++ b/lib/Yours/Model/Repository.pm Wed Oct 23 16:24:52 2013 +0400 @@ -9,6 +9,7 @@ require => { MDParser => 'Yours::Parsers::MDParser', PMDParser => 'Yours::Parsers::PMDParser', + DIMDParser => 'Yours::Parsers::DIMDParser', Uncompress => 'IO::Uncompress::AnyUncompress', IOException => '-IMPL::IOException', ArgException => '-IMPL::InvalidArgumentException', @@ -102,21 +103,30 @@ unless $handler; my %index = map { $_->{type}, $_ } @{ $this->ReadMetadata()->{data} || [] }; - - my $filePrimary = $this->GetLocalFile( $index{primary}{location} ); - - die IOException->new( "File not found", $filePrimary ) - unless -f $filePrimary; + + my %parsers = ( + primary => PMDParser, + deltainfo => DIMDParser + ); - my $hdata = Uncompress->new($filePrimary) - or die IOException->new( "Failed to uncompress file", $filePrimary ); - - PMDParser->new(sub { - my ($meta) = shift; - my $file = $this->GetLocalFile($meta->{location}); - $meta->{location} = $this->GetRemoteLocation($meta->{location}); - &$handler($file,$meta); - })->Parse( { IO => $hdata, no_blanks => 1 } ); + foreach my $db (qw(primary deltainfo)) { + my $file = $index{$db}{location} + or next; + $file = $this->GetLocalFile( $file ); + + die IOException->new( "File not found", $file ) + unless -f $file; + + my $hdata = Uncompress->new($file) + or die IOException->new( "Failed to uncompress file", $file ); + + $parsers{$db}->new(sub { + my ($meta) = shift; + my $file = $this->GetLocalFile($meta->{location}); + $meta->{location} = $this->GetRemoteLocation($meta->{location}); + &$handler($file,$meta); + })->Parse( { IO => $hdata, no_blanks => 1 } ); + } } sub ValidateMetadata {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/Yours/Parsers/DIMDParser.pm Wed Oct 23 16:24:52 2013 +0400 @@ -0,0 +1,59 @@ +package Yours::Parsers::DIMDParser; +use strict; + +use IMPL::Const qw(:prop); +use IMPL::declare { + base => [ + 'Yours::Parsers::SaxParser' => '@_' + ], + props => [ + onpackage => PROP_RW + ] +}; + +sub CTOR { + my ($this,$handler) = @_; + + $this->onpackage($handler); +} + +sub ProcessRootNode { + my ($this,$node) = @_; + + $this->ReadComplexContent({ + newpackage => 'ProcessPackageRecord' + }); +} + +sub ProcessPackageRecord { + my ($this,$node) = @_; + + my $name = $this->attribute('name'); + my $arch = $this->attribute('arch'); + + my $deltas = $this->ReadComplexContent({ + delta => [{ + 'location:filename' => 'ReadTextNode', + size => 'ReadTextNode', + checksumm => sub { + my $me = shift; + return { + type => $me->attribute('type'), + value => 'ReadTextNode' + } + } + }] + })->{delta}; + + if (my $handler = $this->onpackage) { + foreach my $delta ( @{$deltas || []} ) { + $delta->{name} = $name; + $delta->{arch} = $arch; + $handler->($delta); + } + } + + return; +} + +1; \ No newline at end of file
--- a/lib/Yours/Parsers/SaxParser.pm Wed Oct 23 11:49:16 2013 +0400 +++ b/lib/Yours/Parsers/SaxParser.pm Wed Oct 23 16:24:52 2013 +0400 @@ -28,6 +28,7 @@ sub ProcessRootNode { my ( $this, $reader ) = @_; + warn "not implemented"; } sub ReadChildren { @@ -69,22 +70,35 @@ return $text; } +sub ReadComplexContent { + goto &ReadComplexNode; +} + sub ReadComplexNode { my ( $this, $schema ) = @_; if ( ref $schema eq 'HASH' ) { my %data; + + my ($handlers,$aliases); + while(my ($selector,$handler) = each %$schema) { + my ($alias,$node) = split /:/, $selector; + $node ||= $alias; + $handlers->{$node} = $handler; + $aliases->{$node} = $alias; + } $this->ReadChildren( sub { my ( $me, $node ) = @_; my $name = $node->localName; - if ( my $handler = $schema->{$name} ) { + my $alias = $aliases->{$name}; + if ( my $handler = $handlers->{$name} ) { if (ref $handler eq 'ARRAY') { - push @{$data{$name}}, $me->ReadComplexNode($$handler[0]); + push @{$data{$alias}}, $me->ReadComplexNode($$handler[0]); } else { - $data{$name} = $me->ReadComplexNode($handler); + $data{$alias} = $me->ReadComplexNode($handler); } } else { $me->ReadChildren();