in reply to Re: code review?
in thread code review?
#!/usr/bin/perl #use strict; use warnings; use Carp; use File::Find; # globals $g_P4Base = "//depot/main/src/"; sub BuildPerforceFilePath { my ($imagefile, $path) = @_; my $ImageFilePath = ""; # strip the src="/ or src=" from the $imagefile variable. if ($imagefile =~ m/src=\"\//i) { $imagefile = "\/" . $'; } elsif ($imagefile =~ m/src=\"/i) { $imagefile = $'; } # remove double-quotes at end of string if ($imagefile =~ m/(\")$/) { $imagefile = $`; } my $fixedimagefile = $imagefile; # Append the forward slash at the beginning if there isn't one... if (!($fixedimagefile =~ m/^\//)) { $imagefile = "\/" . $imagefile; } # check to see if this image file is in the eMedSample path if ($path =~ m/([a-zA-Z0-9\_\-\/])+MMS-Apps\/eMedSample/i) { $ImageFilePath = "MMS-Apps/eMedSample/WwwRoot" . $imagefile; } # check to see if this image file is in the eSignature path elsif ($path =~ m/([a-zA-Z0-9\_\-\/])+MMS-Apps\/eSignature/i) { $ImageFilePath = "MMS-Apps/eSignature/eSignature.WEB" . $image +file; } # check to see if this image file is in the Partner-Apps path elsif ($path =~ m/([a-zA-Z0-9\_\-\/])+MMS-Apps\/Partner-Apps/i) { if ($path =~ m/([a-zA-Z0-9\_\-\/])+MMS-Apps\/Partner-Apps\/Hen +ryScheinSC/i) { $ImageFilePath = "MMS-Apps/Partner-Apps/HenryScheinSC/Henr +yScheinSC.WEB" . $imagefile; } elsif ($path =~ m/([a-zA-Z0-9\_\-\/])+MMS-Apps\/Partner-Apps\/ +SampleCenter/i) { $ImageFilePath = "MMS-Apps/Partner-Apps/SampleCenter/Sampl +eCenter.WEB" . $imagefile; } elsif ($path =~ m/([a-zA-Z0-9\_\-\/])+MMS-Apps\/Partner-Apps\/ +Lilly/i) { $ImageFilePath = "MMS-Apps/Partner-Apps/Lilly/LillyConnect +/LillyConnect.WEB" . $imagefile; } elsif ($path =~ m/([a-zA-Z0-9\_\-\/])+MMS-Apps\/Partner-Apps\/ +PartnerTest/i) { $ImageFilePath = "MMS-Apps/Partner-Apps/PartnerTest/Partne +rTest.WEB" . $imagefile; } else { $ImageFilePath = "Not sure what the path is here: $path\n" +; } } else { $ImageFilePath = "Not sure what the path is here: $path\n" +; } return $ImageFilePath; } # This function in addition to sub ReportFileFound { my ($filename, $imagefile, $linenum, $bBuildFilePath) = @_; # Convert backslashes to forward slashes my $P4ImagePath = $filename; $P4ImagePath =~ tr/\\/\//; # replace section of path with that of the Perforce Path if ($bBuildFilePath == 1) { my $ImageFilePath = BuildPerforceFilePath($imagefile, $P4Image +Path); $ImageFilePath = $g_P4Base . $ImageFilePath; $ImageFilePath =~ tr/\\/\//; InsertIntoList($ImageFilePath); } else { InsertIntoList($filename); } } # what we are doing now is to ignore all duplicate references to files + so that the list that is written only contains the sub InsertIntoList { my $ImagePath = shift(@_); my $aLength = $#FinalImageFileList + 1; my $bFound = 0; if ($aLength > 0) { # lets see if we can find the string in the array already... foreach $tmpImageFile (@FinalImageFileList) { #its not here so lets insert it... if ($tmpImageFile eq $ImagePath) { $bFound = 1; last; } } if (!$bFound) { push @FinalImageFileList, $ImagePath; print hLOGFILE "$ImagePath\n"; } } else { push @FinalImageFileList, $ImagePath; print hLOGFILE "$ImagePath\n"; } } sub CheckForImageReferencesInFiles { my $filename = $_; my $line = ""; my $linenum = 1; open hFile, $filename or die "Failed to open $filename\n"; while ($line = <hFile>) { chomp($line); if ($line =~ m/src="([a-zA-Z0-9\_\-\/])+\.(gif|jp[e]?g|bmp)"/i +) { $line = $&; ReportFileFound($saved_name, $line, $linenum, 1); } $linenum++; } close hFile; } sub CheckForImageReferencesInSQL { my($server, $username, $password, $DB) = @_; use MSSQL::Sqllib; # Log into the server. my $oSql = sql_init($server, $username, $password, $DB); my $p4Path = $g_P4Base; # now build the P4 depot path based on the DB we are using if ($DB eq "ems_prod") { $p4Path .= "MMS-Apps/eMedSample/Wwwroot"; } elsif ($DB eq "esignature") { $p4Path .= "MMS-Apps/eSignature/eSignature.WEB"; } elsif ($DB eq "ems_directchannel") { } else { } my $p4FQP = $p4Path; # Run a query. my @QueryResult = $oSql->sql("SELECT imgPath From Images Where Sta +tusCode = 1"); # Just print the results, it's a list of hashes. foreach $QueryResult (@QueryResult) { foreach $row (keys %$QueryResult) { $p4FQP .= $$QueryResult{$row}; ReportFileFound($p4FQP, 0, 0, 0); } $p4FQP = $p4Path; } } sub ListFileNames { $saved_name = $File::Find::name; # looking for filenames whose extensions are the oens I want (jpg, + jpeg, js, xml) if ($saved_name =~ m/\.(cs|asp[x]?|js|xml)$/i) { # replace all forward slashes with back-slashes $saved_name =~ tr/\//\\/; # Look for image files beign referenced in the file. CheckForImageReferencesInFiles($saved_name); } } @ARGV = (".") unless @ARGV; $g_FirstCall = 1; $g_Searchpath = shift(@ARGV); $g_logfile = "C:\\Scan4Images.txt"; @FinalImageFileList = (); if (-e $g_logfile and $g_FirstCall != 0) { unlink $g_logfile; $g_FirstCall = 0; } open hLOGFILE, ">>$g_logfile" or die "Could not open the file $g_logfi +le\n"; print hLOGFILE "From Source code files:\n\n"; find(\&ListFileNames, $g_Searchpath); print hLOGFILE "\n\n"; print hLOGFILE "From SQL Queries:\n\n"; CheckForImageReferencesInSQL("emsdbserver", "emsuser", "Mmsmms12", "em +s_prod"); close hLOGFILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: code review? (review)
by kyle (Abbot) on Jun 11, 2008 at 17:50 UTC | |
|
Re^3: code review?
by toolic (Bishop) on Jun 11, 2008 at 18:35 UTC |