diff --git a/.gitignore b/.gitignore index 68ad214..bf8a07a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ pom.xml.asc /resources/public/js/tags.js /resources/public/js/main.js .DS_Store +.vagrant /config.json /tags.json /assocs.json diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..4338dcc --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,52 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + config.vm.box = "precise64" + + config.vm.hostname = "dakait-dev" + config.vm.box_url = "http://files.vagrantup.com/precise64.box" + + config.vm.network :forwarded_port, guest: 3000, host: 3000 + + config.vm.provider :virtualbox do |vb| + vb.customize ["modifyvm", :id, "--memory", "2048"] + vb.customize ["modifyvm", :id, "--cpus", "2"] + vb.customize ["modifyvm", :id, "--ioapic", "on"] + end + + # + ppaRepos = [ + ] + + # The postgres/gis family of products is not in the list intentionally since they + # are explicitly installed in one of the scripts + packageList = [ + "git", + "build-essential", + "openjdk-7-jdk" + ]; + + if Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/default/*/id").empty? + pkg_cmd = "" + + pkg_cmd << "apt-get update -qq; apt-get install -q -y python-software-properties; " + + if ppaRepos.length > 0 + ppaRepos.each { |repo| pkg_cmd << "add-apt-repository -y " << repo << " ; " } + pkg_cmd << "apt-get update -qq; " + end + + # install packages we need + pkg_cmd << "apt-get install -q -y " + packageList.join(" ") << " ; " + + # get the latest version of leiningen and setup it up + pkg_cmd << "wget -O /usr/bin/lein https://raw.github.com/technomancy/leiningen/stable/bin/lein ; " + pkg_cmd << "chmod +x /usr/bin/lein ; " + + config.vm.provision :shell, :inline => pkg_cmd + end +end diff --git a/src/dakait/assocs.clj b/src/dakait/assocs.clj index aaa00b2..136fd29 100644 --- a/src/dakait/assocs.clj +++ b/src/dakait/assocs.clj @@ -26,15 +26,20 @@ ;; (def assocs (atom {})) +(def assocs-file (atom "")) -(def assocs-file (join-path (config :config-data-dir) "assocs.json")) +(defn- figure-assocs-file + "Determine where the assocs file should be" + [] + (reset! assocs-file (join-path (config :config-data-dir) "assocs.json"))) (defn load-associations "Load associations from our configuration file" [] - (info "Associations file: " assocs-file) - (when (.exists (io/file assocs-file)) - (->> assocs-file + (figure-assocs-file) + (info "Associations file: " @assocs-file) + (when (.exists (io/file @assocs-file)) + (->> @assocs-file slurp json/read-str (reset! assocs)))) @@ -44,7 +49,7 @@ [assocs] (->> assocs json/write-str - (spit assocs-file))) + (spit @assocs-file))) (defn- assoc-key "Given a file in the remote file system, append the server info for a unique key" diff --git a/src/dakait/downloader.clj b/src/dakait/downloader.clj index 0d7ec9f..0f37f0e 100644 --- a/src/dakait/downloader.clj +++ b/src/dakait/downloader.clj @@ -17,6 +17,27 @@ (def download-queue (atom (clojure.lang.PersistentQueue/EMPTY))) (def download-states (atom {})) ;; directly modified by download threads +(defn- make-download-command + "Makes operating system specific script + scp command" + [src dest tmp-file] + (let [os (clojure.string/lower-case (System/getProperty "os.name")) + scp-command (list "scp" + "-i" (config :private-key) ;; identity file + "-B" ;; batch run + "-r" ;; recursive if directory + "-o" "StrictHostKeyChecking=no" + "-P" (config :sftp-port) ;; the port to use + (str (config :username) "@" (config :sftp-host) ":\"" src "\"") ;; source + dest)] + (cond + (= os "mac os x") (concat (list "script" "-t" "0" "-q" tmp-file) + scp-command) + (= os "linux") (list + "script" "-f" "-e" "-q" + "-c" (apply str (interpose " " scp-command)) + tmp-file)))) + + ;; Download management ;; (defn- download @@ -24,15 +45,7 @@ [src dest] (.mkdirs (io/file dest)) ;; Make sure the destination directory exists (let [tmp-file (.getAbsolutePath (java.io.File/createTempFile "downloader" "txt")) - args (list - "script" "-t" "0" "-q" tmp-file - "scp" - "-i" (config :private-key) ;; identity file - "-B" ;; batch run - "-r" ;; recursive if directory - "-P" (config :sftp-port) ;; the port to use - (str (config :username) "@" (config :sftp-host) ":\"" src "\"") ;; source - dest) + args (make-download-command src dest tmp-file) update-to-map (fn [s] (when-not (empty? s) (let [parts (remove empty? (clojure.string/split s #"\s"))]