Megatest

Diff
Login

Differences From Artifact [f6c0a6448e]:

To Artifact [4147bb9d6c]:


610
611
612
613
614
615
616
617
618


619
620
621
































622
623
624
625
626
627
628
629
630
631
632
633
634
635
636







637
638
639
640

641
642
643
644
645
646
647
648
649
650
651

652

653

654
655
656
657

658
659
660

661


662

663
664
665
610
611
612
613
614
615
616


617
618



619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658







659
660
661
662
663
664
665
666
667
668

669
670
671
672
673
674
675
676
677
678
679

680
681
682

683
684
685
686

687
688
689

690
691
692
693

694
695
696
697







-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
+










-
+

+
-
+



-
+


-
+

+
+
-
+



;;======================================================================
;; Extract ods file from the db
;;======================================================================

;; runspatt is a comma delimited list of run patterns
;; keypatt-alist must contain *all* keys with an associated pattern: '( ("KEY1" "%") .. )
(define (db:extract-ods-file db outputfile keypatt-alist runspatt)
  (let ((keysstr  (string-intersperse (map car keypatt-alist) ","))
	(keyqry   (string-intersperse (map (lambda (p)(conc (car p) " like ? ")) keypatt-alist) " AND "))
  (let* ((keysstr  (string-intersperse (map car keypatt-alist) ","))
	 (keyqry   (string-intersperse (map (lambda (p)(conc (car p) " like ? ")) keypatt-alist) " AND "))
	(results   '())
	(test-ids '())
	(tempdir  (conc "/tmp/" (current-user-name) "/" runspatt "_" (random 10000) "_" (current-process-id))))
	 (test-ids '())
	 (tempdir  (conc "/tmp/" (current-user-name) "/" runspatt "_" (random 10000) "_" (current-process-id)))
	 (runsheader (append (list "Runname")
			     (map car keypatt-alist)
			     (list "Testname" 
				   "Description"
				   "Item Path"
				   "State"
				   "Status"
				   "Final Log"
				   "Run Duration"
				   "When Run"
				   "Expected Value"
				   "Value Found"
				   "Tolerance"
				   "Error"
				   "Warn"
				   "Tags"
				   "Run Owner"
				   "Comment"
				   "Author"
				   "Test Owner"
				   "Reviewed"
				   "Iterated"
				   "Diskfree"
				   "Uname"
				   "Rundir"
				   "Host"
				   "Cpu Load"
				   "Run Id")))
	 (results (list runsheader)))
    (debug:print 2 "Using " tempdir " for constructing the ods file")
    (apply sqlite3:for-each-row
     (lambda (test-id . b)
       (set! test-ids (cons test-id test-ids))
       (set! results (append results (list b)))) ;; note, drop the test-id
     db
     (conc "SELECT
              t.id,runname," keysstr ",t.testname,description,
              item_path,t.state,t.status,
              attemptnum,final_logf,logdat,run_duration,r.comment,
              t.event_time,expected_value,value,tol,tol_perc,
              first_err,first_warn,tm.tags,
              r.owner,t.comment,
              author,tm.owner,reviewed,iterated,avg_runtime,
              diskfree,uname,rundir,avg_disk,t.tags,run_id,
              host,cpuload
              final_logf,run_duration, 
              strftime('%m/%d/%Y %H:%M:%S',datetime(t.event_time,'unixepoch'),'localtime'),expected_value,value,tol,
              first_err,first_warn,tm.tags,r.owner,t.comment,
              author,
              tm.owner,reviewed,iterated,
              diskfree,uname,rundir,
              host,cpuload,run_id
            FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id INNER JOIN test_meta AS tm ON tm.testname=t.testname
            WHERE runname LIKE ? AND " keyqry ";")
     runspatt (map cadr keypatt-alist))
    (set! results (list "Runs" results))
    (set! results (list (cons "Runs" results)))
    ;; now, for each test, collect the test_data info and add a new sheet
    (for-each
     (lambda (test-id)
       (let ((test-data '())
	     (curr-test-name #f))
	 (sqlite3:for-each-row
	  (lambda (testname item_path category variable value comment)
	    (set! curr-test-name testname)
	    (set! test-data (append test-data (list (list testname item_path category variable value comment)))))
	  db 
	  "SELECT testname,item_path,category,variable,value,comment FROM test_data INNER JOIN tests ON tests.id=test_data.test_id WHERE test_id=?;"
	  "SELECT testname,item_path,category,variable,test_data.value AS value,test_data.comment AS comment FROM test_data INNER JOIN tests ON tests.id=test_data.test_id WHERE test_id=?;"
	  test-id)
	 (if curr-test-name
	 (set! results (append results (list (cons curr-test-name test-data))))
	     (set! results (append results (list (cons curr-test-name test-data)))))
	 ))
     test-ids)
    (system (conc "mkdir -p " tempdir))
    (pp results)
    ;; (pp results)
    (ods:list->ods 
     tempdir
     (if (string-match (regexp "^/") outputfile) ;; full path?
     (if (string-match (regexp "^[/~]+.*") outputfile) ;; full path?
	 outputfile
	 (begin
	   (debug:print 0 "WARNING: path given, " outputfile " is relative, prefixing with current directory")
	 (conc (current-directory) "/" outputfile))
	   (conc (current-directory) "/" outputfile)))
     results)))

;; (db:extract-ods-file db "outputfile.ods" '(("sysname" "%")("fsname" "%")("datapath" "%")) "%")