2 #################################################################################
5 # Description: Script to tag views or vobs into the current region. The main
6 # motivation for this script is to be able to tag things quickly
7 # and easily. As such we employ heuristics to find these objects.
8 # Author: Andrew@DeFaria.com
9 # Created: Fri Apr 9 12:19:04 PDT 2004
12 # (c) Copyright 2004, Andrew@DeFaria.com, all rights reserved.
14 ################################################################################
21 # Extract relative path and basename from script name.
23 $me = (!defined $1) ? $0 : $1;
26 # Check to see if we are running on Windows
27 my $windows = ($^O =~ /MSWin/) ? "yes" : "no";
28 my $null = $windows eq "yes" ? "NUL" : "/dev/null";
29 my $backslashes = $windows eq "yes" ? "\\" : "\\\\";
32 print "Usage $me: [[ -view ] <view_tag> ] [ -vob <vob_tag> ]\n";
34 print "\t-view\tView tag to tag in current region\n";
35 print "\t-vob\tVob tag to tag in current region\n";
39 sub GetCurrentRegion {
40 my @lines = `cleartool hostinfo -l`;
43 chomp; chop $_ if /\r/;
45 if (/Registry region: (\S+)/) {
53 my $current_region = GetCurrentRegion;
54 my @regions = `cleartool lsregion`;
62 my $output = `cleartool lsview -region $_ $view_tag 2> $null`;
63 chomp $output; chop $output if /\r/;
65 if ($output =~ /$view_tag\s*(.*)/) {
66 my $view_storage = $1;
67 $view_storage =~ tr /\\/\/\//;
68 return ($view_storage, $_);
81 my $output = `cleartool lsvob -region $_ $backslashes$vob_tag 2> $null`;
82 chomp $output; chop $output if /\r/;
84 if ($output =~ /$vob_tag\s*(\S*)/) {
86 $vob_storage =~ tr /\\/\/\//;
87 return ($vob_storage, $_);
96 my $view_storage = shift;
98 # Check to see if view tag already exists
99 if (!system "cleartool lsview $view_tag > $null 2>&1") {
100 print "$view_tag already exists in $current_region\n";
103 if (system "cleartool mktag -view -tag $view_tag $view_storage") {
104 die "Unable to make view tag: $view_tag in $current_region\n";
112 my $vob_storage = shift;
114 # Check to see if vob tag already exists
115 if (!system "cleartool lsvob $backslashes$vob_tag > $null 2>&1") {
116 print "$vob_tag already exists in $current_region\n";
119 print "cleartool mktag -vob -tag $backslashes$vob_tag $vob_storage\n";
120 if (system "cleartool mktag -vob -tag $backslashes$vob_tag $vob_storage") {
121 die "Unable to make vob tag: $vob_tag in $current_region\n";
131 while ($#ARGV >= 0) {
132 if ($ARGV [0] eq "-u" or $ARGV [0] eq "-usage") {
136 if ($ARGV [0] eq "-vob") {
138 $vob_tag = $ARGV [0];
139 # Script all backslashes - we'll re-add them when needed...
145 if ($ARGV [0] eq "-view") {
147 $view_tag = $ARGV [0];
152 if (!(defined $view_tag or defined $vob_tag)) {
153 Usage "Must specify a view or a vob to tag!";
156 if (defined $view_tag) {
157 my ($view_storage, $view_region) = FindView $view_tag;
159 die "Unable to find view $view_tag in any region!\n" if !defined $view_region;
160 die "Unable to find storage area for $view_tag\n" if !defined $view_storage;
162 if ($view_region eq $current_region) {
163 print "$view_tag already exists in $current_region\n";
165 print "$view_tag, from $view_region region, added to $current_region region\n" if MkViewTag $view_tag, $view_storage;;
169 if (defined $vob_tag) {
170 my ($vob_storage, $vob_region) = FindVob $vob_tag;
172 die "Unable to find vob $vob_tag in any region!\n" if !defined $vob_region;
173 die "Unable to find storage area for $vob_tag\n" if !defined $vob_storage;
175 if ($vob_region eq $current_region) {
176 print "$vob_tag already exists in $current_region\n";
178 print "$vob_tag, from $vob_region, added to $current_region region\n" if MkVobTag $vob_tag, $vob_storage;;