changeset 3:ae61af01bfa5

sync
author cin
date Wed, 23 Oct 2013 01:13:19 +0400
parents f2a86753b494
children 8001dc056331
files _test/repo.pl _test/test_xml.pl lib/Yours/FileValidator.pm lib/Yours/Model/Repository.pm lib/Yours/Parsers/PMDParser.pm lib/Yours/Parsers/SaxParser.pm lib/Yours/SyncRepository.pm
diffstat 7 files changed, 88 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/_test/repo.pl	Tue Oct 22 16:15:22 2013 +0400
+++ b/_test/repo.pl	Wed Oct 23 01:13:19 2013 +0400
@@ -1,8 +1,6 @@
 #!/usr/bin/perl
 use strict;
 
-$ENV{http_proxy} = "http://10.111.0.3:3128";
-
 use IMPL::require {
 	Repository => 'Yours::Model::Repository',
 	Sync => 'Yours::SyncRepository',
@@ -15,6 +13,16 @@
 		name => 'gnome',
 		dir => 'gnome',
 		location => 'http://download.opensuse.org/repositories/GNOME:/STABLE:/3.8/openSUSE_12.3/'
+	},
+	{
+		name => 'mono',
+		dir => 'mono',
+		location => 'http://download.opensuse.org/repositories/Mono/openSUSE_12.3/'
+	},
+	{
+		name => 'nvidia',
+		dir => 'nvidia',
+		location => 'ftp://download.nvidia.com/opensuse/12.3/'
 	}
 );
 
@@ -22,11 +30,19 @@
 	eval {
 		my $repo = Repository->new( map $info->{$_},qw(name dir location));
 		Sync
-			->new(*STDOUT) # log to STDOUT
+			->new({
+				log => *STDOUT,
+				skipDebug => 1,
+				skipSrc => 1
+			}) 
 			->Update($repo);
 	};
-	warn $@ if $@;
+	if(my $err = $@) {
+		print eval { $err->message || $err }, "\n";
+	} else {
+		print "done\n";
+	}
 }
 
 
-print "SUCCESS\n";
\ No newline at end of file
+print "ALL TASKS COMPLETE\n";
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/_test/test_xml.pl	Wed Oct 23 01:13:19 2013 +0400
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+package MyParser;
+
+use IMPL::declare {
+	base => [
+		'Yours::Parsers::SaxParser' => undef
+	]
+};
+
+sub ProcessRootNode {
+	my ($this,$node) = @_;
+	
+	my $handler;
+	my $level = 0;
+	$handler = sub {
+		my ($me,$node) = @_;
+		print ' ' x $level, $node->depth, " ", $node->name,"\n";
+		$level++;
+		$me->ReadChildren($handler);
+		$level--;
+	};
+	
+	print "root: \n";
+	$this->ReadChildren($handler);
+}
+
+my $text = '<?xml version="1.0"?>
+<root>
+	<n1></n1>
+	<n2>
+		<w1>asd</w1>
+	</n2>
+	<n3></n3>
+</root>
+';
+
+MyParser->new()->Parse({
+	string => $text 
+});
+
--- a/lib/Yours/FileValidator.pm	Tue Oct 22 16:15:22 2013 +0400
+++ b/lib/Yours/FileValidator.pm	Wed Oct 23 01:13:19 2013 +0400
@@ -45,7 +45,7 @@
 					next if $digest eq $checksum->{value};
 
 					push @bad, {
-						message => "$digest ne $checksum->{value}",
+						message => "checksumm failed",
 						file => $file,
 						metadata => $md
 					};
--- a/lib/Yours/Model/Repository.pm	Tue Oct 22 16:15:22 2013 +0400
+++ b/lib/Yours/Model/Repository.pm	Wed Oct 23 01:13:19 2013 +0400
@@ -136,16 +136,19 @@
 }
 
 sub ValidateContent {
-	my ($this) = @_;
+	my ($this,$opts) = @_;
+	
+	$opts ||= {};
 	
 	my %files;
 	
 	$this->ProcessContent(sub {
-		my ($meta) = @_;
+		my ($file,$md) = @_;
 		
-		my $file = $this->GetLocalFile($meta->{location});
+		return if $opts->{skipSrc} and $md->{arch} eq 'src';
+		return if $opts->{skipDebug} and $md->{name} =~ /debuginfo|debugsource/;
 		
-		$files{$file} = $meta;
+		$files{$file} = $md;
 	});
 	
 	return FileValidator->new()->Validate(\%files);
--- a/lib/Yours/Parsers/PMDParser.pm	Tue Oct 22 16:15:22 2013 +0400
+++ b/lib/Yours/Parsers/PMDParser.pm	Wed Oct 23 01:13:19 2013 +0400
@@ -26,6 +26,7 @@
 		
 		my $package = $me->ReadComplexNode({
 			name => 'ReadTextNode',
+			arch => 'ReadTextNode',
 			location => sub { shift->attribute('href') },
 			checksum => sub {
 				my ($me) = @_;
--- a/lib/Yours/Parsers/SaxParser.pm	Tue Oct 22 16:15:22 2013 +0400
+++ b/lib/Yours/Parsers/SaxParser.pm	Wed Oct 23 01:13:19 2013 +0400
@@ -37,15 +37,16 @@
 
 	return if $reader->isEmptyElement;
 
-	my $currentLevel = $reader->depth;
+	my $currentLevel = $reader->depth+1;
 
 	while (
 		$reader->read
-		&& (   $reader->depth > $currentLevel
-			|| $reader->nodeType != XML_READER_TYPE_END_ELEMENT )
 	  )
 	{
-		$this->$handler($reader) if $handler;
+		print "---\n" and return if $reader->depth <= $currentLevel && $reader->nodeType == XML_READER_TYPE_END_ELEMENT;
+		#if ($reader->nodeType != XML_READER_TYPE_END_ELEMENT) {
+			$this->$handler($reader) if $handler;
+		#}
 	}
 }
 
--- a/lib/Yours/SyncRepository.pm	Tue Oct 22 16:15:22 2013 +0400
+++ b/lib/Yours/SyncRepository.pm	Wed Oct 23 01:13:19 2013 +0400
@@ -17,15 +17,21 @@
 	props => [
 		agent => PROP_RO,
 		log => PROP_RO,
+		skipSrc => PROP_RO,
+		skipDebug => PROP_RO,
 		_dirs => PROP_RW,
 		_files => PROP_RW
 	]
 };
 
 sub CTOR {
-	my ($this, $log) = @_;
+	my ($this, $opts) = @_;
+	
+	$opts ||= {};
 	
-	$this->log($log);
+	$this->log($opts->{log});
+	$this->skipSrc($opts->{skipSrc});
+	$this->skipDebug($opts->{skipDebug});
 	$this->_dirs({});
 	$this->_files({});
 	
@@ -78,7 +84,6 @@
 		$this->_RegisterFile($file,$md);
 		
 		$this->_FetchFile($file,$md,'die')
-			unless -f $file;
 	}
 	
 	$this->Log("  loading description");
@@ -107,9 +112,12 @@
 	$repo->ProcessContent(sub {
 		my ($file,$md) = @_;
 		
+		return if $this->skipSrc and $md->{arch} eq 'src';
+		return if $this->skipDebug and $md->{name} =~ /debuginfo|debugsource/;
+		
 		$this->_RegisterFile($file,$md);
 		
-		$this->_FetchFile($file,$md,'die')
+		$this->_FetchFile($file,$md)
 			unless -f $file;
 	});
 	
@@ -124,6 +132,7 @@
 	while(my @errors = Validator->new()->Validate($validateFiles)) {
 		die Exception->new("Unable to complete due errors")
 			unless $retry;
+		$this->Log("  attempt to fix problems");
 		$retry--;
 		
 		$validateFiles = {};