summaryrefslogtreecommitdiffstats
path: root/lib/MDV/Distribconf/MediaCFG.pm
blob: c96bfd6b82a9e95e8e352be8621c3d3bee29ef81 (plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package MDV::Distribconf::MediaCFG;

use strict;
use warnings;
use MDV::Distribconf;

our $VERSION = (qq$Revision$ =~ /(\d+)/)[0];

=head1 NAME

MDV::Distribconf::MediaCFG

=head1 DESCRIPTION

This module provides documenation of known values in F<media.cfg>.

=head1 MEDIACFG VERSION

The media.cfg version is given by the 'mediacfg_version' in 'media_info'.
This value should be set is you want to use new features that can change the
behavior of this module.

=head2 1

This is the default and the first version of media.cfg format.

=head2 2

Since this version, all media paths are relative to the media_info path.
Previously, media paths were relative to media_info except when beginning with
F</>, which were relative to the root of the distrib.

=head2 3

This version allows to include in values variables that refer to
other values defined in the configuration file:

=over 4

=item ${...}

refers to a global value (distribution version, arch...)

=item %{...}

refers to a value specific to the media (name, ...)

=back

=head1 VALUE

=cut

my $value = {};

=head2 GLOBAL VALUES

This value can only be set into 'media_info' section.

=cut

$value->{mediacfg_version} = { 
    validation => sub {
        my ($val) = @_;
        if ($val !~ /^(\d|.)+$/) {
            return ("should be a number");
        }
        return ();
    },
};

=head3 mediacfg_version

The version of the media_cfg

See L<MEDIACFG VERSION>

=cut

$value->{version} = { section => 'media_info' };

=head3 version

The version of distrib

=cut

$value->{arch} = { section => 'media_info' };

=head3 arch

The arcitecture of the distribution

=cut

$value->{suppl} = { section => 'media_info' };

=head3 suppl

This tag is used to change installer behavior, when set, user should be allow
to add media not provided by this distribution.

=cut

$value->{askmedia} = { section => 'media_info' };

=head3 askmedia

This tag is used to change installer behavior, when set, user should be prompt
before adding each media.

=cut

$value->{branch} = { section => 'media_info' };

=head3 branch

The branch of the distribution.

=cut

$value->{product} = { section => 'media_info' };

=head3 product

The name of the product, 'Download' by default

=cut

$value->{minor} = { section => 'media_info' };

=head3 minor

No documentation

=cut

$value->{subversion} = { section => 'media_info' };

=head3 subversion

No documentation

=cut

=head2 MEDIA VALUES

=cut

foreach (qw(hdlist name synthesis pubkey)) {
    $value->{$_} = { };
}

=head3 name

The name of the media. If unset, the section is the name.

=head3 hdlist

The hdlist file holding rpm infos for the media

=head3 synthesis

The synthesis file holding rpm infos for the media

=head3 pubkey

The file holding public gpg key used to sign rpms in this media.

=cut

$value->{srpms} = { deny => 'rpms', cross => 'rpms', ismedialist => 1 };

=head3 srpms

If the media hold binaries rpms, this parameter contains
the list of medias holding corresponding sources rpms.

=cut

$value->{rpms} = { deny => 'srpms', cross => 'srpms', ismedialist => 1 };

=head3 rpms

If the media hold sources rpms, this parameter contains
the list of media holding binaries rpms build by srpms from this media.

=cut

$value->{updates_for} = { ismedialist => 1 };

=head3 updates_for

If the media contain updates, it contain the list of media for which
rpms are updates.

=cut

$value->{debug_for} = { ismedialist => 1 };

=head3 debug_for

If the media contain debug rpms, it contain the list of media for which
rpms are debug rpms.

=cut

$value->{noauto} = {};

=head3 noauto

This value is used by tools to assume if the media should automatically
added to the config (urpmi).

=cut

$value->{size} = {
    validation => sub {
        my ($v) = @_;
        if ($v =~ /^(\d+)(\w)?$/) {
            if ($2) {
                if (! grep { lc($2) eq $_ } qw(k m g t p)) {
                    return("wrong unit");
                }
            }
            return;
        } else {
            return ("malformed value");
        }
    },
};

=head3 size

The size of the media. The value is suffixed by the unit.

=cut

# valid_param($media, $var, $val)
#
# Return a list of errors (if any) about having such value in the config

sub _valid_param {
    my ($media, $var, $val) = @_[-3..-1];
    if (!exists($value->{$var})) {
        return ("unknow var");
    }
    $media ||= 'media_info'; # assume default
    my @errors;
    if ($value->{$var}{section} && $value->{$var}{section} ne $media) {
        push(@errors, "wrong section: should be in $value->{$var}{section}");
    }
    if ($value->{$var}{validation}) {
        push(@errors, $value->{$var}{validation}->($val));
    }
    return @errors;
}

# Retun a hash containing information about $var

sub _value_info {
    my ($var) = $_[-1];
    if (exists($value->{$var})) {
        return $value->{$var}
    }
    return;
}

1;

__END__

=head1 AUTHOR

Olivier Thauvin <nanardon@mandriva.org>

=head1 LICENSE AND COPYRIGHT

(c) 2005, 2006, 2007 Olivier Thauvin
(c) 2005, 2006, 2007 Mandriva

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

=cut