GOAL:-
I need to parse a file with the below input and get the latest (builddate timestamp should be latest)location when the status is approved and builddate is the latest..I provided sample input and output,I have the code in perl,new to python,please suggest how can this be implemented in python
INPUT:-
Build: M1234BAAAANAAW9321.1
Location: \\dreyers\builds468\INTEGRATION\M1234BAAAANAA9321.1
Comments: Build completed, labeled, and marked for retention.
Status: Approved
BuildDate: 10/25/2012 12:51:25
Build: M1234BAAAANAAW9321.2
Location: \\crmbld01\Builds\FAILED\M1234BAAAANAA9321.2
Comments: The build is currently in a failed status.
Status: Failed
BuildDate: 10/25/2012 19:37:17
Build: M1234BAAAANAAW9321.3
Location: \\freeze\builds427\INTEGRATION\M1234BAAAANAA9321.3
Comments: Build completed, labeled, and marked for retention.
Status: Approved
BuildDate: 10/25/2012 19:43:28
OUTPUT:-\\freeze\builds427\INTEGRATION\M1234BAAAANAA9321.3
Following is the perl code that achieves,I am new to python,please suggest how can I pythonize this code
$ echo 'Build: M1234BAAAANAAW9321.1
Location: \\dreyers\builds468\INTEGRATION\M1234BAAAANAAW9321.1
Comments: Build completed, labeled, and marked for retention.
Status: Approved
BuildDate: 10/25/2012 12:51:25
Build: M1234BAAAANAAW9321.2
Location: \\crmbld01\Builds\FAILED\M1234BAAAANAAW9321.2
Comments: The build is currently in a failed status.
Status: Failed
BuildDate: 10/25/2012 19:37:17
Build: M1234BAAAANAAW9321.3
Location: \\freeze\builds427\INTEGRATION\M1234BAAAANAAW9321.3
Comments: Build completed, labeled, and marked for retention.
Status: Approved
BuildDate: 10/25/2012 19:43:28
' | perl -e'
local $/ = "";
my ( $build_date, $location );
while ( <> ) {
next unless /status:\s+approved/i;
my $date = sprintf "%04d%02d%02d%02d%02d%02d", ( /builddate:\s+(\d
++)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)/i )[ 2, 0, 1, 3, 4, 5 ];
if ( !defined $build_date || $build_date lt $date ) {
( $build_date, $location ) = ( $date, /location:\s+(.+)/i );
}
}
print “$location\n”;
‘
\freeze\builds427\INTEGRATION\M1234BAAAANAAW9321.3
I tried to write the following in python,doesnt seem to work,am wondering if there is a better implementation to achieve the goal..please suggest
for line_info in lines:
line_info.find('Location')
if line_info.find('Location') == 0:
# Build Location
print " Found Build location"
logString += " Found Build location\n"
location = line_info.split(" ")
location1 = location[len(location)-1]
elif line_info.find('Status') == 0:
# Status
print " Found Status"
logString += " Found Status\n"
status = line_info.split(" ")
removeEmpty(status)
status1 = status[1].strip()
if status1 != "Approved"
goto .start
elif line_info.find('BuildDate') == 0:
# Main Make
print " Found BuildDate"
logString += " Found BuildDate\n"
builddate1 = line_info.split(" ")
removeEmpty(builddate1)
builddate1 = builddate1[1]
#if builddate1 >
Try this code: