UpgradeActionLog.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #################################################################
  2. ## Licensed Materials - Property of IBM
  3. ##
  4. ## IBM Cognos Products: fmmd
  5. ##
  6. ## (C) Copyright IBM Corp. 2003, 2010
  7. ##
  8. ## US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. #################################################################
  10. # UpgradeActionLog.pl
  11. # Transforms one action log xml file or multiple files under one directory into log files used by the latest Framework Manager
  12. # To execute:
  13. # perl UpgradeActionLog.pl pathOfActionLogDirectory[File]
  14. # e.g.
  15. # perl UpgradeActionLog.pl log1.xml
  16. # or
  17. # perl UpgradeActionLog.pl logDirectory
  18. #
  19. #
  20. # George Chen 05/16/03
  21. use strict; # use strict use of variable naming
  22. sub doHelp(); # prototype
  23. # check for the help switches
  24. if ($#ARGV < 0) { # index of the last element, not the length
  25. doHelp(); # no params means display help info
  26. exit 0;
  27. } else {
  28. my($param);
  29. foreach $param (@ARGV) {
  30. if (($param =~ /[-,\/]h/i) || ($param eq "/?")) {# -h or -H or /h or /H or /? as any param means display help info
  31. doHelp();
  32. exit 0;
  33. }
  34. }
  35. }
  36. # check for the transformation parameters
  37. defined($ARGV[0]) or die "Error: No path to action log file(s) was specified.\n";
  38. # define the parameters
  39. my($inFile) = $ARGV[0];
  40. # check for the required XML file
  41. ( -e $inFile && -w _ )
  42. or die "Error: $inFile does not exist or is not writable.\n";
  43. # check for the xslt file
  44. my $xslFile = "UpgradeActionLog.xsl"; #Transformation file dafault file name
  45. -e $xslFile
  46. or die "Error: $xslFile does not exist in current directory.\n";
  47. # copy log file names to an array
  48. my @logFiles;
  49. if ( -f ($inFile) ) {
  50. @logFiles = ($inFile);
  51. }
  52. elsif ( -d ($inFile) ) {
  53. opendir LOGDIR, $inFile;
  54. @logFiles = map "$inFile/$_", (grep !/^\.\.?$/, readdir LOGDIR); # populate the array with log file's full path
  55. closedir LOGDIR;
  56. }
  57. # Iterate the log files array
  58. my $logFile;
  59. foreach $logFile(@logFiles ) {
  60. -w ($logFile)
  61. or warn("Error: Can't upgrade $logFile because it is read-only.\n"),
  62. next;
  63. # backup the log
  64. my $backupFile = "$logFile.backup";
  65. rename ( $logFile, $backupFile )
  66. or warn("Error: Stop upgrading $logFile because can't create a backup file $backupFile for it.\n"),
  67. next;
  68. # execute system command to do transformation
  69. my $com = "testXSLT -XD -Q -IN $backupFile -XSL $xslFile -OUT $logFile";
  70. system ($com ) ==0
  71. or warn( "Error: $com failed.\n"),
  72. rename ($backupFile, $logFile ),
  73. next;
  74. print "$logFile upgraded successfully, original file backed up in $backupFile.\n";
  75. }
  76. # function to display the help info
  77. sub doHelp () {
  78. print("\n");
  79. print("Name UpgradeActionLog.pl\n");
  80. print("\t Transforms one action log xml file or multiple files under one directory into log files used by the latest Framework Manager\n");
  81. print("\n");
  82. print("Syntax\n");
  83. print("\t perl UpgradeActionLog.pl [-hH] [/hH] [/?] pathOfActionLogDirectory[File]\n");
  84. print("\n");
  85. print("Switches\n");
  86. print("\t -h,-H,/h,/H,/?\t displays this help information\n");
  87. print("\n");
  88. print("Parameters\n");
  89. print("\t pathOfActionLogDirectory[File]\t path to log files or directory only contains log files\n");
  90. print("\n");
  91. print("Example\n");
  92. print("\t perl UpgradeActionLog.pl myLog.xml \n");
  93. print("\t perl UpgradeActionLog.pl myLogDir \n");
  94. print("\n");
  95. }