diff src/clojureDemo/sys_utils.clj @ 1:6d9bdaf919f7

added clojureDemo source
author Robert McIntyre <rlm@mit.edu>
date Fri, 20 Aug 2010 00:32:44 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojureDemo/sys_utils.clj	Fri Aug 20 00:32:44 2010 -0400
     1.3 @@ -0,0 +1,69 @@
     1.4 +
     1.5 +(ns clojureDemo.sys-utils
     1.6 +
     1.7 +(:use [clojure.contrib duck-streams str-utils shell-out])
     1.8 +(:import java.io.File)
     1.9 +)
    1.10 +
    1.11 +
    1.12 +
    1.13 +(defn rename [file]
    1.14 +
    1.15 +  (if (re-matches #".*\.JPG$" (str file))
    1.16 +    (sh "mv" (str file)  (re-sub #"\.JPG" ".jpg" (str file)))
    1.17 +    nil))
    1.18 +
    1.19 +
    1.20 +
    1.21 +
    1.22 +(defn escape-spaces
    1.23 +  [string]
    1.24 +  (re-gsub #" " (str \-) string))
    1.25 +
    1.26 +
    1.27 +(defn view 
    1.28 +  [string]
    1.29 +  (seq (char-array string)))
    1.30 +
    1.31 +(defn parent-source [target file]
    1.32 +  (File. (str target "/" (.getName (.getParentFile file))"-" (.getName file))))
    1.33 +
    1.34 +
    1.35 +(defn rsync [file1 file2]
    1.36 +  (let [*out* nil]
    1.37 +  (sh "rsync" "-avz" (str file1) (escape-spaces(str file2)))))
    1.38 +
    1.39 +(defn shunt-file [target file]
    1.40 +  (rsync (str file) (str (parent-source target file)))) 
    1.41 +	
    1.42 +	  
    1.43 +
    1.44 +(defn extract-files
    1.45 +  [regex source destination]
    1.46 +
    1.47 +  (dorun (map (partial shunt-file destination) 
    1.48 +  (filter (comp not nil? (partial re-matches regex) str)  (file-seq source)))))
    1.49 +
    1.50 +
    1.51 +(defn file-count [#^java.io.File file]
    1.52 +  (count (file-seq file)))
    1.53 +  
    1.54 +
    1.55 +
    1.56 +
    1.57 +(comment
    1.58 +
    1.59 +(defn test-extract
    1.60 +  []
    1.61 +  ((partial extract-files #".*\.JPG"
    1.62 +	    (file-str " /home/r/Desktop/judy_yates_computer_archive/MyDocuments/dallas townhome") 
    1.63 +	    (file-str "/home/r/Desktop/judyates_admin/archive-source-images/"))))
    1.64 +
    1.65 +
    1.66 +(defn judy-jpg-extract
    1.67 +  []
    1.68 +  ((partial extract-files #".*\.JPG"
    1.69 +	    (file-str "/home/r/Desktop/judy_yates_computer_archive") 
    1.70 +	    (file-str "/home/r/Desktop/judyates_admin/archive-source-images/"))))
    1.71 +
    1.72 +)