[lintian] 02/04: r-sync-state: Migrate to new YAML config
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch reporting-rewrite-config-and-archive-handling
in repository lintian.
commit fb0deb60b3c7a016ee109bd09228735c9805386a
Author: Niels Thykier <niels@thykier.net>
Date: Sat Apr 22 16:52:38 2017 +0000
r-sync-state: Migrate to new YAML config
Signed-off-by: Niels Thykier <niels@thykier.net>
---
commands/reporting-sync-state.pm | 104 +++++++++++++++++++--------------------
1 file changed, 52 insertions(+), 52 deletions(-)
diff --git a/commands/reporting-sync-state.pm b/commands/reporting-sync-state.pm
index 42c2579..568b5a4 100644
--- a/commands/reporting-sync-state.pm
+++ b/commands/reporting-sync-state.pm
@@ -24,6 +24,7 @@ use autodie;
use Getopt::Long();
use File::Basename qw(basename);
+use YAML::XS ();
use Lintian::Lab;
use Lintian::Relation::Version qw(versions_comparator);
@@ -34,24 +35,15 @@ use Lintian::Util qw(
save_state_cache
strip
visit_dpkg_paragraph
- untaint
);
my $DEFAULT_CHECKSUM = 'sha256';
my (%KNOWN_MEMBERS, %ACTIVE_GROUPS);
+my $CONFIG;
my %OPT;
my %OPT_HASH= (
- 'state-dir=s' => \$OPT{'state-dir'},
- 'mirror-path=s' => \$OPT{'mirror-path'},
- # Comma-separated lists
- 'distributions=s@' =>
- sub { push(@{$OPT{'distributions'}}, split(m/,/, $_[1])); },
- 'mirror-areas=s@' =>
- sub { push(@{$OPT{'mirror-areas'}}, split(m/,/, $_[1])); },
- 'architectures=s@' =>
- sub { push(@{$OPT{'architectures'}}, split(m/,/, $_[1])); },
+ 'reporting-config=s'=> \$OPT{'reporting-config'},
'desired-version=s' => \$OPT{'desired-version'},
- 'lintian-lab=s' => \$OPT{'lintian-lab'},
'reschedule-all' => \$OPT{'reschedule-all'},
'help|h' => \&usage,
'debug|d' => \$OPT{'debug'},
@@ -59,43 +51,77 @@ my %OPT_HASH= (
);
sub check_parameters {
- for my $parameter (
- qw(state-dir mirror-path distributions mirror-areas architectures desired-version)
- ) {
+ for my $parameter (qw(reporting-config desired-version)) {
if (not defined($OPT{$parameter})) {
die( "Missing required parameter \"--${parameter}\""
. "(use --help for more info)\n");
}
}
- if (-d $OPT{'state-dir'}) {
- untaint($OPT{'state-dir'});
- } else {
- die("The --state-dir parameter must point to an existing directory\n");
+ if (not $OPT{'reporting-config'} or not -f $OPT{'reporting-config'}) {
+ die("The --reporting-config parameter must point to an existing file\n"
+ );
}
return;
}
+sub required_cfg_value {
+ my (@keys) = @_;
+ my $v = $CONFIG;
+ for my $key (@keys) {
+ if (not exists($v->{$key})) {
+ my $k = join('.', @keys);
+ die("Missing required config parameter: ${k}\n");
+ }
+ $v = $v->{$key};
+ }
+ return $v;
+}
+
+sub required_cfg_non_empty_list_value {
+ my (@keys) = @_;
+ my $v = required_cfg_value(@keys);
+ if (not defined($v) || ref($v) ne 'ARRAY' || scalar(@{$v}) < 1) {
+ my $k = join('.', @keys);
+ die("Invalid configuration: ${k} must be a non-empty list\n");
+ }
+ return $v;
+}
+
sub main {
- my $state;
+ my ($state_dir, $state, $archives);
STDOUT->autoflush;
Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');
Getopt::Long::GetOptions(%OPT_HASH) or die("error parsing options\n");
check_parameters();
- $state = load_state_cache($OPT{'state-dir'});
+ $CONFIG = YAML::XS::LoadFile($OPT{'reporting-config'});
+ $state_dir = required_cfg_value('storage', 'state-cache');
+ $state = load_state_cache($state_dir);
+
if (upgrade_state_cache_if_needed($state)) {
log_debug('Updated the state cache');
}
log_debug('Initial state had '
. (scalar(keys(%{$state->{'groups'}})))
. ' groups');
- local_mirror_manifests($state,$OPT{'mirror-path'},$OPT{'distributions'},
- $OPT{'mirror-areas'},$OPT{'architectures'});
+ $archives = required_cfg_value('archives');
+ for my $archive (sort(keys(%{$archives}))) {
+ log_debug("Processing archive $archive");
+ my $path = required_cfg_value('archives', $archive, 'base-dir');
+ my $archs = required_cfg_non_empty_list_value('archives', $archive,
+ 'architectures');
+ my $components
+ = required_cfg_non_empty_list_value('archives', $archive,
+ 'components');
+ my $distributions
+ = required_cfg_non_empty_list_value('archives', $archive,
+ 'distributions');
+ local_mirror_manifests($state, $path, $distributions, $components,
+ $archs);
+ }
+
cleanup_state($state);
if (not $OPT{'dry-run'}) {
- save_state_cache($OPT{'state-dir'}, $state);
- }
- if ($OPT{'lintian-lab'}) {
- prune_lintian_lab($state, $OPT{'lintian-lab'});
+ save_state_cache($state_dir, $state);
}
exit(0);
}
@@ -397,32 +423,6 @@ sub local_mirror_manifests {
return;
}
-sub prune_lintian_lab {
- my ($state, $lintian_lab_dir) = @_;
- my $lab = Lintian::Lab->new($lintian_lab_dir);
- my $err;
- eval {
- $lab->open;
- $lab->visit_packages(
- sub {
- my ($lpkg) = @_;
- my $id = $lpkg->identifier;
- if (not exists($state->{'members-to-groups'}{$id})) {
- log_debug("Removing ${id} from lab");
- $lpkg->remove if (not $OPT{'dry-run'});
- }
- });
- };
- $err = $@;
- eval {$lab->close;};
- if (my $close_err = $@) {
- # The first error is most important
- die($close_err) if not $err;
- }
- die($err) if $err;
- return;
-}
-
# _open_data_file ($file)
#
# Opens $file if it exists, otherwise it tries common extensions (i.e. .gz) and opens
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: