#! /Usr/bin/perl
Use strict;
Use warnings;
Use dBi;
Opendir (Dir, "dirpath/") | die "can not open it ";
My @ connect = readdir (DIR );
Closedir dir;
My $ dir_need;
Foreach my $ con (sort @ Connect ){
If ($ con = ~ /-[0-9] {2}-[0-9] {2 }_/){
$ Dir_need = $ con;
}
}
My $ database = "DBI: mysql: Database ";
My $ username = "root ";
My $ Password = "password ";
My $ mysql_dbh = DBI-> connect ($ database, $ username, $ password) | die "database connection not made: $ DBI: errstr ";
My $ count;
My @ type = QW [stf utf merged];
For ($ COUNT = 0; $ count <3; $ count ++)
{
Open (Python, "/dirpath/$ dir_need/$ type [$ count]/Python/index.html") | die "can not open it ";
My @ connect = <Python>;
Close Python;
My $ flag = 0;
My $ data_hash;
My $ file_name;
My @ name_arr = QW [statements run excluded branches br_exec coverage];
My @ key_name;
My $ Index = 0;
Foreach my $ eachline (@ Connect ){
Chomp $ eachline;
If ($ eachline = ~ /<TD class = 'name left'> <. *?> (.*?) <\//)
{
$ Flag = 1;
$ File_name = $1;
Push (@ key_name, $1 );
}
Elsif ($ eachline = ~ /<TD> ([0-9] +) <\/TD>/& $ flag)
{
$ Data_hash-> {$ file_name}-> {$ name_arr [$ index ++]} = $1;
}
Elsif ($ eachline = ~ /<TD class = 'right'> (. *) % <\/TD>/& $ flag)
{
$ Data_hash-> {$ file_name}-> {$ name_arr [$ Index]} = $1;
$ Index = 0;
$ Flag = 0;
}
}
Foreach my $ key (@ key_name)
{
My $ SQL = "insert into python_coverage (builds_time, framework, file, statements, run, excluded, branches, br_exec, coverage)
Values (?,?,?,?,?,?,?,?,?) ";
My $ something = $ mysql_dbh-> prepare ($ SQL );
$ Something-> bind_param (1, $ dir_need );
If ($ COUNT = 2) {$ something-> bind_param (2, "all ");}
Else {$ something-> bind_param (2, $ type [$ count]);}
$ Something-> bind_param (3, $ key );
My $ para_index = 4;
For ($ Index = 0; $ index <6; $ index ++)
{
$ Something-> bind_param ($ para_index, $ data_hash-> {$ key}-> {$ name_arr [$ Index]});
$ Para_index ++;
}
$ Something-> execute ();
}
}