psadd (PeopleSoft-CCC/Harvest add items

The PeopleSoft add Perl script is used by developers to add new items into the CCC/Harvest repository.
#!/usr/local/bin/perl
#*************************************************************************
#* Script Name:      psadd
#* Creation Date:    10/1/99 
#* Location:         
#* Calling Routine:  NONE
#* Input Parameters: NONE
#* Associated Files: listviewpaths.sql
#* Description:      
#*                  
#* Change Log
#* Name            Date   Change
#* --------------- ------ ------------------------------------------------
#* Paul McKinney   10/1/99 Creation
#*                   
#*************************************************************************

#********************************************************************
#* MAINLINE 
#*
#* -set base directory where files will be checked in to  
#* -clear screen
#* -call subroutine to have user select package
#* -call subroutine to have user select item to check in from package
#* -if item is a type of "pco" then
#*    compile cobol program
#* -call subroutine to check in module into Harvest
#* -synchronize module out to appropriate directory
#********************************************************************
 
$sqlpath="/usr/local/bin";
$repository="ISAS";

system("clear");
&select_environment;
&select_package;
while (1) {

   &enter_file_name;
   &select_viewpath;
   &checkin_module;

   if ($envbase ne "" )  {
      &synchronize_module;
   }
}


#********************************************************************
#* select_environment
#*
#********************************************************************
sub select_environment {
   print "Check In\n\n";
   print "1) PS-Sybase v7.5 Baseline\n";
   print "2) PS-Sybase v7.5 with ISAS Mods\n";
   print "3) PS-Sybase v7 Baseline\n";
   print "4) PS-Sybase v7 with ISAS Mods\n\n";
   print "5) PS-Oracle v7.5 Baseline\n";
   print "6) PS-Oracle v7.5 with ISAS Mods\n";
   print "7) PS-Oracle v7 Baseline\n";
   print "8) PS-Oracle v7 with ISAS Mods\n\n";

   print "Select a environment: ";
   $selection = <STDIN>;
   chop($selection);

   if($selection  eq "1") {
      $environmentname = "PS-Sybase v7.5 Baseline";
      $statename = "Receive";
      $envbase=""; 
      $environmentcode = "75bas"
   } elsif ($selection eq "2") {
      $environmentname = "PS-Sybase v7.5 with ISAS Mods";
      $statename = "Development";
      $envbase="/psoftSYD/ps75/syb/dev";
      $environmentcode = "75dev"
   } elsif ($selection eq "3") {
      $environmentname = "PS-Sybase v7 Baseline";
      $statename = "Receive";
      $envbase=""; 
      $environmentcode = "7bas"
   } elsif ($selection eq "4") {
      $environmentname = "PS-Sybase v7 with ISAS Mods";
      $statename = "Development";
      $envbase="/psoftSYD/ps70/syb/dev";
      $environmentcode = "7dev"
   } elsif ($selection eq "5") {
      $environmentname = "PS-Oracle v7.5 Baseline";
      $statename = "Receive";
      $envbase=""; 
      $environmentcode = "75bas"
   } elsif ($selection eq "6") {
      $environmentname = "PS-Oracle v7.5 with ISAS Mods";
      $statename = "Development";
      $envbase="/psoftSYD/ps75/ora/dev";
      $environmentcode = "75dev"
   } elsif ($selection eq "7") {
      $environmentname = "PS-Oracle v7 Baseline";
      $statename = "Receive";
      $envbase=""; 
      $environmentcode = "7bas"
   } elsif ($selection eq "8") {
      $environmentname = "PS-Oracle v7 with ISAS Mods";
      $statename = "Development";
      $envbase="/psoftSYD/ps70/ora/dev";
      $environmentcode = "7dev"
   } else {
      exit;
   }

}


#********************************************************************
#* select_package
#*
#* -call harvest hsql program to list packages
#* -while  there are more packages
#*    store package names in an array
#* -get input from user
#* -if selection equal "q" then exit
#* -based on user selection store package name
#********************************************************************
sub select_package {
   print "\nIn order to check in a module the changed module must be\n";
   print "associated with a package. Retrieving packages...\n\n";
   open(CMD, "cat $sqlpath/listpackages.sql | sed \"s/\\[environmentname\\]/$environmentname/g\" | sed \"s/\\[statename\\]/$statename/g\" | /tools/Harvest/bin/hsql -t -s -nh |");
   $i = 1;
   while (<CMD>) {
      @packages = (@packages, $_);
      print "$i) $_";
      ++$i;
   }
   close(CMD);
   print "q) Quit\n\n";

   print "Select a package: ";
   $selection = <STDIN>;
   chop($selection);
   if ($selection  eq "q") {
      exit;
   }
   print "\n";
   $packagename = $packages[$selection - 1];
   chop($packagename);
}


#********************************************************************
#* enter_file_name
#*
#********************************************************************
sub enter_file_name {

   print "Enter file name for check in: ";
   $selection = <STDIN>;
   chop($selection);

   if ($selection  eq "") {
      exit;
   }

   $filename = $selection;
   print "\n";
}


#********************************************************************
#* select_viewpath
#*
#* 
#*
#********************************************************************
sub select_viewpath {

   print "File must be checked into designated viewpath.\n\n";
   open(CMD, "cat $sqlpath/listviewpaths.sql | sed \"s/\\[repositoryname\\]/$repository/g\" | /tools/Harvest/bin/hsql -t -s -nh |");
   $i = 1;
   while (<CMD>) {
      @viewpaths = (@viewpaths, $_);
      print "$i) $_";
      ++$i;
   }
   close(CMD);
   print "q) Quit\n\n";

   print "Select a viewpath: ";
   $selection = <STDIN>;
   chop($selection);
   if ($selection  eq "q") {
      exit;
   }
   print "\n";
   $viewpathname = $viewpaths[$selection - 1];
   chop($viewpathname);
   $viewpathname = "/$viewpathname"

}


#********************************************************************
#* checkin_module
#*
#* -use Harvest hci to check in module
#********************************************************************
sub checkin_module {
   print "Checking in module: $filename\n";
   if ($viewpathname =~ /^\/$repository\/tools/) {
      chmod(0550,$filename);
   } else {
      chmod(0440,$filename);
   }

   $checkin_mode = "-ur";
   $flag = FALSE;
   open(CMD,"hci -en \"$environmentname\" -st \"$statename\"                                            -p \"$packagename\" -vp \"$viewpathname\" $checkin_mode                         -op p \"$filename\" |");
   while (<CMD>) {
      $printline = $_;
      print "$printline";
      if (substr($_, 0, 1) eq "E") {
         $flag = TRUE;
      }
   }
   close(CMD);
   if ($flag eq "TRUE") {
       exit;
   }
   print "Check in successful.\n";
         
}
 
#********************************************************************
#* synchonize_module
#*
#* -change directories and use sudo to call hco command to check out
#*  Harvest item
#* -if a pco file then 
#*    move object code and file listing to appropriate directories
#* -if item from sqr path then checkout to sqr directory
#* -if item from tools path then checkout to tools directory
#* -if item from cust path then checkout to cust directory
#********************************************************************
sub synchronize_module {
   print "synchronizing...\n";
   if ($viewpathname =~ /^\/$repository\/src/) {
      system ("cd $envbase/src; sudo -u psoft /tools/Harvest/bin/hco                            -en \"$environmentname\" -st \"$statename\"                                           -pn \"Synchronize\" -p \"$packagename\"                           -vp \"/$repository/src/\" -sy -op p -r -s $filename");
   }
   if ($filename =~ /\.sh$/) {
      system ("sudo -u psoft /home/psoft/scripts/harpsrun $environmentcode                     putshell $filename")
                     && die "putshell of $filename failed";
   }
   if ($viewpathname =~ /^\/$repository\/sqr/) {
      system ("cd $envbase/sqr; sudo -u psoft /tools/Harvest/bin/hco                         -en \"$environmentname\" -st \"$statename\"                                            -pn \"Synchronize\" -p \"$packagename\"                                         -vp \"/$repository/sqr/\" -sy -op p -r -s $filename");
   }
   if ($viewpathname =~ /^\/$repository\/tools/) {
      system ("cd $envbase/tools; sudo -u psoft /tools/Harvest/bin/hco                       -en \"$environmentname\" -st \"$statename\"                                           -pn \"Synchronize\" -p \"$packagename\"                                         -vp \"/$repository/tools/\" -sy -op p -r -s $filename");
   }
   if ($viewpathname =~ /^\/$repository\/cust/) {
      system ("cd $envbase/cust; sudo -u psoft /tools/Harvest/bin/hco                        -en \"$environmentname\" -st \"$statename\"                                            -pn \"Synchronize\" -p \"$packagename\"                                         -vp \"/$repository/cust/\" -sy -op p -r -s $filename");
   }
}