source: trunk/dasscm/dasscm@ 189

Last change on this file since 189 was 189, checked in by joergs, on Nov 10, 2004 at 9:53:48 AM

added help

  • Property keyword set to id
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1#!/usr/bin/perl -w
2
3# $Id: dasscm 189 2004-11-10 08:53:48Z joergs $
4
5use strict;
6
7use Env qw($DASSCM_PROD $DASSCM_REPO);
8use Cwd;
9use File::Basename;
10use File::stat;
11use File::Path;
12use File::Copy;
13#use POSIX qw/getpgrp tcgetpgrp/;
14
15#####################################################################
16#
17# global
18#
19my $SVN = "svn ";
20
21#####################################################################
22#
23# util functions
24#
25sub usage()
26{
27 print "dasscm is intended to help versioning configuration files\n\n";
28
29 print "usage: dasscm <subcommand> [options] [args]\n\n";
30 print "Available subcommands:\n";
31 print " add <filename>\n";
32 print " commit <filename>\n";
33 print " diff <filename>\n";
34 print " help <subcommand>\n";
35}
36
37sub check_env()
38{
39 # DASSCM_PROD
40 if ( ! $DASSCM_PROD ) {
41 $DASSCM_PROD = "/";
42 }
43 print "DASSCM_PROD: ".$DASSCM_PROD."\n";
44 if ( ! -d $DASSCM_PROD ) {
45 die "DASSCM_PROD is not set to a directory.\n";
46 }
47
48 # DASSCM_REPO
49 if ( ! $DASSCM_REPO ) {
50 die "Envirnonment variable DASSCM_REPO not set.\nSet DASSCM_REPO to the directory of the versioning system checkout for this machine.";
51 }
52 print "DASSCM_REPO: ".$DASSCM_REPO."\n";
53 if ( ! -d $DASSCM_REPO ) {
54 die "DASSCM_REPO must be is not set to the directory of the versioning system checkout for this machine.\n";
55 }
56
57}
58
59sub check_parameter(@)
60{
61}
62
63sub get_filenames(@)
64{
65 my $filename_prod = $_[0];
66 if ( !($filename_prod =~ m/^\//) ) {
67 $filename_prod = cwd()."/".$filename_prod;
68 }
69
70 -r $filename_prod or die "$filename_prod is not accessable";
71
72 # TODO: dirname buggy: eg. "/etc/" is reduced to "/",
73 # "/etc" is used as filename
74 my $dirname_prod = dirname($filename_prod);
75 chdir $dirname_prod or die $!;
76 $dirname_prod = cwd();
77 my $basename = basename($filename_prod);
78
79 print "dir: ".$dirname_prod."\n";
80 print "fn: ".$basename."\n";
81
82 my $dirname_repo = $DASSCM_REPO."/".$dirname_prod;
83 my $filename_repo = "$dirname_repo/$basename";
84
85 return ($basename,$dirname_prod,$dirname_repo,$filename_prod,$filename_repo);
86}
87
88sub run_command
89{
90 my $command = shift;
91
92 #print "executing command: " . $command . "\n";
93
94 open(RESULT, $command . ' 2>&1 |' );
95 my @result = <RESULT>;
96 close(RESULT);
97 my $retcode = $?>>8;
98
99 #print @result;
100 #if( $retcode ) { print "return code: " . $retcode . "\n"; }
101
102 return($retcode, @result);
103}
104
105
106#####################################################################
107#
108# functions
109
110sub help(;@)
111{
112 if( @_ == 0 ) {
113 usage();
114 } else {
115 print "help for @_: ...\n";
116 }
117}
118
119sub add(@)
120{
121 check_parameter(@_,1);
122 check_env();
123
124 (my $basename, my $dirname_prod, my $dirname_repo, my $filename_prod, my $filename_repo) = get_filenames($_[0]);
125
126 mkpath($dirname_repo);
127
128 # update complete repository
129 (my $retcode, my @result)=run_command( "$SVN update $DASSCM_REPO" );
130 if( $retcode != 0 ) {
131 print @result;
132 die;
133 }
134
135 copy( $filename_prod, $filename_repo ) or die $!;
136
137 # already checked in?
138 chdir($DASSCM_REPO);
139 # also add the path to filename.
140 for my $dir (split('/', $dirname_prod) ) {
141 if( $dir ) {
142 run_command( "$SVN add --non-recursive $dir" );
143 chdir $dir;
144 }
145 }
146 run_command( "$SVN add $basename" );
147
148 # commit calls $EDITOR. uses "system" here, to display output
149 system( "$SVN commit $DASSCM_REPO" );
150 # TODO: commit (-m)
151
152 print $filename_prod."\n";
153 print $dirname_repo."\n";
154}
155
156sub commit(@)
157{
158 check_parameter(@_,1);
159 check_env();
160
161 (my $basename, my $dirname_prod, my $dirname_repo, my $filename_prod, my $filename_repo) = get_filenames($_[0]);
162
163 (my $rc_update, my @result)=run_command( "$SVN update $filename_repo" );
164 if( $rc_update != 0 ) {
165 print @result;
166 die;
167 }
168
169 # commit calls $EDITOR. uses "system" here, to display output
170 system( "$SVN commit $DASSCM_REPO" );
171 # TODO: commit (-m)
172}
173
174sub diff(@)
175{
176 check_parameter(@_,1);
177 check_env();
178
179 (my $basename, my $dirname_prod, my $dirname_repo, my $filename_prod, my $filename_repo) = get_filenames($_[0]);
180
181 #print "$basename,$dirname_prod,$dirname_repo\n";
182
183 (my $rc_update, my @result)=run_command( "$SVN update $filename_repo" );
184 if( $rc_update != 0 ) {
185 print @result;
186 die;
187 }
188
189 (my $rc_diff, my @diff)=run_command( "diff $filename_repo $filename_prod" );
190 print @diff;
191}
192
193#####################################################################
194#
195# main
196#
197
198my $number_arguments = @ARGV;
199#print "$number_arguments\n";
200
201if ($number_arguments > 0) {
202 my $command = $ARGV[0];
203 shift @ARGV;
204 #$command =~ s/[A-Z]/[a-z]/m;
205 #print "$command\n";
206
207 $_=$command;
208 if (m/help/i) {
209 help(@ARGV);
210 } elsif (m/add/i) {
211 add(@ARGV);
212 } elsif (m/commit/i) {
213 commit(@ARGV);
214 } elsif (m/diff/i) {
215 diff(@ARGV);
216 } elsif (m/activate/i) {
217 activate(@ARGV);
218 } else {
219 usage();
220 check_env();
221 }
222}
Note: See TracBrowser for help on using the repository browser.