[cxtest-cvs] Peter Nociar : Enhance the functionality of sending wine logs

Jozef Stefanka jstefanka at codeweavers.com
Thu Apr 3 09:59:28 CDT 2008


Module: cxtest
Branch: master
Commit: fa219e6ac95ddaa2c17749343246419128337bde
URL:    http://foghorn.codeweavers.com/git/cxtest/cxtest.git/?a=commit;h=fa219e6ac95ddaa2c17749343246419128337bde

Author: Peter Nociar <peter.nociar at ifne.eu>
Date:   Thu Apr  3 09:11:18 2008 +0200

Enhance the functionality of sending wine logs

---

 scripts/run.sh           |    4 +-
 web/cxtest_xml_to_db.php |  113 +++++++++++++++++++++------------------------
 2 files changed, 55 insertions(+), 62 deletions(-)

diff --git a/scripts/run.sh b/scripts/run.sh
index 41a6d74..6da3568 100755
--- a/scripts/run.sh
+++ b/scripts/run.sh
@@ -553,7 +553,7 @@ process_run () {
                     log_xml_attachment "$LOG_DIR/$PACKAGE/${CURR_STEP}${OUTPUT_EXT}" "LOG" "Install $PACKAGE log file"
                   if [ "$WINE_LOG" = "ALWAYS" ] || [ "$WINE_LOG" = "ONFAIL" ]; then
                     if [ $return_status -eq 1 ] || [ "$WINE_LOG" = "ALWAYS" ]; then
-                      log_xml_attachment "$LOG_DIR/$PACKAGE/$CURR_STEP.winelog.gz" "LOG" "Install $PACKAGE wine log file"
+                      log_xml_attachment "$LOG_DIR/$PACKAGE/$CURR_STEP.winelog.gz" "LOG_GZ" "Install $PACKAGE wine log file"
                     fi
                   fi
                 fi
@@ -687,7 +687,7 @@ process_run () {
                     log_xml_attachment "$LOG_DIR/$PACKAGE/${CURR_STEP}${OUTPUT_EXT}" "LOG" "Test $PACKAGE:$CURR_STEP log file"
                     if [ "$WINE_LOG" = "ALWAYS" ] || [ "$WINE_LOG" = "ONFAIL" ]; then
                       if [ $return_status -eq 1 ] || [ "$WINE_LOG" = "ALWAYS" ]; then
-                        log_xml_attachment "$LOG_DIR/$PACKAGE/$CURR_STEP.winelog.gz" "LOG" "Install $PACKAGE wine log file"
+                        log_xml_attachment "$LOG_DIR/$PACKAGE/$CURR_STEP.winelog.gz" "LOG_GZ" "Install $PACKAGE wine log file"
                       fi
                     fi
                   fi
diff --git a/web/cxtest_xml_to_db.php b/web/cxtest_xml_to_db.php
old mode 100644
new mode 100755
index b906391..abe3d5e
--- a/web/cxtest_xml_to_db.php
+++ b/web/cxtest_xml_to_db.php
@@ -281,6 +281,43 @@ function return_status($status)
   return $status;
 }
 
+
+/*----------------------------------------------------------------------------
+**  Store attachment into $att_path. Compress it with bzip2 algorithm if it is 
+**  not an image or already compressed file 
+**--------------------------------------------------------------------------*/
+function store_attachments($att_path,$att_type,$att_name,$att_body)
+{
+  $apath = $att_path;
+  $atype = preg_replace("/\s*$/","",preg_replace("/^\s*/","",$att_type));
+  if($atype == 'LOG_GZ')
+  {
+    $apath .= '.gz';
+  } 
+ 
+  // Do not compress images (IMAGE) and gziped logs (LOG_GZ)
+  debug("Type: ".$atype);
+  if (!($atype =='IMAGE' || $atype == 'LOG_GZ')) {
+    // compressed file
+    debug("Compressing :".$atype);
+    $apath .= '.bz2';
+    debug("** Creating file ".$apath." for attachment: ".$att_name);
+    $fstream = bzopen($apath,'w');
+    bzwrite($fstream, $att_body,strlen($att_body));
+    bzclose($fstream);
+  } else {
+    debug("Not Compressing :".$atype);
+    // regular file
+    debug("** Creating file ".$apath." for attachment: ".$att_name);
+    $fstream = fopen($apath,'w');
+    fwrite($fstream, $att_body);
+    fclose($fstream);
+  }
+  chmod($apath, 0666);
+  unset($att_name, $apath);
+
+}
+
 /*----------------------------------------------------------------------------
 **  parse a CXtest XML file into the web database
 **--------------------------------------------------------------------------*/
@@ -869,25 +906,10 @@ function parse_cxtest_xml (&$raw_data)
                       errexit("invalid query: ".mysql_error());
                     }
 
-                    if (preg_replace("/\s*$/","",preg_replace("/^\s*/","",$data['RUN'][$i]['INSTALL'][$k][$j]['TYPE']))!='IMAGE') {
-                       // compressed file
-                       $aname = IMAGE_DIR.mysql_insert_id().'.bz2';
-                       debug("** Creating file ".$aname." for attachment: ".$fname);
-                       $fstream = bzopen($aname,'w');
-                       bzwrite($fstream, $mime->parts[$attachment_index[$fname]]->body,strlen($mime->parts[$attachment_index[$fname]]->body));
-                       bzclose($fstream);
-                       chmod($aname, 0666);
-                       unset($fname, $aname);
-                    } else {
-                       // regular file
-                       $aname = IMAGE_DIR.mysql_insert_id();
-                       debug("** Creating file ".$aname." for attachment: ".$fname);
-                       $fstream = fopen($aname,'w');
-                       fwrite($fstream, $mime->parts[$attachment_index[$fname]]->body);
-                       fclose($fstream);
-                       chmod($aname, 0666);
-                       unset($fname, $aname);
-                    }
+                    store_attachments(IMAGE_DIR.mysql_insert_id(),
+                                      $data['RUN'][$i]['INSTALL'][$k][$j]['TYPE'],
+                                      $fname,
+                                      $mime->parts[$attachment_index[$fname]]->body);
                  }
               }
            }
@@ -927,25 +949,10 @@ function parse_cxtest_xml (&$raw_data)
               errexit("invalid query: ".mysql_error());
             }
 
-            if (preg_replace("/\s*$/","",preg_replace("/^\s*/","",$data['RUN'][$i]['INSTALL'][$k]['TYPE']))!='IMAGE') {
-                // compressed file
-                $aname = IMAGE_DIR.mysql_insert_id().'.bz2';
-                debug("** Creating file ".$aname." for attachment: ".$fname);
-                $fstream = bzopen($aname,'w');
-                bzwrite($fstream, $mime->parts[$attachment_index[$fname]]->body,strlen($mime->parts[$attachment_index[$fname]]->body));
-                bzclose($fstream);
-                chmod($aname, 0666);
-                unset($fname, $aname);
-            } else {
-               // regular file
-               $aname = IMAGE_DIR.mysql_insert_id();
-               debug("** Creating file ".$aname." for attachment: ".$fname);
-               $fstream = fopen($aname,'w');
-               fwrite($fstream, $mime->parts[$attachment_index[$fname]]->body);
-               fclose($fstream);
-               chmod($aname, 0666);
-               unset($fname, $aname);
-            }
+            store_attachments(IMAGE_DIR.mysql_insert_id(),
+                              $data['RUN'][$i]['INSTALL'][$k]['TYPE'],
+			      $fname,
+                              $mime->parts[$attachment_index[$fname]]->body);
           }
           else
           {
@@ -1097,25 +1104,10 @@ function parse_cxtest_xml (&$raw_data)
               errexit("invalid query: ".mysql_error());
             }
 
-            if (preg_replace("/\s*$/","",preg_replace("/^\s*/","",$data['RUN'][$i][$j][$k]['TYPE']))!='IMAGE') {
-                // compressed file
-                $aname = IMAGE_DIR.mysql_insert_id().'.bz2';
-                debug("** Creating file ".$aname." for attachment: ".$fname);
-                $fstream = bzopen($aname,'w');
-                bzwrite($fstream, $mime->parts[$attachment_index[$fname]]->body,strlen($mime->parts[$attachment_index[$fname]]->body));
-                bzclose($fstream);
-                chmod($aname, 0666);
-                unset($fname, $aname);
-            } else {
-               // regular file
-               $aname = IMAGE_DIR.mysql_insert_id();
-               debug("** Creating file ".$aname." for attachment: ".$fname);
-               $fstream = fopen($aname,'w');
-               fwrite($fstream, $mime->parts[$attachment_index[$fname]]->body);
-               fclose($fstream);
-               chmod($aname, 0666);
-               unset($fname, $aname);
-            }
+            store_attachments(IMAGE_DIR.mysql_insert_id(),
+                              $data['RUN'][$i][$j][$k]['TYPE'],
+			      $fname,
+                              $mime->parts[$attachment_index[$fname]]->body);
           }
           else
           {
@@ -1136,7 +1128,7 @@ $dir = opendir(QUEUE_DIR);
 while($file = readdir($dir))
 {
   // skip incorrect filenames
-  if(!preg_match('/^MSG/', $file))
+  if(preg_match('/^ERR/', $file))
       continue;
    
   // open and read file from queue
@@ -1166,13 +1158,13 @@ while($file = readdir($dir))
     // successful, delete queue file
     debug("++ parse successful!");
     if (file_exists(QUEUE_DIR.'/'.$file))
-        unlink(QUEUE_DIR.'/'.$file);
+      unlink(QUEUE_DIR.'/'.$file);
   }
   else
   {
     // failed, rename to ERR
     debug("++ parse FAILED!");
-    $errfile = preg_replace('/^(MSG)(.*)/', 'ERR\\2', $file);
+    $errfile = "ERR".$file;
     if (file_exists(QUEUE_DIR.'/'.$file))
         rename(QUEUE_DIR.'/'.$file, QUEUE_DIR.'/'.$errfile);
     unset($errfile);
@@ -1209,3 +1201,4 @@ close_all();
 exit(0);
 
 ?>
+




More information about the cxtest-cvs mailing list