source: trunk/dasscm/dasscm@ 187

Last change on this file since 187 was 187, checked in by joergs, on Nov 9, 2004 at 10:17:50 PM

added diff, commit

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