Changeset 178

Show
Ignore:
Timestamp:
03/02/07 20:55:20 (2 years ago)
Author:
ingy
Message:
 r3468@skinny:  ingy | 2007-02-26 21:08:37 -0800
 More major config refactoring
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/Kwiki/Command/Base.pm

    r156 r178  
    2525    $self->hub->$class_id->quiet($self->quiet); 
    2626    $self->hub->$class_id->extract_files; 
    27     $self->msg("\n"); 
     27    $self->msg(" \n"); 
    2828} 
    2929 
  • trunk/src/core/Kwiki/kwiki

    r158 r178  
    3131 
    3232BEGIN { 
    33     my @env_files = qw(_kwiki .ht_kwiki); 
    34     push @env_files, "$ENV{HOME}/.kwiki/_kwiki" if defined $ENV{HOME}; 
     33    my @env_files = qw(kwiki.env .ht-kwiki.env); 
     34    push @env_files, "$ENV{HOME}/.kwiki/kwiki.env" if defined $ENV{HOME}; 
    3535    my $fh; 
    36     for (@env_files) { open $fh, $_ and last } 
    37     do { $ENV{$1} ||= $2 if /^(\w+)\s*=\s*['"]?(.*?)['"]?\s*$/ } for <$fh>; 
     36    for (@env_files) { 
     37        if (open $fh, $_) { 
     38            do { 
     39                $ENV{$1} ||= $2 if /^(\w+)\s*=\s*['"]?(.*?)['"]?\s*$/; 
     40            } for <$fh>; 
     41            last; 
     42        } 
     43    } 
    3844 
    3945    if ($ENV{KWIKI_TEST_CLEAN}) { 
  • trunk/src/core/Kwiki/lib/Kwiki/Boot/Base.pm

    r172 r178  
    3030 
    3131    $self->kwiki($main); 
     32    $self->setup; 
     33} 
     34 
     35sub setup { 
     36    $self->add_default_classes; 
     37    $self->add_configs_files; 
     38    $self->add_plugins_files; 
    3239} 
    3340 
     
    4047    } 
    4148} 
     49 
     50sub add_plugins_files { 
     51    for my $file ($self->hub->paths->all_filepaths('plugins')) { 
     52        $self->config->add_plugins_file($file); 
     53    } 
     54} 
  • trunk/src/core/Kwiki/lib/Kwiki/Boot/V1.pm

    r177 r178  
    66const hub_class => 'Kwiki::Hub'; 
    77 
    8 sub init { 
    9     $self->SUPER::init; 
    10     $self->add_default_classes; 
    11     $self->add_configs_files; 
    12     $self->add_plugins_files; 
    13 } 
    14  
    158sub add_configs_files { 
    169    $self->config->add_file('config.yaml'); 
     
    1811        $self->config->add_config($filepath, 1); 
    1912    } 
    20 } 
    21  
    22 sub add_plugins_files { 
    23     my $plugins_used = {}; 
    24     my $plugin_classes = []; 
    25     for my $file ($self->hub->paths->all_filepaths('plugins')) { 
    26         my @plugins = grep { 
    27             s/^([\+\-]?[\w\:]+)\s*$/$1/; 
    28         } io($file)->slurp; 
    29         for my $class (@plugins) { 
    30             if ($class =~ s/^\-//) { 
    31                 if ($plugins_used->{$class}) { 
    32                     delete $plugins_used->{$class}; 
    33                     @$plugin_classes = grep { $_ ne $class } @$plugin_classes; 
    34                 } 
    35             } 
    36             else { 
    37                 $class =~ s/^\+//; 
    38                 unless ($plugins_used->{$class}) { 
    39                     push @$plugin_classes, $class; 
    40                     $plugins_used->{$class} = 1; 
    41                 } 
    42             } 
    43         } 
    44     } 
    45     $self->config->plugin_classes($plugin_classes); 
    4613} 
    4714 
  • trunk/src/core/Kwiki/lib/Kwiki/Boot/V2.pm

    r172 r178  
    66const hub_class => 'Kwiki::Hub'; 
    77 
    8 sub init { 
    9     $self->add_default_classes; 
    10     $self->add_configs_files; 
    11     $self->add_plugins_files; 
    12 } 
    13  
    148sub add_configs_files { 
    159    # TODO Get all config locations from hub->paths 
    16     $self->config->add_path('config'); 
    1710    $self->config->add_file('config.yaml'); 
    18 
    19  
    20 sub add_plugins_files { 
    21     # TODO Get all plugins files from hub->paths 
    22     $self->config->add_plugins_file('plugins'); 
     11    my $config = $ENV{KWIKI_LOCAL_CONFIG_LOCATION}; 
     12    $self->config->add_config($config, 1) 
     13        if $config and -f $config; 
    2314} 
    2415 
  • trunk/src/core/Kwiki/lib/Kwiki/Command/V2.pm

    r172 r178  
    88    $self->create_www_link; 
    99    $self->add_new_default_config; 
     10#     XXX $self->hub->files; 
    1011    $self->install('files'); 
    1112    $self->create_database; 
     
    1617 
    1718sub create_plugin_scratch { 
    18     $ENV{KWIKI_PLUGIN_SCRATCH_FILEPATH} or return; 
    19     my $plugin = io($ENV{KWIKI_PLUGIN_SCRATCH_FILEPATH}) or return; 
     19    $ENV{KWIKI_PLUGIN_SCRATCH_LOCATION} or return; 
     20    my $plugin = io($ENV{KWIKI_PLUGIN_SCRATCH_LOCATION}) or return; 
    2021    $plugin->mkpath unless $plugin->exists; 
    2122} 
    2223 
    2324sub create_database { 
    24     my $target = $ENV{KWIKI_DATABASE_FILEPATH} or return; 
    25     my $source = $self->hub->paths->find_first_filepath('database'); 
    26     unless (-d $target) { 
    27         mkdir $target or die; 
    28     } 
    29     system("cp $source/* $target") == 0 or die; 
     25    my @source_dirs = $self->hub->paths->all_filepaths('database'); 
     26    my $target_path = $ENV{KWIKI_DATABASE_LOCATION} or return; 
     27    my $target = io($target_path); 
     28    $target->mkpath unless $target->exists; 
     29     
     30    for my $source_dir (reverse @source_dirs) { 
     31        for my $source_file (io($source_dir)->all_files) { 
     32            my $target_file = $target_path . '/' . $source_file->filename; 
     33            $source_file > io($target_file) 
     34                unless -e $target_file; 
     35        } 
     36    } 
    3037} 
    3138 
     
    4249    die "No such directory '$flavor_path'" 
    4350        unless -d $flavor_path and -d "$flavor_path/www"; 
    44     my $www = $ENV{KWIKI_WWW_FILEPATH} or die; 
     51    my $www = $ENV{KWIKI_WWW_LOCATION} or die; 
    4552    io->link("$www/__")->assert->symlink("$flavor_path/www"); 
    4653} 
     
    6269 
    6370sub kwiki_env_path { 
    64     for (qw(_kwiki .ht_kwiki)) { 
     71    for (qw(kwiki.env .ht-kwiki.env)) { 
    6572        return $_ if -e $_; 
    6673    } 
    67     return '_kwiki'; 
     74    return 'kwiki.env'; 
    6875} 
    6976 
     
    8087    return <<'...'; 
    8188KWIKI_BOOT=V2 
     89KWIKI_BASE= 
    8290KWIKI_LIB_PATH=lib 
    83 KWIKI_BASE= 
    8491KWIKI_FLAVOR=Vanilla 
    8592KWIKI_TEST_CLEAN=0 
    86 KWIKI_PLUGIN_SCRATCH_FILEPATH=plugin 
    87 KWIKI_DATABASE_FILEPATH=database 
    88 KWIKI_WWW_FILEPATH=www 
     93KWIKI_PLUGIN_SCRATCH_LOCATION=plugin 
     94KWIKI_DATABASE_LOCATION=database 
     95KWIKI_WWW_LOCATION=www 
     96KWIKI_LOCAL_CONFIG_LOCATION=config.yaml 
    8997... 
    9098} 
     
    175183 
    176184sub set_permissions { 
    177     my $database = $ENV{KWIKI_DATABASE_FILEPATH} or die; 
    178     my $plugin = $ENV{KWIKI_PLUGIN_SCRATCH_FILEPATH} or die; 
     185    my $database = $ENV{KWIKI_DATABASE_LOCATION} or die; 
     186    my $plugin = $ENV{KWIKI_PLUGIN_SCRATCH_LOCATION} or die; 
    179187    my $umask = umask 0000; 
    180188    chmod 0777, $database, $plugin; 
  • trunk/src/core/Kwiki/lib/Kwiki/Files/V2.pm

    r165 r178  
    1313BEGIN { 
    1414    my $fh; 
    15     for (qw(_kwiki .ht_kwiki)) { open $fh, $_ and last } 
     15    for (qw(kwiki.env .ht-kwiki.env)) { open $fh, $_ and last } 
    1616    do { $ENV{$1} ||= $2 if /^(\w+)\s*=\s*['"]?(.*?)['"]?\s*$/ } for <$fh>; 
    1717} 
  • trunk/src/core/Kwiki/lib/Kwiki/Paths/V1.pm

    r173 r178  
    11package Kwiki::Paths::V1; 
    22use Kwiki::Base -Base; 
     3use Cwd qw(cwd abs_path); 
    34 
    4 sub all_filepaths { 
    5     my $filepath = shift; 
    6     if ($filepath eq 'config') { 
    7         return ('./config'); 
    8     } 
    9     my @paths; 
    10     push @paths, $filepath if -f $filepath; 
     5# All directories in the config chain (starting at root). 
     6sub all_paths { 
     7    my $dir = cwd(); 
     8    my @paths = ($dir); 
    119    while (1) { 
    12         $filepath = "../$filepath"; 
    13         last unless -f $filepath; 
    14         unshift @paths, $filepath; 
     10        my $updir = abs_path("$dir/..") or last; 
     11        last if $dir eq $updir; 
     12        $dir = $updir; 
     13        last unless -e "$dir/config.yaml"; 
     14        unshift @paths, $dir; 
    1515    } 
    1616    return @paths; 
    1717} 
     18 
     19# All filepaths in the chain ending with the given file 
     20sub all_filepaths { 
     21    my $file = shift; 
     22    return ('./config') if $file eq 'config'; 
     23 
     24    return grep { -e } map "$_/$file", $self->all_paths; 
     25} 
     26 
     27# First filepath in the chain ending with the given file 
     28sub first_filepath { 
     29    return scalar $self->all_paths(shift); 
     30} 
  • trunk/src/core/Kwiki/lib/Kwiki/Paths/V2.pm

    r173 r178  
    11package Kwiki::Paths::V2; 
    22use Kwiki::Base -Base; 
     3use Cwd qw(cwd abs_path); 
    34 
     5field 'all_paths_cache'; 
     6 
     7# All directories in the config chain (starting at root). 
     8sub all_paths { 
     9    my $paths; 
     10#     delete $self->{all_paths_cache} if @_; 
     11#     $paths = $self->all_paths_cache; 
     12#     return @$paths if ref $paths; 
     13    $paths = []; 
     14#     $self->all_paths_cache($paths); 
     15    my $seen = {}; 
     16     
     17    my $dir = cwd(); 
     18    push @$paths, $dir; 
     19    $seen->{$dir} = 1; 
     20 
     21    $dir = $ENV{KWIKI_WWW_LOCATION} or return @$paths; 
     22    $dir = abs_path($dir) or return @$paths; 
     23    return @$paths unless -d $dir; 
     24    return @$paths if $seen->{$dir}; 
     25    push @$paths, $dir; 
     26    $seen->{$dir} = 1; 
     27 
     28    while (-e "$dir/__") { 
     29        $dir = abs_path("$dir/__"); 
     30        last unless -d $dir; 
     31        last if $seen->{$dir}; 
     32        unshift @$paths, $dir; 
     33        $seen->{$dir} = 1; 
     34 
     35        my $updir = abs_path("$dir/.."); 
     36        last unless -d $updir; 
     37        last if $seen->{$updir}; 
     38        unshift @$paths, $updir; 
     39        $seen->{$updir} = 1; 
     40    } 
     41 
     42    return @$paths; 
     43} 
     44 
     45# All filepaths in the chain ending with the given file 
     46sub all_filepaths { 
     47    my $file = shift; 
     48    return grep { -e $_ } map "$_/$file", $self->all_paths(@_); 
     49} 
     50 
     51# First filepath in the chain ending with the given file 
    452sub first_filepath { 
    5     return "$ENV{KWIKI_BASE}/base/database"; 
     53    my @all = $self->all_paths(@_); 
     54    return $all[-1]; 
    655} 
  • trunk/src/core/Spoon/lib/Spoon/Config.pm

    r177 r178  
    6969} 
    7070 
    71 sub add_plugin { 
    72     push @{$self->plugin_classes}, shift; 
     71sub add_plugins_file { 
     72    my $file = shift; 
     73    my $used = {}; 
     74    my $classes = $self->plugin_classes; 
     75    $used->{$_} = 1 for @$classes; 
     76     
     77    my @plugins = grep { 
     78        s/^([\+\-]?[\w\:]+)\s*$/$1/; 
     79    } io($file)->slurp; 
     80 
     81    for my $class (@plugins) { 
     82        if ($class =~ s/^\-//) { 
     83            if ($used->{$class}) { 
     84                delete $used->{$class}; 
     85                @$classes = grep { $_ ne $class } @$classes; 
     86            } 
     87        } 
     88        else { 
     89            $class =~ s/^\+//; 
     90            unless ($used->{$class}) { 
     91                push @$classes, $class; 
     92                $used->{$class} = 1; 
     93            } 
     94        } 
     95    } 
     96 
     97    $self->plugin_classes($classes); 
    7398} 
    74  
    75 sub change_plugin { 
    76     my ($new_class, $old_class) = @_; 
    77     my $pattern = $old_class || do { 
    78         my $temp = $new_class; 
    79         $temp =~ s/^\w+:://; 
    80         '\w+::' . $temp; 
    81     }; 
    82     my $plugins = $self->plugin_classes; 
    83     for (@$plugins) { 
    84         last if s/$pattern/$new_class/; 
    85     } 
    86 } 
  • trunk/src/plugins/miyagawa/Kwiki-FastCGI/lib/Kwiki/FastCGI.pm

    r158 r178  
    4646BEGIN { 
    4747    my $fh; 
    48     for (qw(_kwiki .ht_kwiki)) { open $fh, $_ and last } 
     48    for (qw(kwiki.env .ht-kwiki.env)) { open $fh, $_ and last } 
    4949    do { $ENV{$1} ||= $2 if /^(\w+)\s*=\s*['"]?(.*?)['"]?\s*$/ } for <$fh>; 
    5050}