File: process

package info (click to toggle)
extrepo-data 1.0.6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 10,544 kB
  • sloc: perl: 761; makefile: 5
file content (102 lines) | stat: -rwxr-xr-x 3,220 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/perl -w

use strict;
use warnings;

use File::Basename;
use YAML::XS qw/LoadFile DumpFile/;
use Crypt::Digest::SHA256 qw/sha256_hex/;

use lib join("/", dirname($0), "lib");

use ExtRepoData;

my %required = (
	deb => 1,
	description => 1,
);
my @files = glob("repos/debian/*.yaml");
my %dists = ( debian => {} );
my %ancillary = ( debian => {} );
foreach my $file(@files) {
	my $data = LoadFile($file);
	foreach my $repo(keys %$data) {
		next if $repo =~ /^\./;
		next if exists($data->{$repo}{Disabled});
		tie my (%hash), 'ExtRepoData', $data->{$repo};
		$data->{$repo} = \%hash;
		die "missing suites in repository $repo!\n" unless exists($data->{$repo}{suites});
		foreach my $suite_o(@{$data->{$repo}{suites}}) {
			my $suite = new ExtRepoData::Suite($suite_o);
			$dists{debian}{$suite} = {} unless exists($dists{debian}{$suite});
			$ancillary{debian}{$suite} = {} unless exists($ancillary{debian}{$suite});
			$dists{debian}{$suite}{$repo} = {};
			$dists{debian}{$suite}{$repo}{"gpg-key-checksum"} = { sha256 => sha256_hex($data->{$repo}{"gpg-key"}) };
			$ancillary{debian}{$suite}{$repo} = {};
			$ancillary{debian}{$suite}{$repo}{"gpg-key"} = $data->{$repo}{"gpg-key"};
			my $vers = ExtRepoData::Suite::version_of($suite_o);
			foreach my $key(keys(%{$data->{$repo}{source}})) {
				my $targetkey = $key;
				if($key =~ /^suite-.*/) {
					next unless $key =~ /^suite-$suite-(.*)$/;
					$targetkey = $1;
				} else {
					next if exists($dists{debian}{$suite}{$repo}{source}{$targetkey});
				}
				my $value = $data->{$repo}{source}{$key};
				$value =~ s/<SUITE>/$suite_o/g;
				$value =~ s/<VERSION>/$vers/g;
				$dists{debian}{$suite}{$repo}{source}{$targetkey} = $value;
			}
			foreach my $key(qw/components policies policy contact description/) {
				next unless exists($data->{$repo}{$key});
				my $value = $data->{$repo}{$key};
				$value =~ s/<SUITE>/$suite_o/g;
				$value =~ s/<VERSION>/$vers/g;
				$dists{debian}{$suite}{$repo}{$key} = $value;
			}
			if(exists($data->{$repo}{"suite-$suite-components"})) {
				my $value = $data->{$repo}{"suite-$suite-components"};
				$value =~ s/<SUITE>/$suite_o/g;
				$value =~ s/<VERSION>/$vers/g;
				$dists{debian}{$suite}{$repo}{components} = $value;
			}
			$dists{debian}{$suite}{$repo}{"gpg-key-file"} = "$repo.asc";
		}
	}
}

mkdir "public";

sub create_index {
	my $dir = shift;

	open my $file, ">", "public/$dir/index.html" or die $!;
	my $base = basename($dir);
	$base = "/" if($base eq ".");
	print $file "<html><head><title>extrepo data: $base index</title></head><body>";
	foreach my $entry(sort(glob "public/$dir/*")) {
		my $ebase = basename($entry);
		print $file "<a href=\"$ebase\">$ebase</a><br>\n";
		if(-d $entry) {
			create_index(join("/", $dir, $ebase));
		}
	}
	print $file "</body></html>\n";
	close $file;
}

foreach my $dist(keys %dists) {
	mkdir "public/$dist";
	foreach my $suite(keys %{$dists{$dist}}) {
		mkdir "public/$dist/$suite";
		DumpFile("public/$dist/$suite/index.yaml", $dists{$dist}{$suite});
		foreach my $repo(keys %{$dists{$dist}{$suite}}) {
			open my $fh, ">public/$dist/$suite/$repo.asc";
			print $fh $ancillary{$dist}{$suite}{$repo}{"gpg-key"};
			close $fh;
		}
	}
}

create_index(".");