about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2022-05-04 19:52:51 +0530
committerArun Isaac2022-05-04 19:52:51 +0530
commitdd2e09270d5e1390bdeb0e6dc4d865326aa1e78d (patch)
tree51c82d51dd8b869b1b6b4a13a7eaaabb9b30a4b1
parent1b96fb54e751923afc0e783135dc6035559ecd0e (diff)
downloadgn-transform-databases-dd2e09270d5e1390bdeb0e6dc4d865326aa1e78d.tar.gz
Read SPARQL connection settings from file.
* visualize-schema.scm (%sparql-host, %sparql-port): New parameters.
(sparql-query-records): Use %sparql-host and %sparql-port parameters.
(main): Accept connection settings file as argument, read it, and
parameterize %sparql-host and %sparql-port.
Pass command-line arguments to main.
-rwxr-xr-xvisualize-schema.scm32
1 files changed, 24 insertions, 8 deletions
diff --git a/visualize-schema.scm b/visualize-schema.scm
index 0e203bd..6850cb8 100755
--- a/visualize-schema.scm
+++ b/visualize-schema.scm
@@ -31,13 +31,19 @@
 (define html-string (@@ (ccwl graphviz) html-string))
 (define graph->dot (@@ (ccwl graphviz) graph->dot))
 
+(define %sparql-host
+  (make-parameter #f))
+
+(define %sparql-port
+  (make-parameter #f))
+
 (define (sparql-query-records . args)
   ;; TODO: Use the JSON query results so that types can be converted
   ;; correctly.
   (query-results->list (apply sparql-query
                               (append args
-                                  (list #:host "127.0.0.1"
-                                        #:port 8891)))
+                                      (list #:host (%sparql-host)
+                                            #:port (%sparql-port))))
                        #t))
 
 (define (floor-log1024 x)
@@ -272,10 +278,20 @@ PORT."
           #:edges (rdf-edges))
    port))
 
-(define (main)
-  (call-with-output-file "sql.dot"
-    write-sql-visualization)
-  (call-with-output-file "rdf.dot"
-    write-rdf-visualization))
+(define main
+  (match-lambda*
+    ((_ connection-settings-file)
+     (let ((connection-settings (call-with-input-file connection-settings-file
+                                  read)))
+       (parameterize ((%sparql-host (assq-ref connection-settings 'sparql-host))
+                      (%sparql-port (assq-ref connection-settings 'sparql-port)))
+         (call-with-output-file "sql.dot"
+           write-sql-visualization)
+         (call-with-output-file "rdf.dot"
+           write-rdf-visualization))))
+    ((arg0 _ ...)
+     (display (format "Usage: ~a CONNECTION-SETTINGS-FILE~%" arg0)
+              (current-error-port))
+     (exit #f))))
 
-(main)
+(apply main (command-line))