Mercurial > lasercutter
annotate src/clojureDemo/sys_utils.clj @ 9:35cf337adfcf
replaced jars
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:10:24 -0400 |
parents | 6d9bdaf919f7 |
children |
rev | line source |
---|---|
rlm@1 | 1 |
rlm@1 | 2 (ns clojureDemo.sys-utils |
rlm@1 | 3 |
rlm@1 | 4 (:use [clojure.contrib duck-streams str-utils shell-out]) |
rlm@1 | 5 (:import java.io.File) |
rlm@1 | 6 ) |
rlm@1 | 7 |
rlm@1 | 8 |
rlm@1 | 9 |
rlm@1 | 10 (defn rename [file] |
rlm@1 | 11 |
rlm@1 | 12 (if (re-matches #".*\.JPG$" (str file)) |
rlm@1 | 13 (sh "mv" (str file) (re-sub #"\.JPG" ".jpg" (str file))) |
rlm@1 | 14 nil)) |
rlm@1 | 15 |
rlm@1 | 16 |
rlm@1 | 17 |
rlm@1 | 18 |
rlm@1 | 19 (defn escape-spaces |
rlm@1 | 20 [string] |
rlm@1 | 21 (re-gsub #" " (str \-) string)) |
rlm@1 | 22 |
rlm@1 | 23 |
rlm@1 | 24 (defn view |
rlm@1 | 25 [string] |
rlm@1 | 26 (seq (char-array string))) |
rlm@1 | 27 |
rlm@1 | 28 (defn parent-source [target file] |
rlm@1 | 29 (File. (str target "/" (.getName (.getParentFile file))"-" (.getName file)))) |
rlm@1 | 30 |
rlm@1 | 31 |
rlm@1 | 32 (defn rsync [file1 file2] |
rlm@1 | 33 (let [*out* nil] |
rlm@1 | 34 (sh "rsync" "-avz" (str file1) (escape-spaces(str file2))))) |
rlm@1 | 35 |
rlm@1 | 36 (defn shunt-file [target file] |
rlm@1 | 37 (rsync (str file) (str (parent-source target file)))) |
rlm@1 | 38 |
rlm@1 | 39 |
rlm@1 | 40 |
rlm@1 | 41 (defn extract-files |
rlm@1 | 42 [regex source destination] |
rlm@1 | 43 |
rlm@1 | 44 (dorun (map (partial shunt-file destination) |
rlm@1 | 45 (filter (comp not nil? (partial re-matches regex) str) (file-seq source))))) |
rlm@1 | 46 |
rlm@1 | 47 |
rlm@1 | 48 (defn file-count [#^java.io.File file] |
rlm@1 | 49 (count (file-seq file))) |
rlm@1 | 50 |
rlm@1 | 51 |
rlm@1 | 52 |
rlm@1 | 53 |
rlm@1 | 54 (comment |
rlm@1 | 55 |
rlm@1 | 56 (defn test-extract |
rlm@1 | 57 [] |
rlm@1 | 58 ((partial extract-files #".*\.JPG" |
rlm@1 | 59 (file-str " /home/r/Desktop/judy_yates_computer_archive/MyDocuments/dallas townhome") |
rlm@1 | 60 (file-str "/home/r/Desktop/judyates_admin/archive-source-images/")))) |
rlm@1 | 61 |
rlm@1 | 62 |
rlm@1 | 63 (defn judy-jpg-extract |
rlm@1 | 64 [] |
rlm@1 | 65 ((partial extract-files #".*\.JPG" |
rlm@1 | 66 (file-str "/home/r/Desktop/judy_yates_computer_archive") |
rlm@1 | 67 (file-str "/home/r/Desktop/judyates_admin/archive-source-images/")))) |
rlm@1 | 68 |
rlm@1 | 69 ) |