Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Beginnings of gal db writer (just knows how to safely delete previous)

  • Loading branch information...
commit c6df0ed9ba3cc7782e641076eaa5d2690419a87c 1 parent 8ac8a97
@timmc authored
View
4 clj/src/kpawebgen/core.clj
@@ -4,6 +4,7 @@
(:use [clojopts.core :only (clojopts with-arg optional-arg)])
(:require kpawebgen.slurp
kpawebgen.munge
+ kpawebgen.spit
clojure.repl))
(def ^{:doc "Boolean indicating whether debug mode is on", :dynamic true}
@@ -14,8 +15,7 @@
[{:keys [config] :as opts}]
(->> (kpawebgen.slurp/read config)
(kpawebgen.munge/shadow->localweb config)
- keys
- (println "Tables:")))
+ (kpawebgen.spit/write config)))
(def ^{:doc "Map of task keywords to functions (taking command-line options)."}
tasks {:localweb localweb})
View
33 clj/src/kpawebgen/spit.clj
@@ -0,0 +1,33 @@
+(ns kpawebgen.spit
+ "Produce thumbnails/watermarked images and SQL database from in-memory
+data structures and photo store."
+ (:require [clojure.java.jdbc :as sql]
+ clojure.java.jdbc.internal
+ clojure.java.shell
+ kpawebgen.config
+ [kpawebgen.util :as u])
+ (:use [org.timmc.handy :only (version-norm)]
+ [slingshot.slingshot :only [throw+]]))
+
+(defn wipe-dest
+ "Wipe destination files and folders."
+ [conf]
+ (let [conf-base (u/file (kpawebgen.config/config-dir conf))
+ gal-db (u/file conf-base (:gal_db_path conf))
+ ;;TODO data-dir (u/file conf-base (:data_dir conf))
+ ]
+ ;; check if DB is there or createable
+ (when-not (u/file-type-match-any? gal-db [#"(?i)sqlite"]
+ :ok-missing? true, :ok-empty? true)
+ (throw+ {:type ::target-db-file-type-on-deletion,
+ :msg (format "Refusing to overwrite file %s, not SQLite or empty"
+ gal-db)}))
+ (.delete gal-db)))
+
+(defn write
+ "Write website data out to disk and generate all files.
+
+Does not yet optimize based on diff to last localweb generation."
+ [config db]
+ (wipe-dest config)
+ (println "Tables:" (keys db)))
View
4 clj/test/kpawebgen/test/util.clj
@@ -18,7 +18,7 @@
[f & args]
(apply f (apply concat (butlast args) (last args))))
-(defn maybe-real
+(defn maybe-real-file
"Resolve a file resource if real, or just make a File somehow."
[path]
(if-let [res (io/resource path)]
@@ -27,7 +27,7 @@
(deftest file-types
(are [f res opts exp]
- (= (boolean (mapply file-type-match-any? (maybe-real f) res opts))
+ (= (boolean (mapply file-type-match-any? (maybe-real-file f) res opts))
exp)
;; basic explicit behavior
"." [#"directory"] {:ok-empty? false, :ok-missing? false} true
Please sign in to comment.
Something went wrong with that request. Please try again.