Debian Codegraph @

script/kgb-split-config

raw
1 #!/usr/bin/perl
2 # vim: ts=4:sw=4:et:ai:sts=4
3 #
4 # KGB - an IRC bot helping collaboration
5 # Copyright © 2012 Damyan Ivanov
6 # Copyright © 2012 gregor herrmann
7 #
8 # This program is free software; you can redistribute it and/or modify it under
9 # the terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # This program is distributed in the hope that it will be useful, but WITHOUT
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 # details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # this program; if not, write to the Free Software Foundation, Inc., 51
20 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 use strict;
23 use warnings;
24 use 5.010;
25 use autodie;
26
27 use YAML qw(LoadFile DumpFile);
28 use File::Spec;
29
30 no warnings 'once';
31 local $YAML::SortKeys = [qw(repositories channels)];
32 use warnings;
33
34 my $file = '/etc/kgb-bot/kgb.conf';
35 my $dir = '/etc/kgb-bot/kgb.conf.d';
36
37 my $yaml = LoadFile($file);
38
39 foreach my $repo ( keys %{ $yaml->{repositories} } ) {
40 my $splitconfig = {};
41 $splitconfig->{repositories}->{$repo} = $yaml->{repositories}->{$repo};
42 foreach my $channel ( @{ $yaml->{channels} } ) {
43 push @{ $splitconfig->{channels} }, $channel
44 if grep { $_ eq $repo } @{ $channel->{repos} };
45 }
46 my $outfile = File::Spec->catdir( $dir, "$repo.conf" );
47 DumpFile( $outfile, $splitconfig );
48 }
49
50 __END__
51
52 =head1 NAME
53
54 kgb-split-config - helper script for splitting out project configurations
55
56 =head1 SYNOPSIS
57
58 B<kgb-split-config>
59
60 =head1 DESCRIPTION
61
62 B<kgb-split-config> extracts project configurations from F</etc/kgb-bot/kgb.conf> and
63 dumps them as separate files into F</etc/kgb-bot/kgb.conf.d/>.
64
65 =head1 COPYRIGHT AND LICENSE
66
67 Copyright (C) 2012 Damyan Ivanov
68 Copyright (C) 2012 gregor herrmann
69
70 This program is free software; you can redistribute it and/or modify it under
71 the terms of the GNU General Public License as published by the Free Software
72 Foundation; either version 2 of the License, or (at your option) any later
73 version.
74
75 This program is distributed in the hope that it will be useful, but WITHOUT
76 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
77 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
78 details.
79
80 You should have received a copy of the GNU General Public License along with
81 this program; if not, write to the Free Software Foundation, Inc., 51
82 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
83
84 =cut