Changeset 172

Show
Ignore:
Timestamp:
02/23/07 15:51:49 (2 years ago)
Author:
ingy
Message:
 r3453@skinny:  ingy | 2007-02-22 17:00:55 -0800
 Some seriously refactoring of the bootstrap and config process.
 Seems to work at this point, so checking in.
 More to come.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/core/Kwiki/lib/Kwiki/Boot.pm

    r151 r172  
    11package Kwiki::Boot; 
    22use Kwiki::Base -Base; 
    3  
    4 field 'config'; 
    5 field 'kwiki'; 
    6  
    7 sub new { 
    8     $self = $self->SUPER::new(@_); 
    9     $self->init(); 
    10     return $self; 
    11 } 
    12  
    13 sub init { 
    14     for my $type (qw(main config hub)) { 
    15         my $method = "${type}_class"; 
    16         my $class = $self->$method; 
    17         eval "use $class; 1" or die $@; 
    18     } 
    19  
    20     my $config = $self->config_class->new(@_); 
    21     $self->config($config); 
    22  
    23     my $hub = $self->hub_class->new; 
    24  
    25     my $main = $self->main_class->new; 
    26     $hub->main($main); 
    27     $hub->config($config); 
    28  
    29     $self->kwiki($main); 
    30 } 
    313 
    324sub boot { 
  • trunk/src/core/Kwiki/lib/Kwiki/Boot/V1.pm

    r160 r172  
    11package Kwiki::Boot::V1; 
    2 use Kwiki::Boot -Base; 
     2use Kwiki::Boot::Base -Base; 
    33 
    44const main_class => 'Kwiki'; 
     
    77 
    88sub init { 
    9     $self->SUPER::init('config*.*')
     9    $self->SUPER::init
    1010    $self->add_default_classes; 
    1111    $self->add_configs_files; 
     
    1414 
    1515sub add_configs_files { 
    16     $self->config->add_path('config'); 
    1716    $self->config->add_file('config.yaml'); 
     17    for my $filepath (glob 'config*.*') { 
     18        $self->config->add_filepath($filepath); 
     19    } 
    1820} 
    1921 
     
    2325 
    2426sub add_default_classes { 
    25     my %default = ( 
     27    my $default = { 
    2628        cgi_class => 'Kwiki::CGI', 
    2729        command_class => 'Kwiki::Command::V1', 
    28         config_class => 'Kwiki::Config', 
    2930        cookie_class => 'Kwiki::Cookie', 
    3031        css_class => 'Kwiki::CSS', 
     
    3233        headers_class => 'Spoon::Headers', 
    3334        hooks_class => 'Spoon::Hooks', 
    34         hub_class => 'Kwiki::Hub', 
    3535        javascript_class => 'Kwiki::Javascript', 
    3636        pages_class => 'Kwiki::Pages', 
     37        paths_class => 'Kwiki::Paths::V1', 
    3738        preferences_class => 'Kwiki::Preferences', 
    3839        registry_class => 'Kwiki::Registry', 
    3940        template_class => 'Kwiki::Template::TT2', 
    4041        users_class => 'Kwiki::Users', 
    41     ); 
    42     while (my($key, $val) = each %default) { 
    43         unless (defined $self->config->{$key}) { 
    44             $self->config->add_config({ $key => $val }); 
    45         } 
    46     } 
     42    }; 
     43    $self->SUPER::add_default_classes($default); 
    4744} 
    48  
  • trunk/src/core/Kwiki/lib/Kwiki/Boot/V2.pm

    r160 r172  
    11package Kwiki::Boot::V2; 
    2 use Kwiki::Boot -Base; 
     2use Kwiki::Boot::Base -Base; 
    33 
    44const main_class => 'Kwiki'; 
     
    77 
    88sub init { 
    9     $self->SUPER::init('config*.*'); 
    109    $self->add_default_classes; 
    1110    $self->add_configs_files; 
     
    1413 
    1514sub add_configs_files { 
     15    # TODO Get all config locations from hub->paths 
    1616    $self->config->add_path('config'); 
    1717    $self->config->add_file('config.yaml'); 
     
    1919 
    2020sub add_plugins_files { 
     21    # TODO Get all plugins files from hub->paths 
    2122    $self->config->add_plugins_file('plugins'); 
    2223} 
    2324 
    2425sub add_default_classes { 
    25     my %default = ( 
     26    my $default = { 
    2627        cgi_class => 'Kwiki::CGI', 
    2728        command_class => 'Kwiki::Command::V2', 
    28         config_class => 'Kwiki::Config', 
    2929        cookie_class => 'Kwiki::Cookie', 
    3030        css_class => 'Kwiki::CSS', 
     
    3232        headers_class => 'Spoon::Headers', 
    3333        hooks_class => 'Spoon::Hooks', 
    34         hub_class => 'Kwiki::Hub', 
    3534        javascript_class => 'Kwiki::Javascript', 
    3635        pages_class => 'Kwiki::Pages', 
     36        paths_class => 'Kwiki::Paths::V2', 
    3737        preferences_class => 'Kwiki::Preferences', 
    3838        registry_class => 'Kwiki::Registry', 
    3939        template_class => 'Kwiki::Template::TT2', 
    4040        users_class => 'Kwiki::Users', 
    41     ); 
    42     while (my($key, $val) = each %default) { 
    43         unless (defined $self->config->{$key}) { 
    44             $self->config->add_config({ $key => $val }); 
    45         } 
    46     } 
     41    }; 
     42    $self->SUPER::add_default_classes($default); 
    4743} 
    48  
  • trunk/src/core/Kwiki/lib/Kwiki/Command/V1.pm

    r161 r172  
    5050# 
    5151# privacy_group: 
     52END 
    5253 
    5354    $self->create_new_view_plugins; 
  • trunk/src/core/Kwiki/lib/Kwiki/Command/V2.pm

    r161 r172  
    44sub handle_new { 
    55    $self->assert_directory(shift, 'Kwiki'); 
     6    $self->update_kwiki_env_file; 
     7    $self->apply_kwiki_env_file; 
     8    $self->create_www_link; 
    69    $self->add_new_default_config; 
    710    $self->install('files'); 
     11    $self->create_database; 
     12    $self->create_plugin_scratch; 
    813    $self->set_permissions; 
    914    $self->finished_msg; 
    1015} 
    1116 
     17sub create_plugin_scratch { 
     18    $ENV{KWIKI_PLUGIN_SCRATCH_FILEPATH} or return; 
     19    my $plugin = io($ENV{KWIKI_PLUGIN_SCRATCH_FILEPATH}) or return; 
     20    $plugin->mkpath unless $plugin->exists; 
     21} 
     22 
     23sub 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; 
     30} 
     31 
     32sub apply_kwiki_env_file { 
     33    my $env = $self->parse_env(io($self->kwiki_env_path)->all); 
     34    for my $k (keys %$env) { 
     35        next if defined $ENV{$k}; 
     36        $ENV{$k} = $env->{$k} if length($env->{$k}); 
     37    } 
     38} 
     39 
     40sub create_www_link { 
     41    my $flavor_path = $ENV{KWIKI_BASE} . '/flavor/' . $ENV{KWIKI_FLAVOR}; 
     42    die "No such directory '$flavor_path'" 
     43        unless -d $flavor_path and -d "$flavor_path/www"; 
     44    my $www = $ENV{KWIKI_WWW_FILEPATH} or die; 
     45    io->link("$www/__")->assert->symlink("$flavor_path/www"); 
     46} 
     47 
     48sub update_kwiki_env_file { 
     49    my $env_file = io($self->kwiki_env_path); 
     50    my $env_text = $env_file->exists  
     51        ? $env_file->all 
     52        : $self->default_kwiki_env; 
     53    my $env = $self->parse_env($env_text); 
     54    for my $k (keys %ENV) { 
     55        next unless exists $env->{$k}; 
     56        my $v = $ENV{$k}; 
     57        $v = '' unless defined $v; 
     58        $env_text =~ s/^$k=.*$/$k=$v/m; 
     59    } 
     60    $env_file->print($env_text); 
     61} 
     62 
     63sub kwiki_env_path { 
     64    for (qw(_kwiki .ht_kwiki)) { 
     65        return $_ if -e $_; 
     66    } 
     67    return '_kwiki'; 
     68} 
     69 
     70sub parse_env { 
     71    my $text = shift; 
     72    my $env = {}; 
     73    for (split /\n/, $text) { 
     74        $env->{$1} ||= $2 if /^(\w+)\s*=\s*['"]?(.*?)['"]?\s*$/; 
     75    } 
     76    return $env; 
     77} 
     78 
     79sub default_kwiki_env { 
     80    return <<'...'; 
     81KWIKI_BOOT=V2 
     82KWIKI_LIB_PATH=lib 
     83KWIKI_BASE= 
     84KWIKI_FLAVOR=Vanilla 
     85KWIKI_TEST_CLEAN=0 
     86KWIKI_PLUGIN_SCRATCH_FILEPATH=plugin 
     87KWIKI_DATABASE_FILEPATH=database 
     88KWIKI_WWW_FILEPATH=www 
     89... 
     90} 
     91 
    1292sub handle_new_view { 
     93    die; 
    1394    $self->assert_directory(shift, 'kwiki view'); 
    1495    die "Parent directory does not look like a Kwiki installation" 
     
    34115# 
    35116# privacy_group: 
     117END 
    36118 
    37119    $self->create_new_view_plugins; 
     
    60142    $self->hub->config->add_config( 
    61143        { 
    62             display_class => 'Kwiki::Display', 
    63             edit_class => 'Kwiki::Edit', 
    64144            files_class => 'Kwiki::Files::V2', 
    65             theme_class => 'Kwiki::Theme::Basic', 
    66             toolbar_class => 'Kwiki::Toolbar', 
    67             status_class => 'Kwiki::Status', 
    68             widgets_class => 'Kwiki::Widgets', 
    69145        } 
    70146    ); 
     
    77153 
    78154sub handle_update { 
     155    die; 
    79156    chdir io->dir(shift || '.')->assert->open . ''; 
    80157    die "Can't update non Kwiki directory!\n" 
     
    87164 
    88165sub handle_update_all { 
     166    die; 
    89167    my @dirs = (io->curdir, io->curdir->All_Dirs); 
    90168    while (my $dir = shift @dirs) { 
     
    97175 
    98176sub set_permissions { 
     177    my $database = $ENV{KWIKI_DATABASE_FILEPATH} or die; 
     178    my $plugin = $ENV{KWIKI_PLUGIN_SCRATCH_FILEPATH} or die; 
    99179    my $umask = umask 0000; 
    100     chmod 0777, qw(database plugin)
    101     chmod 0666, qw(database/HomePage)
     180    chmod 0777, $database, $plugin
     181    chmod 0666, glob "$database/*"
    102182    chmod 0755, qw(index.cgi); 
    103183    umask $umask; 
  • trunk/src/core/Kwiki/lib/Kwiki/Config.pm

    r138 r172  
    66const class_title => 'Kwiki Configuration'; 
    77field script_name => ''; 
    8 field path => []; 
    98 
    109sub add_plugins_file { 
     
    6261 
    6362sub add_file { 
    64     my $file = shift 
    65       or return; 
    66     my $file_path = ''; 
    67     for (@{$self->path}) { 
    68         $file_path = "$_/$file", last 
    69           if -f "$_/$file"; 
    70     } 
    71     return unless $file_path; 
    72     my $hash = $self->hash_from_file($file_path); 
     63    my $file = shift; 
     64    my $config_path = $self->hub->paths->lookup_path('config'); 
     65    for my $dir (@$config_path) { 
     66        my $filepath = "$dir/$file"; 
     67        $self->add_filepath($filepath) 
     68          if -f $filepath; 
     69    } 
     70
     71 
     72sub add_filepath { 
     73    my $filepath = shift; 
     74    my $hash = $self->hash_from_file($filepath); 
    7375    for my $key (keys %$hash) { 
    74         next if defined $self->{$key}; 
    75         field $key; 
    76         $self->{$key} = $hash->{$key}; 
    77     } 
    78 
    79  
    80 sub add_path { 
    81     splice @{$self->path}, 0, 0, @_; 
     76        $self->add_field($key, $hash->{$key}); 
     77    } 
    8278} 
    8379 
  • trunk/src/core/Spoon/lib/Spoon/Config.pm

    r138 r172  
    33 
    44const class_id => 'config'; 
     5field plugin_classes => []; 
    56 
    67sub all { 
     
    89} 
    910 
    10 sub default_configs { return } 
    11  
    12 sub new() { 
    13     my $class = shift; 
    14     my $self = bless {}, $class; 
    15     my (@configs) = map { 
    16         /\*/ ? (sort glob) : ($_) 
    17     } @_ ? @_ : $self->default_configs; 
    18     $self->add_config($self->default_config); 
    19     for my $config (@configs) { 
    20         $self->rebless($self->add_config($config)); 
    21     } 
    22     $self->init; 
    23     return $self; 
    24 } 
    25  
    2611sub add_field { 
    27     my ($field, $default) = @_; 
    28     field $field => $default; 
     12    my ($field, $value) = @_; 
     13    field $field; 
     14    $self->{$field} = $value; 
    2915} 
    3016 
     
    3925    } 
    4026    return $hash; 
    41 } 
    42  
    43 sub rebless { 
    44     my $hash = shift; 
    45     if (defined (my $config_class = $hash->{config_class})) { 
    46         eval qq{ require $config_class }; die $@ if $@; 
    47         bless $self, $config_class; 
    48     } 
    4927} 
    5028 
     
    8462    return $hash; 
    8563} 
    86  
    87 sub default_config { 
    88     +{ 
    89         plugin_classes => [$self->default_plugin_classes], 
    90     } 
    91 } 
    92  
    93 sub default_plugin_classes { () } 
  • trunk/src/core/modules.mk

    r161 r172  
    77        Kwiki/Command \ 
    88        Kwiki/Files \ 
     9        Kwiki/Paths \ 
    910        Kwiki/Template \ 
    1011        Kwiki/Theme \ 
     
    1314        Spoon \ 
    1415        Spoon/Template \ 
     16        Spork \ 
     17        Spork/Config \ 
     18        Spork/Formatter \ 
     19        Spork/Template \ 
    1520        Template \ 
    1621        Template/Namespace \ 
     
    3035        Spiffy.pm \ 
    3136        Spoon.pm \ 
     37        Spork.pm \ 
    3238        Template.pm \ 
    3339        YAML.pm \ 
     
    8591        Spoon/Trace.pm \ 
    8692        Spoon/Utils.pm \ 
     93        Spork/Command.pm \ 
     94        Spork/Config.pm \ 
     95        Spork/Formatter.pm \ 
     96        Spork/Hub.pm \ 
     97        Spork/Plugin.pm \ 
     98        Spork/Registry.pm \ 
     99        Spork/Slides.pm \ 
    87100        Template/Base.pm \ 
    88101        Template/Config.pm \ 
     
    127140        IO/All/Temp.pm \ 
    128141        Kwiki/Archive/Simple.pm \ 
     142        Kwiki/Boot/Base.pm \ 
    129143        Kwiki/Boot/V1.pm \ 
    130144        Kwiki/Boot/V2.pm \ 
     
    133147        Kwiki/Files/V1.pm \ 
    134148        Kwiki/Files/V2.pm \ 
     149        Kwiki/Paths/V1.pm \ 
     150        Kwiki/Paths/V2.pm \ 
    135151        Kwiki/Template/TT2.pm \ 
    136152        Kwiki/Theme/Basic.pm \ 
    137153        Spoon/Template/TT2.pm \ 
     154        Spork/Config/Default.pm \ 
     155        Spork/Formatter/Autringy.pm \ 
     156        Spork/Template/TT2.pm \ 
    138157        Template/Namespace/Constants.pm \ 
    139158        Template/Plugin/Autoformat.pm \