Permalink
Browse files

r4977 admin: allow selection of source(s) to distribute

  • Loading branch information...
1 parent 00c3153 commit be07666040cdfe4f67da9de357b7c467e4fde206 @matthewrmshin matthewrmshin committed Aug 8, 2013
Showing with 39 additions and 48 deletions.
  1. +7 −1 lib/FCM/Admin/Config.pm
  2. +15 −12 lib/FCM/Admin/System.pm
  3. +17 −35 sbin/fcm-commit-update
View
@@ -25,7 +25,6 @@ package FCM::Admin::Config;
use FCM::Context::Locator;
use FCM::Util;
use File::Spec::Functions qw{catfile};
-use Text::ParseWords qw{shellwords};
my $USER = (getpwuid($<))[0];
my $HOME = (getpwuid($<))[7];
@@ -37,6 +36,7 @@ my %DEFAULT_R = (
fcm_wc => catfile($HOME, qw{fcm}),
fcm_site_wc => catfile($HOME, qw{fcm_admin}),
mirror_dests => q{},
+ mirror_keys => q{fcm_wc fcm_site_wc},
trac_gid => scalar(getgrnam(q{apache})),
user_number_min => 500,
);
@@ -143,6 +143,12 @@ Returns the HOME directory of the FCM administrator.
Returns a string containing a list of destinations to mirror FCM installation.
+=item $config->get_mirror_keys()
+
+Returns a string containing a list of source keys. Each source key should point
+to a source location in this $config. The source locations will be distributed
+to the list of destinations in $config->get_mirror_dests().
+
=item $config->get_fcm_wc()
Returns the (working copy) source path of the default FCM distribution.
View
@@ -364,18 +364,21 @@ sub distribute_wc {
my $CONFIG = FCM::Admin::Config->instance();
my $RUNNER = FCM::Admin::Runner->instance();
my @RSYNC_OPTS = qw{--timeout=1800 --exclude=.*};
- for my $path ($CONFIG->get_fcm_wc(), $CONFIG->get_fcm_site_wc()) {
- for my $dest (shellwords($CONFIG->get_mirror_dests())) {
- $rc = $RUNNER->run_continue(
- "distributing FCM to $dest",
- sub {
- run_rsync(
- [$path], $dest,
- [@RSYNC_OPTS, qw{-a --delete-excluded}],
- );
- },
- ) && $rc;
- }
+ my @sources;
+ for my $source_key (shellwords($CONFIG->get_mirror_keys())) {
+ my $method = "get_$source_key";
+ push(@sources, $CONFIG->$method());
+ }
+ for my $dest (shellwords($CONFIG->get_mirror_dests())) {
+ $rc = $RUNNER->run_continue(
+ "distributing FCM to $dest",
+ sub {
+ run_rsync(
+ \@sources, $dest,
+ [@RSYNC_OPTS, qw{-a --delete-excluded}],
+ );
+ },
+ ) && $rc;
}
return $rc;
}
View
@@ -43,6 +43,7 @@ use FCM::Admin::Util qw{
};
use Getopt::Long qw{GetOptions};
use Pod::Usage qw{pod2usage};
+use Text::ParseWords qw{shellwords};
# ------------------------------------------------------------------------------
my $CONFIG = FCM::Admin::Config->instance();
@@ -76,53 +77,34 @@ sub main {
my $is_force = $option{'force'};
UPDATE:
while (1) {
- my @updates_in_fcm = run_svn_update($CONFIG->get_fcm_wc());
- my @updates_in_fcm_site = run_svn_update($CONFIG->get_fcm_site_wc());
- if (!$is_force && !@updates_in_fcm && !@updates_in_fcm_site) {
+ my @updates;
+ for my $source_key (shellwords($CONFIG->get_mirror_keys())) {
+ my $method = "get_$source_key";
+ push(@updates, run_svn_update($CONFIG->$method()));
+ }
+ if (!$is_force && !@updates) {
last UPDATE;
}
- for my $task ((
- { name => '(re-)installing hook scripts',
- main => sub {
+ if ($is_force || grep {$_ =~ $PATTERN_OF{'SRC_HOOK'}} @updates) {
+ $RUNNER->run(
+ '(re-)installing hook scripts',
+ sub {
for my $project (get_projects_from_svn_live()) {
install_svn_hook($project);
}
return 1;
- },
- want => get_pattern_grepper('SRC_HOOK', 1),
- },
- { name => 'distributing FCM to standard locations',
- main => \&distribute_wc,
- want => get_pattern_grepper(q{}, 1),
- },
- )) {
- if ( $is_force
- || $task->{want}->(\@updates_in_fcm, \@updates_in_fcm_site)
- ) {
- $RUNNER->run($task->{name}, $task->{main});
- }
+ }
+ );
+ }
+ if ($is_force || grep {$_ =~ $PATTERN_OF{q{}}} @updates) {
+ $RUNNER->run(
+ 'distributing FCM to standard locations', \&distribute_wc);
}
$is_force = 0;
}
}
# ------------------------------------------------------------------------------
-# Returns a function that "grep" for a known pattern ($pattern_key). The
-# returned function expects a list reference in the 0th element of its argument
-# list.
-sub get_pattern_grepper {
- my ($pattern_key, $should_grep_fcm_site) = @_;
- sub {
- my ($updates_in_fcm_ref, $updates_in_fcm_site_ref) = @_;
- my @updates = @{$updates_in_fcm_ref};
- if ($should_grep_fcm_site) {
- push(@updates, @{$updates_in_fcm_site_ref});
- }
- grep({$_ =~ $PATTERN_OF{$pattern_key}} @updates);
- };
-}
-
-# ------------------------------------------------------------------------------
# Creates a lock. Returns true on success. Removes lock when program finishes.
our $LOCK;
sub create_lock {

0 comments on commit be07666

Please sign in to comment.