[Bps-public-commit] r14490 - in Pushmi/trunk: . Pushmi-Admin/etc Pushmi-Admin/lib/Pushmi/Admin/Action Pushmi-Admin/lib/Pushmi/Admin/Model

alexmv at bestpractical.com alexmv at bestpractical.com
Thu Jul 24 17:35:11 EDT 2008


Author: alexmv
Date: Thu Jul 24 17:35:11 2008
New Revision: 14490

Modified:
   Pushmi/trunk/   (props changed)
   Pushmi/trunk/Pushmi-Admin/etc/config.yml
   Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin.pm
   Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Action/CheckURL.pm
   Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/HttpRoot.pm
   Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/Replica.pm

Log:
 r34625 at kohr-ah:  chmrr | 2008-07-24 17:34:59 -0400
  * Totally not bulletproofed calls to write out apache2.2 config files
  * Slight refactor on time deltas


Modified: Pushmi/trunk/Pushmi-Admin/etc/config.yml
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/etc/config.yml	(original)
+++ Pushmi/trunk/Pushmi-Admin/etc/config.yml	Thu Jul 24 17:35:11 2008
@@ -56,5 +56,8 @@
     TemplateRoot: share/web/templates
 application:
     svn_root: %var/svn_root%
-    http_root: http://localhost:8888/
     pushmi_bin: /usr/bin/pushmi
+    apache:
+      root: http://localhost/
+      bin: sudo /etc/init.d/apache2
+      conf: /etc/apache2/pushmi.conf

Modified: Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin.pm
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin.pm	(original)
+++ Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin.pm	Thu Jul 24 17:35:11 2008
@@ -13,13 +13,12 @@
     my $props = $memcached->get( $url );
     return $props if defined $props;
 
-    my ($baton, $ref) = SVN::Core::auth_open_helper(undef);
-    my $ra = SVN::Ra->new( url => $url, config => undef, auth => $baton);
-
     my $start = Time::HiRes::time;
     local $SIG{ALRM} = sub { die "Timeout!" };
     alarm 10;
     eval {
+        my ($baton, $ref) = SVN::Core::auth_open_helper(undef);
+        my $ra = SVN::Ra->new( url => $url, config => undef, auth => $baton);
         $props->{rev} = $ra->get_latest_revnum;
         $props->{date} = 1e6 * str2time($ra->rev_prop($props->{rev}, 'svn:date'));
     };
@@ -49,4 +48,21 @@
     $memcached->delete( $url );
 }
 
+sub update_apache {
+    my $class = shift;
+
+    my $path = Jifty->config->app("apache")->{conf};
+    open(APACHE, ">", $path) or die "Can't write apache configuration file $path: $!";
+    my $roots = Pushmi::Admin::Model::HttpRootCollection->new;
+    $roots->unlimit;
+    print APACHE "PerlLoadModule Apache::AuthenHook\n";
+    while (my $r = $roots->next) {
+        print APACHE $r->apache_conf;
+    }
+    close(APACHE);
+
+    my $hup = Jifty->config->app("apache")->{bin};
+    system("$hup restart >/dev/null");
+}
+
 1;

Modified: Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Action/CheckURL.pm
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Action/CheckURL.pm	(original)
+++ Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Action/CheckURL.pm	Thu Jul 24 17:35:11 2008
@@ -30,8 +30,8 @@
     my ($url) = @_;
     warn "Validating $url\n";
     return $self->validation_error(
-        url => "We can only deal with http:// urls" )
-        unless $url =~ m{^http://};
+        url => "We can only deal with http:// or file:// urls" )
+        unless $url =~ m{^(http|file)://};
 
     $url =~ s{/+$}{};
 

Modified: Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/HttpRoot.pm
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/HttpRoot.pm	(original)
+++ Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/HttpRoot.pm	Thu Jul 24 17:35:11 2008
@@ -15,9 +15,47 @@
 
 };
 
+sub after_create {
+    my $self = shift;
+    my ($ref) = @_;
+
+    return unless $ref;
+    Pushmi::Admin->update_apache;
+    return 1;
+}
+
+sub after_delete {
+    my $self = shift;
+    my ($ref) = @_;
+
+    return unless $ref;
+    Pushmi::Admin->update_apache;
+    return 1;
+}
+
 sub current_user_can {
     return 1;
 }
 
+sub apache_conf {
+    my $self = shift;
+    return <<EOT;
+<Location /@{[$self->path]}>
+    DAV svn
+    SVNPath @{[$self->replica->svn_root]}
+    PerlSetVar SVNPath @{[$self->replica->svn_root]}
+    PerlSetVar Pushmi @{[Jifty->config->app("pushmi_bin")]}
+    PerlSetVar PushmiConfig /etc/pushmi.conf
+
+    <LimitExcept GET PROPFIND OPTIONS REPORT>
+        AuthName "Subversion repository for @{[$self->replica->name]}"
+        AuthType Basic
+        Require valid-user
+        AuthBasicProvider Pushmi::Apache::RelayProvider
+    </LimitExcept>
+</Location>
+EOT
+}
+
 1;
 

Modified: Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/Replica.pm
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/Replica.pm	(original)
+++ Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/Replica.pm	Thu Jul 24 17:35:11 2008
@@ -72,13 +72,13 @@
 
     my ( $id, $msg ) = $self->SUPER::create(%args);
     if ($id) {
+        $self->set_clean_name( $self->_clean_name );
+
         if ($mirror) {
             my $http = Pushmi::Admin::Model::HttpRoot->new;
             $http->create( path => $mirror, replica_id => $id );
         }
 
-        $self->set_clean_name( $self->_clean_name );
-
         eval {
             Pushmi::Command::Mirror->new->run( $self->svn_root, $self->url );
         };
@@ -184,11 +184,18 @@
     return sprintf( "%.2f seconds", $self->cache->{latency} );
 }
 
+sub time_delta {
+    my $self = shift;
+    my ($time) = @_;
+    my $d =  Time::Duration::duration(
+        time - $time / 1e6 );
+    return $d if $d eq "just now";
+    return "$d ago";
+}
+
 sub last_remote {
     my $self = shift;
-    return Time::Duration::duration(
-        time - $self->cache->{remote_date} / 1e6 )
-        . " ago";
+    return $self->time_delta($self->cache->{remote_date});
 }
 
 sub local_revision {
@@ -198,8 +205,7 @@
 
 sub last_local {
     my $self = shift;
-    return Time::Duration::duration( time - $self->cache->{local_date} / 1e6 )
-        . " ago";
+    return $self->time_delta($self->cache->{local_date});
 }
 
 sub status {
@@ -247,6 +253,7 @@
                 $_->{ $self->clean_name } = { pid => $pid };
             } else {
                 my $id = $self->id;
+                close STDOUT;
                 exec( $^X => "-Ilib",
                     "-MPushmi::Admin::Watcher",
                     "-e" => "Pushmi::Admin::Watcher->new($id)"



More information about the Bps-public-commit mailing list