 (comment (defn- print-datasets []
    (dorun (map println (datasets)))))
 
-; XXX should add ring jsonp
+; XXX add ring jsonp?
 (defn- get-app [db loader]
   (-> cavm.views.datasets/routes
       (wrap-trace :header :ui)

                  (println "Unable to create directory" docroot))
                (do
                  (when (:auto opts)
                    (watch (partial file-changed loader) docroot))
                  (when (:serve opts)
                    (serv (get-app db loader) port)))))))
  (shutdown-agents))

; (def testdb (create-xenadb "test;TRACE_LEVEL_FILE=3"))
; (def testdb (create-xenadb "/inside/home/craft/xena/database;TRACE_LEVEL_FILE=3"))
; (def testdetector (apply cr/detector "/inside/home/craft/xena/files" detectors))
; (def testloader (partial cl/loader testdb testdetector "/inside/home/craft/xena/files"))
; (def app (get-app testdb testloader))
; (defonce server (ring.adapter.jetty/run-jetty #'app {:port 7222 :join? false}))
; (.start server)

  [cgdata/detect-cgdata
   cgdata/detect-tsv])

; Full reload metadata. The loader will skip
; data files with unchanged hashes.
(defn file-changed [loader docroot kind file]
  (doseq [f (rest (file-seq (io/file docroot)))] ; skip docroot (the first element)
    (try (loader f)
      (catch Exception e (println (str "caught exception: " (.getMessage e))))))) ; XXX this is unhelpful. Log it somewhere.

(def xenadir-default (str (io/file (System/getProperty  "user.home") "xena")))
(def docroot-default (str (io/file xenadir-default "files")))
