15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
;;
;; You should have received a copy of the GNU General Public License
;; along with Megatest. If not, see <http://www.gnu.org/licenses/>.
;;======================================================================
(declare (unit commonmod))
(declare (uses configfmod))
(module commonmod
*
(import scheme chicken data-structures extras)
(import (prefix sqlite3 sqlite3:) posix typed-records srfi-18)
(import (prefix sqlite3 sqlite3:) posix typed-records srfi-18 srfi-69 ports srfi-1 files format)
(import configfmod)
(include "common_records.scm")
(define (db:dbdat-get-path dbdat)
(if (pair? dbdat)
(cdr dbdat)
#f))
(define (common:get-area-name alldat)
(let* ((configdat (alldat-mtconfig alldat))
(areapath (alldat-areapath alldat)))
(or (configf:lookup configdat "setup" "area-name") ;; megatest is a flexible tool, testsuite is too limiting a description.
(configf:lookup configdat "setup" "testsuite" )
(get-environment-variable "MT_TESTSUITE_NAME")
(if (string? areapath )
(pathname-file areapath)
#f)))) ;; (pathname-file (current-directory)))))
;; return first path that can be created or already exists and is writable
;;
(define (common:get-create-writeable-dir dirs)
(if (null? dirs)
#f
(let loop ((hed (car dirs))
(tal (cdr dirs)))
(let ((res (or (and (directory? hed)
(file-write-access? hed)
hed)
(handle-exceptions
exn
(begin
;; TODO add print of exception here
;; (debug:print-info 0 *default-log-port* "could not create " hed ", this might cause problems down the road.")
#f)
(create-directory hed #t)))))
(if (and (string? res)
(directory? res))
res
(if (null? tal)
#f
(loop (car tal)(cdr tal))))))))
;; (define common:get-area-name common:get-area-name)
(define (common:get-db-tmp-area alldat)
(let* ((dbdir #f)
(log-port (alldat-log-port alldat)))
(if (alldat-tmppath alldat)
(alldat-tmppath alldat)
(if (alldat-areapath alldat) ;; common:get-create-writeable-dir
(handle-exceptions
exn
(begin
(debug:print-error 0 log-port "Couldn't create path to " dbdir)
(exit 1))
(let ((dbpath (common:get-create-writeable-dir
(list (conc "/tmp/" (current-user-name)
"/megatest_localdb/"
(common:get-area-name alldat) "/"
(string-translate (alldat-areapath alldat) "/" ".")))))) ;; #t))))
(set! dbdir dbpath)
(alldat-tmppath alldat dbpath)
dbpath))
#f))))
;; (define (debug:print . params) #f)
;; (define (debug:print-info . params) #f)
;;
;; (define (set-functions dbgp dbgpinfo)
;; (set! debug:print dbgp)
;; (set! debug:print-info dbgpinfo))
|