]> git.donarmstrong.com Git - bin.git/commitdiff
Add sarc support to sa
authorDon Armstrong <don@donarmstrong.com>
Thu, 3 Nov 2005 09:22:26 +0000 (09:22 +0000)
committerDon Armstrong <don@donarmstrong.com>
Thu, 3 Nov 2005 09:22:26 +0000 (09:22 +0000)
sa

diff --git a/sa b/sa
index b61ddeee677b404d42f0878287be0fee86f6358d..53f9f72434c88afd14e28b1a07d6292f767089b1 100755 (executable)
--- a/sa
+++ b/sa
@@ -46,11 +46,10 @@ Display this manual.
 
 
 use User;
+use IO::File;
 use vars qw($DEBUG);
 
-# XXX parse config file
-
-my %options = (quick           => 0,
+my %options = (quick           => 1,
               quiet           => 1,
               debug           => 0,
               help            => 0,
@@ -62,6 +61,47 @@ GetOptions(\%options,'quick|Q!','quiet|q!','debug|d+','help|h|?','man|m');
 pod2usage() if $options{help};
 pod2usage({verbose=>2}) if $options{man};
 
+# parse configuration file
+
+=head1 CONFIGURATION
+
+Reads configuration information from Start by parsing /etc/sa.conf,
+then ~/.sarc then ~/.sarc_$hostname, then ~/.sarc_local
+
+The configuration file contains a list of svn repositories which
+should be queried; each line can contain a tab, which indicates that
+the command following the tab should be run fater the svn directory is
+updated.
+
+The configuration files are read in the order given above.
+
+=cut
+
+sub parse_config_file {
+     my ($repos,$filename,$home) = @_;
+     return unless -e $filename and -r _;
+     my $fh = new IO::File $filename, 'r' or die "Unable to read configuration file $filename $!";
+     while (<$fh>) {
+         chomp;
+         next if /^#/;
+         my ($repo,$command) = split /\t/,$_,2;
+         $repo =~ s/^\~/$home/;
+         $$repos{$repo} = $command;
+     }
+}
+
+
+my $HOME=User->Home;
+my $HOSTNAME=qx(hostname);
+$HOSTNAME=~s/\n//g;
+my %repos;
+for ('/etc/sa.conf', "${HOME}/.sarc", "${HOME}/.sarc_${HOSTNAME}", "${HOME}/.sarc_local") {
+     if (-e $_) {
+         parse_config_file(\%repos,$_,$HOME);
+     }
+}
+
+
 $DEBUG = $options{debug};
 
 my $command;
@@ -73,15 +113,17 @@ else {
      $command = 'status';
 }
 
-my $HOME=User->Home;
 
-for my $dir (map{"${HOME}/$_"} '',qw(.hide bin lib)) {
-     if (-e "$dir/.svn") {
+while (my ($repo,$run_after) = each(%repos)) {
+     if (-e "$repo/.svn") {
          system('svn',
                 $command,
                 $options{quiet}?'-q':(),
                 $options{quick}?('--ignore-externals','-N'):(),
-                $dir,
+                $repo,
                );
      }
+     if ($command =~ /^up(?:date)|checkout$/) {
+         system($run_after,$repo);
+     }
 }