source: trunk/dasscm/dasscm@ 186

Last change on this file since 186 was 186, checked in by joergs, on Nov 1, 2004 at 9:10:49 PM

initial. add implemented

  • Property svn:executable set to *
File size: 2.8 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 check_env()
20{
21 # DASSCM_PROD
22 if ( ! $DASSCM_PROD ) {
23 $DASSCM_PROD = "/";
24 }
25 print "DASSCM_PROD: ".$DASSCM_PROD."\n";
26 if ( ! -d $DASSCM_PROD ) {
27 die "DASSCM_PROD is not set to a directory.\n";
28 }
29
30 # DASSCM_REPO
31 if ( ! $DASSCM_REPO ) {
32 die "Envirnonment variable DASSCM_REPO not set.\nSet DASSCM_REPO to the directory of the versioning system checkout for this machine.";
33 }
34 print "DASSCM_REPO: ".$DASSCM_REPO."\n";
35 if ( ! -d $DASSCM_REPO ) {
36 die "DASSCM_REPO must be is not set to the directory of the versioning system checkout for this machine.\n";
37 }
38
39}
40
41sub check_parameter(@)
42{
43}
44
45sub run_command
46{
47 my $command = shift;
48
49 print "executing command: " . $command . "\n";
50
51 open(RESULT, $command . ' 2>&1 |' );
52 my @result = <RESULT>;
53 close(RESULT);
54 my $retcode = $?>>8;
55
56 print @result;
57 if( $retcode ) { print "return code: " . $retcode . "\n"; }
58
59 return($retcode, @result);
60}
61
62
63
64# functions
65
66sub help(;@)
67{
68 print "help for @_\n";
69}
70
71sub add(@)
72{
73 check_parameter(@_,1);
74 check_env();
75 my $filename_prod = $_[0];
76 if ( !($filename_prod =~ m/^\//) ) {
77 $filename_prod = cwd()."/".$filename_prod;
78 }
79
80 -r $filename_prod or die "$filename_prod is not accessable";
81
82 # TODO: dirname buggy: eg. "/etc/" is reduced to "/",
83 # "/etc" is used as filename
84 my $dirname_prod = dirname($filename_prod);
85 chdir $dirname_prod or die $!;
86 $dirname_prod = cwd();
87 my $basename = basename($filename_prod);
88
89 print "dir: ".$dirname_prod."\n";
90 print "fn: ".$basename."\n";
91
92 my $dirname_repo = $DASSCM_REPO."/".$dirname_prod;
93 my $filename_repo = "$dirname_repo/$basename";
94
95 mkpath($dirname_repo);
96
97 # update complete repository
98 run_command( "$SVN update $DASSCM_REPO" );
99
100 copy( $filename_prod, $filename_repo ) or die $!;
101
102 # already checked in?
103 chdir($DASSCM_REPO);
104 # also add the path to filename.
105 for my $dir (split('/', $dirname_prod) ) {
106 if( $dir ) {
107 run_command( "$SVN add --non-recursive $dir" );
108 chdir $dir;
109 }
110 }
111 run_command( "$SVN add $basename" );
112
113 # commit calls $EDITOR. uses "system" here, to display output
114 system( "$SVN commit $DASSCM_REPO" );
115 # TODO: commit (-m)
116
117 print $filename_prod."\n";
118 print $dirname_repo."\n";
119}
120
121
122# main
123
124my $number_arguments = @ARGV;
125print "$number_arguments\n";
126
127if ($number_arguments > 0) {
128 my $command = $ARGV[0];
129 shift @ARGV;
130 #$command =~ s/[A-Z]/[a-z]/m;
131 #print "$command\n";
132
133 $_=$command;
134 if (m/help/i) {
135 help(@ARGV);
136 } elsif (m/add/i) {
137 add(@ARGV);
138 } elsif (m/commit/i) {
139 commit(@ARGV);
140 } elsif (m/diff/i) {
141 diff(@ARGV);
142 } elsif (m/activate/i) {
143 activate(@ARGV);
144 }
145}
Note: See TracBrowser for help on using the repository browser.