123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- use strict;
- sub doHelp();
- if ($#ARGV < 0) {
- doHelp();
- exit 0;
- } else {
- my($param);
- foreach $param (@ARGV) {
- if (($param =~ /[-,\/]h/i) || ($param eq "/?")) {
- doHelp();
- exit 0;
- }
- }
- }
- defined($ARGV[0]) or die "Error: No path to action log file(s) was specified.\n";
- my($inFile) = $ARGV[0];
- ( -e $inFile && -w _ )
- or die "Error: $inFile does not exist or is not writable.\n";
- my $xslFile = "UpgradeActionLog.xsl";
- -e $xslFile
- or die "Error: $xslFile does not exist in current directory.\n";
- my @logFiles;
- if ( -f ($inFile) ) {
- @logFiles = ($inFile);
- }
- elsif ( -d ($inFile) ) {
- opendir LOGDIR, $inFile;
- @logFiles = map "$inFile/$_", (grep !/^\.\.?$/, readdir LOGDIR);
- closedir LOGDIR;
- }
- my $logFile;
- foreach $logFile(@logFiles ) {
- -w ($logFile)
- or warn("Error: Can't upgrade $logFile because it is read-only.\n"),
- next;
-
-
- 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;
-
- 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";
- }
- 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");
- }
|