[Bps-public-commit] Prophet branch, config-gitlike, updated. 0b8bf4fee509f4bffcfe086e4239499d647b83e3
jesse
jesse at bestpractical.com
Tue Jul 7 16:01:25 EDT 2009
The branch, config-gitlike has been updated
via 0b8bf4fee509f4bffcfe086e4239499d647b83e3 (commit)
from 35ff302990eeee5a6a7099b770e27fda9894ba03 (commit)
Summary of changes:
lib/Prophet/Config.pm | 165 +------------------------------------------------
t/aliases.t | 6 +-
2 files changed, 4 insertions(+), 167 deletions(-)
- Log -----------------------------------------------------------------
commit 0b8bf4fee509f4bffcfe086e4239499d647b83e3
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Tue Jul 7 16:01:00 2009 -0400
moved a whole bunch of sd-specific config upgrade stuff out of the prophet core
diff --git a/lib/Prophet/Config.pm b/lib/Prophet/Config.pm
index 292d9a7..654b978 100644
--- a/lib/Prophet/Config.pm
+++ b/lib/Prophet/Config.pm
@@ -20,9 +20,9 @@ override group_set => sub {
# Set a config format version on this config file if
# it doesn't have one already.
- push @$args_ref, {
+ unshift @$args_ref, {
key => 'core.config-format-version',
- value => FORMAT_VERSION,
+ value => $self->FORMAT_VERSION,
} unless _file_has_config_format_version( $filename );
$self->SUPER::group_set($filename, $args_ref);
@@ -151,168 +151,7 @@ sub display_name_for_uuid {
return exists $sources_by_uuid{$uuid} ? $sources_by_uuid{$uuid} : $uuid;
}
-### XXX BACKCOMPAT ONLY! We eventually want to kill this hash, modifier and
-### the following methods.
-
-# None of these need to have values mucked with at all, just the keys
-# migrated from old to new.
-our %KEYS_CONVERSION_TABLE = (
- 'email_address' => 'user.email-address',
- 'default_group_ticket_list' => 'ticket.list.default-group',
- 'default_sort_ticket_list' => 'ticket.list.default-sort',
- 'summary_format_ticket' => 'ticket.summary-format',
- 'default_summary_format' => 'record.summary-format',
- 'common_ticket_props' => 'ticket.common-props',
- 'disable_ticket_show_history_by_default' => 'ticket.show.disable-history',
-);
-
-override load => sub {
- my $self = shift;
-
- Prophet::CLI->end_pager();
-
- # Do backcompat stuff.
- for my $file ( ($self->_old_app_config_file, $self->dir_file,
- $self->user_file, $self->global_file) ) {
- my $content = -f $file ? Prophet::Util->slurp($file) : '[';
- # config file is old
-
- # Also "converts" empty files but that's fine. If it ever
- # does happen, we get the positive benefit of writing the
- # config format to it.
- if ( $content !~ /\[/ ) {
-
- $self->convert_ancient_config_file($file);
- }
-
- }
-
- Prophet::CLI->start_pager();
-
- # Do a regular load.
- $self->SUPER::load;
-};
-
-
-sub convert_ancient_config_file {
- my $self = shift;
- my $file = shift;
- print "Detected old format config file $file. Converting to ".
- "new format... ";
-
- # read in and parse old config
- my $config = { _sources => {}, _aliases => {} };
- $self->_load_old_config_from_file( $file, $config );
- my $aliases = delete $config->{_aliases};
- my $sources = delete $config->{_sources};
-
- # new configuration will include a config format version #
- my @config_to_set = ( {
- key => 'core.config-format-version',
- value => FORMAT_VERSION,
- } );
-
- # convert its keys to new-style keys by comparing to a conversion
- # table
- for my $key ( keys %$config ) {
- die "Unknown key '$key' in old format config file '$file'."
- ." Remove it or ask\non irc.freenode.net #prophet if you"
- ." think this is a bug.\n"
- unless exists $KEYS_CONVERSION_TABLE{$key};
- push @config_to_set, {
- key => $KEYS_CONVERSION_TABLE{$key},
- value => $config->{$key},
- };
- }
- # convert its aliases
- for my $alias ( keys %$aliases ) {
- push @config_to_set, {
- key => "alias.'$alias'",
- value => $aliases->{$alias},
- };
- }
- # convert its sources
- for my $name ( keys %$sources ) {
- my ($url, $uuid) = split(/ \| /, $sources->{$name}, 2);
- push @config_to_set, {
- key => "replica.'$name'.url",
- value => $url,
- }, {
- key => "replica.'$name'.uuid",
- value => $uuid,
- };
- }
- # move the old config file to a backup
- my $backup_file = $file;
- unless ( $self->_deprecated_repo_config_names->{$file} ) {
- $backup_file = "$file.bak";
- rename $file, $backup_file;
- }
-
- # we want to write the new file to a supported filename if
- # it's from a deprecated config name (replica/prophetrc)
- $file = File::Spec->catfile( $self->app_handle->handle->fs_root, 'config' )
- if $self->_deprecated_repo_config_names->{$file};
-
- # write the new config file (with group_set)
- $self->group_set( $file, \@config_to_set, 1);
-
- # tell the user that we're done
- print "done.\nOld config can be found at $backup_file; "
- ,"new config is $file.\n\n";
-
-}
-
-
-sub _deprecated_repo_config_names {
- my $self = shift;
-
- my %filenames = ( File::Spec->catfile( $self->app_handle->handle->fs_root => 'prophetrc' ) => 1 );
-
- return wantarray ? %filenames : \%filenames;
-};
-
-sub _old_app_config_file {
- my $self = shift;
- my $config_env_var
- = $_{config_env_var} ? $_{config_env_var} : 'PROPHET_APP_CONFIG';
-
- return $self->_file_if_exists($ENV{$config_env_var})
- || $self->_file_if_exists( $self->_old_replica_config_file)
- || $self->_file_if_exists( File::Spec->catfile( $ENV{'HOME'} => '.prophetrc' ))
- || $self->_old_replica_config_file
-}
-
-sub _old_replica_config_file {
- my $self = shift;
- return
- $self->_file_if_exists( File::Spec->catfile( $self->app_handle->handle->fs_root => 'config' )) ||
- $self->_file_if_exists( File::Spec->catfile( $self->app_handle->handle->fs_root => 'prophetrc' )) ||
- File::Spec->catfile( $self->app_handle->handle->fs_root => 'config' );
-}
-
-sub _load_old_config_from_file {
- my $self = shift;
- my $file = shift;
- my $config = shift || {};
-
- for my $line (Prophet::Util->slurp($file) ) {
- $line =~ s/\#.*$//; # strip comments
- next unless ($line =~ /^(.*?)\s*=\s*(.*)$/);
- my $key = $1;
- my $val = $2;
- if ($key =~ m!alias\s+(.+)!) {
- $config->{_aliases}->{$1} = $val;
- } elsif ($key =~ m!source\s+(.+)!) {
- $config->{_sources}->{$1} = $val;
- } else {
- $config->{$key} = $val;
- }
- }
- $config->{_aliases} ||= {}; # default aliases is null.
- $config->{_sources} ||= {}; # default to no sources.
-}
sub _file_if_exists {
my $self = shift;
diff --git a/t/aliases.t b/t/aliases.t
index 90a67f8..d15edf4 100644
--- a/t/aliases.t
+++ b/t/aliases.t
@@ -5,12 +5,10 @@ use strict;
use Prophet::Test tests => 33;
use File::Temp qw/tempfile/;
-$ENV{'PROPHET_REPO'} = $Prophet::Test::REPO_BASE . '/repo-' . $$;
$ENV{'PROPHET_APP_CONFIG'} = (tempfile(UNLINK => !$ENV{PROPHET_DEBUG}))[1];
diag("Using config file $ENV{PROPHET_APP_CONFIG}");
# since we don't initialize the db for these tests, make the repo dir
-mkdir $ENV{PROPHET_REPO};
use_ok('Prophet::CLI');
@@ -182,10 +180,10 @@ is_deeply(
# check content in config
my $content;
-open my $fh, '<', $ENV{'PROPHET_APP_CONFIG'}
- or die "failed to open $ENV{'PROPHET_APP_CONFIG'}: $!";
+open my $fh, '<', $ENV{'PROPHET_APP_CONFIG'} or die "failed to open $ENV{'PROPHET_APP_CONFIG'}: $!";
{ local $/; $content = <$fh>; }
is( $content, <<EOF, 'content in config' );
+
[core]
config-format-version = 0
[alias]
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list