123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #################################################################
- ## Licensed Materials - Property of IBM
- ##
- ## IBM Cognos Products: fmmd
- ##
- ## (C) Copyright IBM Corp. 2003, 2010
- ##
- ## US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- #################################################################
- # UpgradeActionLog.pl
- # Transforms one action log xml file or multiple files under one directory into log files used by the latest Framework Manager
- # To execute:
- # perl UpgradeActionLog.pl pathOfActionLogDirectory[File]
- # e.g.
- # perl UpgradeActionLog.pl log1.xml
- # or
- # perl UpgradeActionLog.pl logDirectory
- #
- #
- # George Chen 05/16/03
- use strict; # use strict use of variable naming
- sub doHelp(); # prototype
- # check for the help switches
- if ($#ARGV < 0) { # index of the last element, not the length
- doHelp(); # no params means display help info
- exit 0;
- } else {
- my($param);
- foreach $param (@ARGV) {
- if (($param =~ /[-,\/]h/i) || ($param eq "/?")) {# -h or -H or /h or /H or /? as any param means display help info
- doHelp();
- exit 0;
- }
- }
- }
- # check for the transformation parameters
- defined($ARGV[0]) or die "Error: No path to action log file(s) was specified.\n";
- # define the parameters
- my($inFile) = $ARGV[0];
- # check for the required XML file
- ( -e $inFile && -w _ )
- or die "Error: $inFile does not exist or is not writable.\n";
- # check for the xslt file
- my $xslFile = "UpgradeActionLog.xsl"; #Transformation file dafault file name
- -e $xslFile
- or die "Error: $xslFile does not exist in current directory.\n";
- # copy log file names to an array
- my @logFiles;
- if ( -f ($inFile) ) {
- @logFiles = ($inFile);
- }
- elsif ( -d ($inFile) ) {
- opendir LOGDIR, $inFile;
- @logFiles = map "$inFile/$_", (grep !/^\.\.?$/, readdir LOGDIR); # populate the array with log file's full path
- closedir LOGDIR;
- }
- # Iterate the log files array
- my $logFile;
- foreach $logFile(@logFiles ) {
- -w ($logFile)
- or warn("Error: Can't upgrade $logFile because it is read-only.\n"),
- next;
-
- # backup the log
- my $backupFile = "$logFile.backup";
- rename ( $logFile, $backupFile )
- or warn("Error: Stop upgrading $logFile because can't create a backup file $backupFile for it.\n"),
- next;
- # execute system command to do transformation
- my $com = "testXSLT -XD -Q -IN $backupFile -XSL $xslFile -OUT $logFile";
- system ($com ) ==0
- or warn( "Error: $com failed.\n"),
- rename ($backupFile, $logFile ),
- next;
- print "$logFile upgraded successfully, original file backed up in $backupFile.\n";
- }
- # function to display the help info
- sub doHelp () {
- print("\n");
- print("Name UpgradeActionLog.pl\n");
- print("\t Transforms one action log xml file or multiple files under one directory into log files used by the latest Framework Manager\n");
- print("\n");
- print("Syntax\n");
- print("\t perl UpgradeActionLog.pl [-hH] [/hH] [/?] pathOfActionLogDirectory[File]\n");
- print("\n");
- print("Switches\n");
- print("\t -h,-H,/h,/H,/?\t displays this help information\n");
- print("\n");
- print("Parameters\n");
- print("\t pathOfActionLogDirectory[File]\t path to log files or directory only contains log files\n");
- print("\n");
- print("Example\n");
- print("\t perl UpgradeActionLog.pl myLog.xml \n");
- print("\t perl UpgradeActionLog.pl myLogDir \n");
- print("\n");
- }
|