[jenkinscat-docs] master: Updated to use exec and fileutils modules. (30b2c2d)

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


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

On branch  : master

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

commit 30b2c2d1c5d6758287eb23900a38644bb9b77e68
Author: Pavel Tisnovsky <ptisnovs at redhat.com>
Date:   Wed Dec 3 12:01:33 2014 +0100

    Updated to use exec and fileutils modules.


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

 ChangeLog                 |    5 ++
 src/jenkinscat/server.clj |  117 +++++++++++++++++++--------------------------
 2 files changed, 54 insertions(+), 68 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6801b54..f6f7c79 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2014-12-03  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
+	* src/jenkinscat/server.clj:
+	Updated to use exec and fileutils modules.
+
+2014-12-03  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
 	* src/jenkinscat/fileutils.clj:
 	File-related utils should be stored in separate file (and namespace).
 
diff --git a/src/jenkinscat/server.clj b/src/jenkinscat/server.clj
index 61b06f7..e780b77 100644
--- a/src/jenkinscat/server.clj
+++ b/src/jenkinscat/server.clj
@@ -33,19 +33,18 @@
 
 (require 'clojure.string)
 
-(require '[hiccup.core        :as hiccup])
-(require '[hiccup.page        :as page])
-(require '[hiccup.form        :as form])
-
-(require '[ring.util.response :as http-response])
-(require '[clojure.data.json  :as json])
-(require '[jenkinscat.books   :as books])
+(require '[hiccup.core          :as hiccup])
+(require '[hiccup.page          :as page])
+(require '[hiccup.form          :as form])
+
+(require '[ring.util.response   :as http-response])
+(require '[clojure.data.json    :as json])
+(require '[jenkinscat.books     :as books])
+(require '[jenkinscat.fileutils :as fileutils])
 (require '[jenkinscat.config    :as config])
+(require '[jenkinscat.exec      :as exec])
 
-(require '[clojure.xml        :as xml])
-
-(def test-results-prefix
-    "/var/www/html/tests/")
+(require '[clojure.xml          :as xml])
 
 (def not-available-message
     "<span style='color:red'>N/A</span>")
@@ -55,32 +54,14 @@
     [coll]
     (nth coll 2))
 
-(defn exec
-    "Execute external command."
-    ([command]
-     (.waitFor (. (Runtime/getRuntime) exec command)))
-    ([command param1]
-     (.waitFor (. (Runtime/getRuntime) exec (str command " " param1))))
-    ([command param1 param2]
-     (.waitFor (. (Runtime/getRuntime) exec (str command " " param1 " " param2))))
-    ([command param1 param2 param3]
-     (.waitFor (. (Runtime/getRuntime) exec (str command " " param1 " " param2 " " param3))))
-    ([command param1 param2 param3 param4]
-     (.waitFor (. (Runtime/getRuntime) exec (str command " " param1 " " param2 " " param3 " " param4))))
-    ([command param1 param2 param3 param4 param5]
-     (.waitFor (. (Runtime/getRuntime) exec (str command " " param1 " " param2 " " param3 " " param4 " " param5)))))
-
 (defn start-build
     "Start a new build (add the request for a build to Jenkins queue)."
     [job-name]
-    (exec "./tools/start_builds.sh" job-name))
+    (exec/exec "./tools/start_builds.sh" job-name))
 
-(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 empty-string-to-nil
+    [string]
+    (if (clojure.string/blank? string) nil string))
 
 (defn gnome-job?
     [job-name]
@@ -107,20 +88,20 @@
 (defn href-to-pdf
     "Return a proper href to a PDF document generated by Jenkins job."
     [job-name file-name]
-    (str jobs-href-prefix job-name "%20(PDF)/lastStableBuild/artifact/tmp/en-US/pdf/" file-name))
-    ;(str "<a href='" jobs-href-prefix job-name "%20(PDF)/lastStableBuild/artifact/tmp/en-US/pdf/" file-name "'>link</a>"))
+    (str config/jobs-href-prefix job-name "%20(PDF)/lastStableBuild/artifact/tmp/en-US/pdf/" file-name))
+    ;(str "<a href='" config/jobs-href-prefix job-name "%20(PDF)/lastStableBuild/artifact/tmp/en-US/pdf/" file-name "'>link</a>"))
 
 (defn href-to-single-html
     "Return a proper href to a single-html page generated by Jenkins job."
     [job-name]
-    (cond (gnome-job? job-name)    (str jobs-href-prefix job-name "%20(html)/lastStableBuild/artifact/gnome-help/C/index.html")
-          (appinfra-job? job-name) (str jobs-href-prefix job-name "%20(html-single)/lastStableBuild/artifact/index.html")
-          :else                    (str jobs-href-prefix job-name "%20(html-single)/lastStableBuild/artifact/tmp/en-US/html-single/index.html")))
-    ;(str "<a href='" jobs-href-prefix job-name "%20(html-single)/lastStableBuild/artifact/tmp/en-US/html-single/index.html'>link</a>"))
+    (cond (gnome-job? job-name)    (str config/jobs-href-prefix job-name "%20(html)/lastStableBuild/artifact/gnome-help/C/index.html")
+          (appinfra-job? job-name) (str config/jobs-href-prefix job-name "%20(html-single)/lastStableBuild/artifact/index.html")
+          :else                    (str config/jobs-href-prefix job-name "%20(html-single)/lastStableBuild/artifact/tmp/en-US/html-single/index.html")))
+    ;(str "<a href='" config/jobs-href-prefix job-name "%20(html-single)/lastStableBuild/artifact/tmp/en-US/html-single/index.html'>link</a>"))
 
 (defn href-to-file-middleware
     [job-name-prefix job-name-postfix extension]
-    (str jobs-href-prefix job-name-prefix "/lastStableBuild/artifact/output/" job-name-postfix "/" job-name-postfix "." extension))
+    (str config/jobs-href-prefix job-name-prefix "/lastStableBuild/artifact/output/" job-name-postfix "/" job-name-postfix "." extension))
 
 (defn href-to-pdf-middleware
     [job-name-prefix job-name-postfix]
@@ -133,25 +114,25 @@
 (defn pdf-exists?
     "Test for existence of PDF file(s) generated by Jenkins."
     [job-name]
-    (let [directory (new-file (str jobs-dir-prefix job-name " (PDF)/lastStable/archive/tmp/en-US/pdf/"))
+    (let [directory (fileutils/new-file (str config/jobs-dir-prefix job-name " (PDF)/lastStable/archive/tmp/en-US/pdf/"))
           filelist  (.listFiles directory)]
         (>= 1 (count filelist))))
 
 (defn file-exists?
     "Check of existence of given file."
     [file-name]
-    (let [file (new-file file-name)]
+    (let [file (fileutils/new-file file-name)]
         (and (.exists file) (not (.isDirectory file)))))
 
 (defn test-summary-exists?
     "Test for existence of summary file generated by Emender."
     [job-name]
-    (file-exists? (str test-results-prefix job-name ".summary")))
+    (file-exists? (str config/test-results-prefix job-name ".summary")))
 
 (defn test-results-exists?
     "Test for existence of result file generated by Emender."
     [job-name]
-    (file-exists? (str test-results-prefix job-name ".html")))
+    (file-exists? (str config/test-results-prefix job-name ".html")))
 
 (defn compute-percents
     "Compute percentage of passed/failed tests."
@@ -168,7 +149,7 @@
 (defn read-test-results
     "Read test results generated by Emender."
     [job-name]
-    (let [summary-file-name        (str test-results-prefix job-name ".summary")
+    (let [summary-file-name        (str config/test-results-prefix job-name ".summary")
           summary-as-string        (slurp summary-file-name)
           test-summary             (clojure.string/split-lines summary-as-string)
           total-tests              (read-string (first test-summary))
@@ -182,7 +163,7 @@
     [(str "Passed: " formatted-passed-percent "  Failed: " formatted-failed-percent)
      passed-percent
      failed-percent
-     (str test-results-url-prefix job-name ".html")]))
+     (str config/test-results-url-prefix job-name ".html")]))
 
 (defn try-to-read-test-results
     "Read test results generated by Emender, but only if results exist."
@@ -196,7 +177,7 @@
     
 (defn get-path-to-pdf-publican-book
     [job-name]
-    (let [directory (new-file (str jobs-dir-prefix job-name " (PDF)/lastStable/archive/tmp/en-US/pdf/"))
+    (let [directory (fileutils/new-file (str config/jobs-dir-prefix job-name " (PDF)/lastStable/archive/tmp/en-US/pdf/"))
           filelist  (.listFiles directory)]
         (if (<= 1 (count filelist))
             (href-to-pdf job-name (.getName (first filelist)))
@@ -206,7 +187,7 @@
     [job-name extension]
     (let [job-name-prefix  (get-job-name-prefix job-name)
           job-name-postfix (get-job-name-postfix job-name)
-          path-to-file     (str jobs-dir-prefix job-name-prefix "/lastStable/archive/output/" job-name-postfix "/" job-name-postfix "." extension)]
+          path-to-file     (str config/jobs-dir-prefix job-name-prefix "/lastStable/archive/output/" job-name-postfix "/" job-name-postfix "." extension)]
         path-to-file))
 
 (defn get-path-to-middleware-job-html
@@ -220,7 +201,7 @@
 (defn pdf-exists-middleware-job?
     [job-name]
     (let [path-to-html (get-path-to-middleware-job-pdf job-name)
-          file (new-file path-to-html)]
+          file (fileutils/new-file path-to-html)]
         (.isFile file)))
 
 (defn get-path-to-pdf-middleware-book
@@ -240,23 +221,23 @@
 
 (defn html-exists-gnome-job?
     [job-name]
-    (let [file (new-file (str jobs-dir-prefix job-name " (html)/lastStable/archive/gnome-help/C/index.html"))]
+    (let [file (fileutils/new-file (str config/jobs-dir-prefix job-name " (html)/lastStable/archive/gnome-help/C/index.html"))]
         (.isFile file)))
 
 (defn html-exists-publican-job?
     [job-name]
-    (let [file (new-file (str jobs-dir-prefix job-name " (html-single)/lastStable/archive/tmp/en-US/html-single/index.html"))]
+    (let [file (fileutils/new-file (str config/jobs-dir-prefix job-name " (html-single)/lastStable/archive/tmp/en-US/html-single/index.html"))]
         (.isFile file)))
 
 (defn html-exists-middleware-job?
     [job-name]
     (let [path-to-html (get-path-to-middleware-job-html job-name)
-          file (new-file path-to-html)]
+          file (fileutils/new-file path-to-html)]
         (.isFile file)))
 
 (defn html-exists-appinfra-job?
     [job-name]
-    (let [file (new-file (str jobs-dir-prefix job-name " (html-single)/lastStable/archive/index.html"))]
+    (let [file (fileutils/new-file (str config/jobs-dir-prefix job-name " (html-single)/lastStable/archive/index.html"))]
         (.isFile file)))
 
 (defn html-exists?
@@ -269,14 +250,14 @@
 
 (defn get-path-to-html-publican-book
     [job-name]
-    (let [file (new-file (str jobs-dir-prefix job-name " (html-single)/lastStable/archive/tmp/en-US/html-single/index.html"))]
+    (let [file (fileutils/new-file (str config/jobs-dir-prefix job-name " (html-single)/lastStable/archive/tmp/en-US/html-single/index.html"))]
         (if (.isFile file)
             (href-to-single-html job-name)
             nil)))
 
 (defn get-path-to-html-appinfra-book
     [job-name]
-    (let [file (new-file (str jobs-dir-prefix job-name " (html-single)/lastStable/archive/index.html"))]
+    (let [file (fileutils/new-file (str config/jobs-dir-prefix job-name " (html-single)/lastStable/archive/index.html"))]
         (if (.isFile file)
             (href-to-single-html job-name)
             nil)))
@@ -284,7 +265,7 @@
 (defn get-path-to-html-gnome-book
     [job-name]
     ;example http://localhost:8080/job/doc-FuseSource-ActiveMQDocs/lastStableBuild/artifact/output/admin_guide/admin_guide.html
-    (let [file (new-file (str jobs-dir-prefix job-name " (html)/lastStable/archive/gnome-help/C/index.html"))]
+    (let [file (fileutils/new-file (str config/jobs-dir-prefix job-name " (html)/lastStable/archive/gnome-help/C/index.html"))]
         (if (.isFile file)
             (href-to-single-html job-name)
             nil)))
@@ -307,19 +288,19 @@
 
 (defn get-path-to-log-publican-book
     [job-name]
-    (let [directory (new-file (str jobs-dir-prefix job-name " (html-single)/lastStable/archive/tmp/en-US/html-single"))
+    (let [directory (fileutils/new-file (str config/jobs-dir-prefix job-name " (html-single)/lastStable/archive/tmp/en-US/html-single"))
           filelist (.listFiles directory)]
         (if (<= 1 (count filelist))
-                (str jobs-href-prefix job-name "%20(html-single)/lastSuccessfulBuild/consoleText")
-                (str jobs-href-prefix job-name "%20(html-single)/lastFailedBuild/consoleText"))))
+                (str config/jobs-href-prefix job-name "%20(html-single)/lastSuccessfulBuild/consoleText")
+                (str config/jobs-href-prefix job-name "%20(html-single)/lastFailedBuild/consoleText"))))
 
 (defn get-path-to-log-gnome-book
     [job-name]
-    (let [directory (new-file (str jobs-dir-prefix job-name " (html)/lastStable/archive/tmp/en-US/pdf/"))
+    (let [directory (fileutils/new-file (str config/jobs-dir-prefix job-name " (html)/lastStable/archive/tmp/en-US/pdf/"))
           filelist (.listFiles directory)]
         (if (<= 1 (count filelist))
-                (str jobs-href-prefix job-name "%20(html)/lastSuccessfulBuild/consoleText")
-                (str jobs-href-prefix job-name "%20(html)/lastFailedBuild/consoleText"))))
+                (str config/jobs-href-prefix job-name "%20(html)/lastSuccessfulBuild/consoleText")
+                (str config/jobs-href-prefix job-name "%20(html)/lastFailedBuild/consoleText"))))
 
 (defn get-path-to-log
     "Get path to status and/or console output for the given job."
@@ -576,7 +557,7 @@
 (defn read-job-info-as-json
     "Fetch the timestamp and duration of the last build from Jenkins server."
     [job-name]
-    (let [full-json-url (str json-url "job/" (.replace job-name " " "%20") "/lastBuild/api/json?pretty=true")
+    (let [full-json-url (str config/json-url "job/" (.replace job-name " " "%20") "/lastBuild/api/json?pretty=true")
           inputstr (slurp full-json-url)]
         (if inputstr
             (let [parsed   (json/read-str inputstr)]
@@ -688,7 +669,7 @@
 (defn overview-exists?
     [product-name component-name]
     (let [path-to-html (str "/var/www/html/overview/" product-name "/" component-name "/index.html")
-          file (new-file path-to-html)]
+          file (fileutils/new-file path-to-html)]
         (if (.isFile file) "ok" "")))
 
 (defn get-books-for-product
@@ -869,7 +850,7 @@
 (defn read-job-configuration
     [job-name]
     (let [updated-job-name (update-job-name-for-reading-configuration job-name)
-          config-as-xml (xml-seq (xml/parse (str json-url "job/" updated-job-name "/config.xml")))
+          config-as-xml (xml-seq (xml/parse (str config/json-url "job/" updated-job-name "/config.xml")))
           config (get-job-config-from-xml updated-job-name config-as-xml)]
     [job-name config]))
 
@@ -906,12 +887,12 @@
 
 (defn read-page-count-for-pdf-book
     [file-name]
-    (exec "./tools/read_page_count.sh" (.toString file-name))
+    (exec/exec "./tools/read_page_count.sh" (.toString file-name))
     (Integer/parseInt (.trim (slurp "./page_count.txt"))))
 
 (defn try-to-read-page-count-for-pdf-book
     [job-name]
-    (let [directory (new-file (str jobs-dir-prefix job-name "/lastStable/archive/tmp/en-US/pdf/"))
+    (let [directory (fileutils/new-file (str config/jobs-dir-prefix job-name "/lastStable/archive/tmp/en-US/pdf/"))
           filelist (.listFiles directory)]
           (if (= (count filelist) 1)
               (read-page-count-for-pdf-book (first filelist))
@@ -1093,7 +1074,7 @@
 (defn get-file-handler
     "Return selected file handler or nil in case the handler is unknown."
     [uri]
-    (get file-handlers uri nil))
+    (file-handlers/get-file-handler uri))
 
 (defn get-action-handler
     "Return selected action handler or nil in case the handler is unknown."



More information about the docs-commits mailing list