Changeset 178
- Timestamp:
- 03/02/07 20:55:20 (2 years ago)
- Files:
-
- trunk/lib/Kwiki/Command/Base.pm (modified) (1 diff)
- trunk/src/core/Kwiki/kwiki (modified) (1 diff)
- trunk/src/core/Kwiki/lib/Kwiki/Boot/Base.pm (modified) (2 diffs)
- trunk/src/core/Kwiki/lib/Kwiki/Boot/V1.pm (modified) (2 diffs)
- trunk/src/core/Kwiki/lib/Kwiki/Boot/V2.pm (modified) (1 diff)
- trunk/src/core/Kwiki/lib/Kwiki/Command/V2.pm (modified) (6 diffs)
- trunk/src/core/Kwiki/lib/Kwiki/Files/V2.pm (modified) (1 diff)
- trunk/src/core/Kwiki/lib/Kwiki/Paths/V1.pm (modified) (1 diff)
- trunk/src/core/Kwiki/lib/Kwiki/Paths/V2.pm (modified) (1 diff)
- trunk/src/core/Spoon/lib/Spoon/Config.pm (modified) (1 diff)
- trunk/src/plugins/miyagawa/Kwiki-FastCGI/lib/Kwiki/FastCGI.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/Kwiki/Command/Base.pm
r156 r178 25 25 $self->hub->$class_id->quiet($self->quiet); 26 26 $self->hub->$class_id->extract_files; 27 $self->msg(" \n");27 $self->msg(" \n"); 28 28 } 29 29 trunk/src/core/Kwiki/kwiki
r158 r178 31 31 32 32 BEGIN { 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}; 35 35 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 } 38 44 39 45 if ($ENV{KWIKI_TEST_CLEAN}) { trunk/src/core/Kwiki/lib/Kwiki/Boot/Base.pm
r172 r178 30 30 31 31 $self->kwiki($main); 32 $self->setup; 33 } 34 35 sub setup { 36 $self->add_default_classes; 37 $self->add_configs_files; 38 $self->add_plugins_files; 32 39 } 33 40 … … 40 47 } 41 48 } 49 50 sub 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 6 6 const hub_class => 'Kwiki::Hub'; 7 7 8 sub init {9 $self->SUPER::init;10 $self->add_default_classes;11 $self->add_configs_files;12 $self->add_plugins_files;13 }14 15 8 sub add_configs_files { 16 9 $self->config->add_file('config.yaml'); … … 18 11 $self->config->add_config($filepath, 1); 19 12 } 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);46 13 } 47 14 trunk/src/core/Kwiki/lib/Kwiki/Boot/V2.pm
r172 r178 6 6 const hub_class => 'Kwiki::Hub'; 7 7 8 sub init {9 $self->add_default_classes;10 $self->add_configs_files;11 $self->add_plugins_files;12 }13 14 8 sub add_configs_files { 15 9 # TODO Get all config locations from hub->paths 16 $self->config->add_path('config');17 10 $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; 23 14 } 24 15 trunk/src/core/Kwiki/lib/Kwiki/Command/V2.pm
r172 r178 8 8 $self->create_www_link; 9 9 $self->add_new_default_config; 10 # XXX $self->hub->files; 10 11 $self->install('files'); 11 12 $self->create_database; … … 16 17 17 18 sub 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; 20 21 $plugin->mkpath unless $plugin->exists; 21 22 } 22 23 23 24 sub 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 } 30 37 } 31 38 … … 42 49 die "No such directory '$flavor_path'" 43 50 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; 45 52 io->link("$www/__")->assert->symlink("$flavor_path/www"); 46 53 } … … 62 69 63 70 sub kwiki_env_path { 64 for (qw( _kwiki .ht_kwiki)) {71 for (qw(kwiki.env .ht-kwiki.env)) { 65 72 return $_ if -e $_; 66 73 } 67 return ' _kwiki';74 return 'kwiki.env'; 68 75 } 69 76 … … 80 87 return <<'...'; 81 88 KWIKI_BOOT=V2 89 KWIKI_BASE= 82 90 KWIKI_LIB_PATH=lib 83 KWIKI_BASE=84 91 KWIKI_FLAVOR=Vanilla 85 92 KWIKI_TEST_CLEAN=0 86 KWIKI_PLUGIN_SCRATCH_FILEPATH=plugin 87 KWIKI_DATABASE_FILEPATH=database 88 KWIKI_WWW_FILEPATH=www 93 KWIKI_PLUGIN_SCRATCH_LOCATION=plugin 94 KWIKI_DATABASE_LOCATION=database 95 KWIKI_WWW_LOCATION=www 96 KWIKI_LOCAL_CONFIG_LOCATION=config.yaml 89 97 ... 90 98 } … … 175 183 176 184 sub 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; 179 187 my $umask = umask 0000; 180 188 chmod 0777, $database, $plugin; trunk/src/core/Kwiki/lib/Kwiki/Files/V2.pm
r165 r178 13 13 BEGIN { 14 14 my $fh; 15 for (qw( _kwiki .ht_kwiki)) { open $fh, $_ and last }15 for (qw(kwiki.env .ht-kwiki.env)) { open $fh, $_ and last } 16 16 do { $ENV{$1} ||= $2 if /^(\w+)\s*=\s*['"]?(.*?)['"]?\s*$/ } for <$fh>; 17 17 } trunk/src/core/Kwiki/lib/Kwiki/Paths/V1.pm
r173 r178 1 1 package Kwiki::Paths::V1; 2 2 use Kwiki::Base -Base; 3 use Cwd qw(cwd abs_path); 3 4 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). 6 sub all_paths { 7 my $dir = cwd(); 8 my @paths = ($dir); 11 9 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; 15 15 } 16 16 return @paths; 17 17 } 18 19 # All filepaths in the chain ending with the given file 20 sub 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 28 sub first_filepath { 29 return scalar $self->all_paths(shift); 30 } trunk/src/core/Kwiki/lib/Kwiki/Paths/V2.pm
r173 r178 1 1 package Kwiki::Paths::V2; 2 2 use Kwiki::Base -Base; 3 use Cwd qw(cwd abs_path); 3 4 5 field 'all_paths_cache'; 6 7 # All directories in the config chain (starting at root). 8 sub 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 46 sub 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 4 52 sub first_filepath { 5 return "$ENV{KWIKI_BASE}/base/database"; 53 my @all = $self->all_paths(@_); 54 return $all[-1]; 6 55 } trunk/src/core/Spoon/lib/Spoon/Config.pm
r177 r178 69 69 } 70 70 71 sub add_plugin { 72 push @{$self->plugin_classes}, shift; 71 sub 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); 73 98 } 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 46 46 BEGIN { 47 47 my $fh; 48 for (qw( _kwiki .ht_kwiki)) { open $fh, $_ and last }48 for (qw(kwiki.env .ht-kwiki.env)) { open $fh, $_ and last } 49 49 do { $ENV{$1} ||= $2 if /^(\w+)\s*=\s*['"]?(.*?)['"]?\s*$/ } for <$fh>; 50 50 }
