Skip to content

Commit

Permalink
Fix downloads for linux, add vagrantfile, fix where associations file…
Browse files Browse the repository at this point in the history
… is stored
  • Loading branch information
verma committed Feb 22, 2014
1 parent 5d1e9c3 commit f66daa3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 52 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -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
15 changes: 10 additions & 5 deletions src/dakait/assocs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand All @@ -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"
Expand Down
31 changes: 22 additions & 9 deletions src/dakait/downloader.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,35 @@
(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
"Download the given file or directory to the given directory"
[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"))]
Expand Down

0 comments on commit f66daa3

Please sign in to comment.