[jenkinscat-docs] master: File-related utils should be stored in separate file (and namespace). (a465181)

immanetize at fedoraproject.org immanetize at fedoraproject.org
Fri Feb 6 07:40:01 UTC 2015


Repository : http://git.fedorahosted.org/cgit/jenkinscat-docs.git

On branch  : master

>---------------------------------------------------------------

commit a465181960cf69659f5ff46c88ed909b0e4f6e50
Author: Pavel Tisnovsky <ptisnovs at redhat.com>
Date:   Wed Dec 3 11:16:35 2014 +0100

    File-related utils should be stored in separate file (and namespace).


>---------------------------------------------------------------

 ChangeLog                    |    5 +++
 src/jenkinscat/fileutils.clj |   82 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9a644ff..6801b54 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-12-03  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/jenkinscat/fileutils.clj:
+	File-related utils should be stored in separate file (and namespace).
+
 2014-12-02  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/jenkinscat/exec.clj:
diff --git a/src/jenkinscat/fileutils.clj b/src/jenkinscat/fileutils.clj
new file mode 100644
index 0000000..b556a5a
--- /dev/null
+++ b/src/jenkinscat/fileutils.clj
@@ -0,0 +1,82 @@
+;;; Copyright (c) 2014  Pavel Tisnovsky, Red Hat
+;;; All rights reserved.
+;;;
+;;; Redistribution and use in source and binary forms, with or without
+;;; modification, are permitted provided that the following conditions are met:
+;;;     * Redistributions of source code must retain the above copyright
+;;;       notice, this list of conditions and the following disclaimer.
+;;;     * Redistributions in binary form must reproduce the above copyright
+;;;       notice, this list of conditions and the following disclaimer in the
+;;;       documentation and/or other materials provided with the distribution.
+;;;     * Neither the name of the Red Hat nor the
+;;;       names of its contributors may be used to endorse or promote products
+;;;       derived from this software without specific prior written permission.
+;;;
+;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;; DISCLAIMED. IN NO EVENT SHALL Pavel Tisnovsky BE LIABLE FOR ANY
+;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+;;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+;;; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+
+(ns jenkinscat.fileutils)
+
+(require '[jenkinscat.exec :as exec])
+
+(defn print-slurp-exception
+    "Print warning message to the standard output."
+    ([filename]
+        (println "Warning: cannot read content of the following file: " filename))
+    ([directory filename]
+        (println "Warning: cannot read content of the following file: " directory "/" filename)))
+
+(defn slurp-
+    "Alternative (slurp) implementation that does not throw an exception, but returns nil instead."
+    ([filename]
+        (try
+            (slurp filename)
+            (catch Exception e (print-slurp-exception filename))))
+    ([directory filename]
+        (try
+            (slurp (str directory "/" filename))
+            (catch Exception e (print-slurp-exception directory filename)))))
+
+(defn new-file
+    "Just a shortcut for (new java.io.File filename)."
+    ( [filename]
+    (new java.io.File filename))
+    ( [path filename]
+    (new java.io.File path filename)))
+
+(defn make-temporary-directory
+    "Make temporary directory that would reside in /tmp (at least on Linux)."
+    []
+    (let [basedir-name (System/getProperty "java.io.tmpdir")
+          base-name    (str "jenkinscat-" (System/currentTimeMillis))
+          temp-dir     (new java.io.File basedir-name base-name)]
+        (.mkdir temp-dir)
+        temp-dir))
+
+(defn remove-temporary-directory
+    "Remove (delete) temporary directory that resides in /tmp (at least on Linux)."
+    [directory-name]
+    (let [file (new java.io.File directory-name)
+          abs-path (.getAbsolutePath file)]
+        ; make sure we are not going to remove wrong directory!
+        (if (.startsWith abs-path "/tmp")
+            (exec/exec "/bin/rm -rf" abs-path))))
+
+(defn make-temporary-directory-name
+    "Make temporary directory name that would reside in /tmp (at least on Linux)."
+    []
+    (let [basedir-name (System/getProperty "java.io.tmpdir")
+          base-name    (str "jenkinscat-" (System/currentTimeMillis))
+          temp-dir     (new java.io.File basedir-name base-name)]
+          (.getAbsolutePath temp-dir)))
+



More information about the docs-commits mailing list