~mathiaz/ubuntu/lucid/mysql-dfsg-5.1/zap-bug-552053

« back to all changes in this revision

Viewing changes to mysql-test/lib/My/Config.pm

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-06-25 12:55:45 UTC
  • mfrom: (1.1.2 upstream) (0.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090625125545-m8ogs96zzsri74xe
Tags: 5.1.34-1ubuntu1
* Merge from debian experimental (and 5.0 from main), remaining changes:
  - debian/mysql-server-5.1.config:
    + ask for MySQL root password at priority high instead of medium so
      that the password prompt is seen on a default install. (LP: #319843)
    + don't ask for root password when upgrading from a 5.0 install.
  - debian/control:
    + Make libmysqlclient16-dev a transitional package depending on
      libmysqlclient-dev.
    + Make libmysqlclient-dev conflict with libmysqlclient15-dev.
    + Don't build mysql-server, mysql-client, mysql-common and
      libmysqlclient15-dev binary packages since they're still provided
      by mysql-dfsg-5.0.
    + Make mysql-{client,server}-5.1 packages conflict and
      replace mysql-{client,server}-5.0, but not provide
      mysql-{client,server}.
    + Depend on a specific version of mysql-common rather than the src
      version of mysql-dfsg-5.1 since mysql-common is currently part of
      mysql-dfsg-5.0.
    + Lower mailx from a Recommends to a Suggests to avoid pulling in
      a full MTA on all installs of mysql-server. (LP: #259477)
  - debian/rules:
    + added -fno-strict-aliasing to CFLAGS to get around mysql testsuite
      build failures.
    + install mysql-test and sql-bench to /usr/share/mysql/ rather than
      /usr/.
  - debian/additions/debian-start.inc.sh: support ANSI mode (LP: #310211)
  - Add AppArmor profile:
    - debian/apparmor-profile: apparmor profile.
    - debian/rules, debian/mysql-server-5.0.files: install apparmor profile.
    - debian/mysql-server-5.0.dirs: add etc/apparmor.d/force-complain
    - debian/mysql-server-5.0.postrm: remove symlink in force-complain/ on
      purge.
    - debian/mysql-server-5.1.README.Debian: add apparmor documentation.
    - debian/additions/my.cnf: Add warning about apparmor. (LP: #201799)
    - debian/mysql-server-5.1.postinst: reload apparmor profiles.
  - debian/additions/my.cnf: remove language option. Error message files are
    located in a different directory in MySQL 5.0. Setting the language
    option to use /usr/share/mysql/english breaks 5.0. Both 5.0 and 5.1
    use a default value that works. (LP: #316974)
  - debian/mysql-server-5.1.mysql.init:
    + Clearly indicate that we do not support running multiple instances
      of mysqld by duplicating the init script.
      (closes: #314785, #324834, #435165, #444216)
    + Properly parameterize all existing references to the mysql config
      file (/etc/mysql/my.cnf).
  - debian/mysql-server-5.0.postinst: Clear out the second password
    when setting up mysql. (LP: #344816)
  - mysql-server-core-5.1 package for files needed by Akonadi:
    + debian/control: create mysql-server-core-5.1 package.
    + debian/mysql-server-core-5.1.files, debian/mysql-server-5.1.files:
      move core mysqld files to mysql-server-core-5.1 package.
  - Don't package sql-bench and mysql-test file.
* Dropped changes:
  - debian/patches/92_ssl_test_cert.dpatch: certificate expiration in
    test suite (LP: #323755). Included upstream.
* Dropped from 5.0:
  - apparmor profile:
    - debian/control: Recommends apparmor >= 2.1+1075-0ubuntu6. All version
      of apparmor-profile (>hardy) are higher than this version.
    - debian/mysql-server-5.0.preinst: create symlink for force-complain/
      on pre-feisty upgrades, upgrades where apparmor-profiles profile is
      unchanged (ie non-enforcing) and upgrades where the profile
      doesn't exist. Support for pre-hardy upgrades is no longer needed.
* debian/mysql-server-5.1.postinst: fix debian-sys-maint user creation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
use strict;
6
6
use warnings;
 
7
use Carp;
7
8
 
8
9
 
9
10
sub new {
26
27
  return $self->{value};
27
28
}
28
29
 
 
30
sub option {
 
31
  my ($self)= @_;
 
32
  my $name=  $self->{name};
 
33
  my $value= $self->{value};
 
34
 
 
35
  my $opt= $name;
 
36
  $opt= "$name=$value" if ($value);
 
37
  $opt= "--$opt" unless ($opt =~ /^--/);
 
38
  return $opt;
 
39
}
29
40
 
30
41
package My::Config::Group;
31
42
 
32
43
use strict;
33
44
use warnings;
34
 
 
 
45
use Carp;
35
46
 
36
47
sub new {
37
48
  my ($class, $group_name)= @_;
68
79
  return undef unless defined $option;
69
80
 
70
81
  # Remove from the hash
71
 
  delete($self->{options_by_name}->{$option_name}) or die;
 
82
  delete($self->{options_by_name}->{$option_name}) or croak;
72
83
 
73
84
  # Remove from the array
74
85
  @{$self->{options}}= grep { $_->name ne $option_name } @{$self->{options}};
88
99
  return $self->{name};
89
100
}
90
101
 
 
102
sub suffix {
 
103
  my ($self)= @_;
 
104
  # Everything in name from the last .
 
105
  my @parts= split(/\./, $self->{name});
 
106
  my $suffix= pop(@parts);
 
107
  return ".$suffix";
 
108
}
 
109
 
 
110
sub after {
 
111
  my ($self, $prefix)= @_;
 
112
  die unless defined $prefix;
 
113
 
 
114
  # everything after $prefix
 
115
  my $name= $self->{name};
 
116
  if ($name =~ /^\Q$prefix\E(.*)$/)
 
117
  {
 
118
    return $1;
 
119
  }
 
120
  die "Failed to extract the value after '$prefix' in $name";
 
121
}
 
122
 
 
123
 
 
124
sub split {
 
125
  my ($self)= @_;
 
126
  # Return an array with name parts
 
127
  return split(/\./, $self->{name});
 
128
}
91
129
 
92
130
#
93
131
# Return a specific option in the group
100
138
 
101
139
 
102
140
#
103
 
# Return a specific value for an option in the group
 
141
# Return value for an option in the group, fail if it does not exist
104
142
#
105
143
sub value {
106
144
  my ($self, $option_name)= @_;
107
145
  my $option= $self->option($option_name);
108
146
 
109
 
  die "No option named '$option_name' in this group"
 
147
  croak "No option named '$option_name' in group '$self->{name}'"
110
148
    if ! defined($option);
111
149
 
112
150
  return $option->value();
113
151
}
114
152
 
115
153
 
 
154
#
 
155
# Return value for an option if it exist
 
156
#
 
157
sub if_exist {
 
158
  my ($self, $option_name)= @_;
 
159
  my $option= $self->option($option_name);
 
160
 
 
161
  return undef if ! defined($option);
 
162
 
 
163
  return $option->value();
 
164
}
 
165
 
 
166
 
116
167
package My::Config;
117
168
 
118
169
use strict;
119
170
use warnings;
 
171
use Carp;
120
172
use IO::File;
121
173
use File::Basename;
122
174
 
132
184
 
133
185
  my $self= bless { groups => [] }, $class;
134
186
  my $F= IO::File->new($path, "<")
135
 
    or die "Could not open '$path': $!";
 
187
    or croak "Could not open '$path': $!";
136
188
 
137
189
  while (  my $line= <$F> ) {
138
190
    chomp($line);
139
191
 
140
192
    # [group]
141
 
    if ( $line =~ /\[(.*)\]/ ) {
 
193
    if ( $line =~ /^\[(.*)\]/ ) {
142
194
      # New group found
143
195
      $group_name= $1;
144
196
      #print "group: $group_name\n";
149
201
    # Magic #! comments
150
202
    elsif ( $line =~ /^#\!/) {
151
203
      my $magic= $line;
152
 
      die "Found magic comment '$magic' outside of group"
 
204
      croak "Found magic comment '$magic' outside of group"
153
205
        unless $group_name;
154
206
 
155
207
      #print "$magic\n";
171
223
    # !include <filename>
172
224
    elsif ( $line =~ /^\!include\s*(.*?)\s*$/ ) {
173
225
      my $include_file_name= dirname($path)."/".$1;
174
 
      # Check that the file exists
175
 
      die "The include file '$include_file_name' does not exist"
 
226
 
 
227
      # Check that the file exists relative to path of first config file
 
228
      if (! -f $include_file_name){
 
229
        # Try to include file relativ to current dir
 
230
        $include_file_name= $1;
 
231
      }
 
232
      croak "The include file '$include_file_name' does not exist"
176
233
        unless -f $include_file_name;
177
234
 
178
235
      $self->append(My::Config->new($include_file_name));
182
239
    elsif ( $line =~ /^([\@\w-]+)\s*$/ ) {
183
240
      my $option= $1;
184
241
 
185
 
      die "Found option '$option' outside of group"
 
242
      croak "Found option '$option' outside of group"
186
243
        unless $group_name;
187
244
 
188
245
      #print "$option\n";
194
251
      my $option= $1;
195
252
      my $value= $2;
196
253
 
197
 
      die "Found option '$option=$value' outside of group"
 
254
      croak "Found option '$option=$value' outside of group"
198
255
        unless $group_name;
199
256
 
200
257
      #print "$option=$value\n";
201
258
      $self->insert($group_name, $option, $value);
202
259
    } else {
203
 
      die "Unexpected line '$line' found in '$path'";
 
260
      croak "Unexpected line '$line' found in '$path'";
204
261
    }
205
262
 
206
263
  }
231
288
    # Add the option to the group
232
289
    $group->insert($option, $value, $if_not_exist);
233
290
  }
 
291
  return $group;
234
292
}
235
293
 
236
294
#
240
298
  my ($self, $group_name, $option_name)= @_;
241
299
  my $group= $self->group($group_name);
242
300
 
243
 
  die "group '$group_name' does not exist"
 
301
  croak "group '$group_name' does not exist"
244
302
    unless defined($group);
245
303
 
246
304
  $group->remove($option_name) or
247
 
    die "option '$option_name' does not exist";
 
305
    croak "option '$option_name' does not exist";
248
306
}
249
307
 
250
308
 
267
325
#
268
326
sub _group_insert {
269
327
  my ($self, $group_name)= @_;
270
 
  caller eq __PACKAGE__ or die;
 
328
  caller eq __PACKAGE__ or croak;
271
329
 
272
330
  # Check that group does not already exist
273
 
  die "Group already exists" if $self->group_exists($group_name);
 
331
  croak "Group already exists" if $self->group_exists($group_name);
274
332
 
275
333
  my $group= My::Config::Group->new($group_name);
276
334
  push(@{$self->{groups}}, $group);
354
412
  my ($self, $group_name, $option_name)= @_;
355
413
  my $group= $self->group($group_name);
356
414
 
357
 
  die "group '$group_name' does not exist"
 
415
  croak "group '$group_name' does not exist"
358
416
    unless defined($group);
359
417
 
360
418
  my $option= $group->option($option_name);
361
 
  die "option '$option_name' does not exist"
 
419
  croak "option '$option_name' does not exist"
362
420
    unless defined($option);
363
421
 
364
422
  return $option->value();
372
430
  my ($self, $group_name, $option_name)= @_;
373
431
  my $group= $self->group($group_name);
374
432
 
375
 
  die "group '$group_name' does not exist"
 
433
  croak "group '$group_name' does not exist"
376
434
    unless defined($group);
377
435
 
378
436
  my $option= $group->option($option_name);
412
470
# Save the config to named file
413
471
#
414
472
sub save {
415
 
    my ($self, $path)= @_;
416
 
    my $F= IO::File->new($path, ">")
417
 
        or die "Could not open '$path': $!";
418
 
    print $F $self;
419
 
    undef $F; # Close the file
 
473
  my ($self, $path)= @_;
 
474
  my $F= IO::File->new($path, ">")
 
475
    or croak "Could not open '$path': $!";
 
476
  print $F $self;
 
477
  undef $F; # Close the file
420
478
}
421
479
 
422
480
1;