[jenkinscat-docs] master: Added functions to read book metainformations. (979f0a5)

immanetize at fedoraproject.org immanetize at fedoraproject.org
Fri Feb 6 07:41:17 UTC 2015


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

On branch  : master

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

commit 979f0a571e79838aeebca0f164c45451fb1c802b
Author: Pavel Tisnovsky <ptisnovs at redhat.com>
Date:   Fri Jan 23 10:25:44 2015 +0100

    Added functions to read book metainformations.


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

 ChangeLog                 |    5 ++
 src/jenkinscat/server.clj |  100 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e7973ca..291b11b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-23  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/jenkinscat/server.clj:
+	Added functions to read book metainformations.
+
 2015-01-22  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* tools/create_books_clj_file.lua:
diff --git a/src/jenkinscat/server.clj b/src/jenkinscat/server.clj
index 496246e..1c6bf5a 100644
--- a/src/jenkinscat/server.clj
+++ b/src/jenkinscat/server.clj
@@ -814,6 +814,106 @@
             (= document-type "Article") "Article"
             :else "Book")))
 
+(defn exec-read-product-name-script
+    "Call the script that read product name from the given book and stores this string in temporary file."
+    [temp-dir-name document-type]
+    (exec/exec "./tools/new_book_scripts/read_product_name.sh" temp-dir-name document-type))
+
+(defn exec-read-product-number-script
+    "Call the script that read product number from the given book and stores this string in temporary file."
+    [temp-dir-name document-type]
+    (exec/exec "./tools/new_book_scripts/read_product_number.sh" temp-dir-name document-type))
+
+(defn exec-read-document-title-script
+    "Call the script that read document title from the given book and stores this string in temporary file."
+    [temp-dir-name document-type]
+    (exec/exec "./tools/new_book_scripts/read_document_title.sh" temp-dir-name document-type))
+
+(defn read-product-name
+    "Read product name (applicable for all DocBook guides)."
+    [temp-dir-name document-type]
+    (if document-type
+        (do
+            (exec-read-product-name-script temp-dir-name document-type)
+            (try
+                (fileutils/slurp- (str temp-dir-name "/product_name"))
+                (catch Exception e (println "Warning: cannot read product_name file"))))
+        nil))
+
+(defn read-product-number
+    "Read product number (applicable for all DocBook guides)."
+    [temp-dir-name document-type]
+    (if document-type
+        (do
+            (exec-read-product-number-script temp-dir-name document-type)
+            (try
+                (fileutils/slurp- (str temp-dir-name "/product_number"))
+                (catch Exception e (println "Warning: cannot read product_number file"))))
+        nil))
+
+(defn read-document-title
+    "Read document title (applicable for all DocBook guides)."
+    [temp-dir-name document-type]
+    (if document-type
+        (do
+            (exec-read-document-title-script temp-dir-name document-type)
+            (try
+                (fileutils/slurp- (str temp-dir-name "/document_title"))
+                (catch Exception e (println "Warning: cannot read document_title file"))))
+        nil))
+
+(defn read-docbook-info
+    "Read all relevant DocBook-related information from the DocBook book stored in given temporary directory."
+    [temp-dir-name]
+    (let [publican-cfg   (read-publican-cfg temp-dir-name)
+          document-type  (get-document-type publican-cfg)
+          document-title (empty-string-to-nil (read-document-title temp-dir-name document-type))
+          product-name   (empty-string-to-nil (read-product-name temp-dir-name document-type))
+          product-number (empty-string-to-nil (read-product-number temp-dir-name document-type))]
+       {:document-title document-title
+        :product-name   product-name
+        :product-number product-number}))
+
+(defn read-book-info
+    "Try to read ChesshireCat-related and DocBook-related information from the book stored in given temporary directory."
+    [temp-dir-name]
+    (println "Repository cloned sucesfully!")
+    (let [cheshirecat  (read-cheshirecat-edn temp-dir-name)
+          docbook-info (read-docbook-info    temp-dir-name)]
+       (fileutils/remove-temporary-directory temp-dir-name)
+       (merge docbook-info {:component-name    (:component (:article cheshirecat))
+                            :component-product (:product (:article cheshirecat))})))
+
+(defn clone-repo-and-read-book-info
+    [repo-type url]
+    (println "Repository exists, let's clone it.")
+    (let [temp-dir-name (fileutils/make-temporary-directory-name)
+          dvcs (get-dvcs repo-type)]
+        (println "Temporary directory: " temp-dir-name)
+        (if (clone-repo repo-type dvcs url temp-dir-name)
+            (read-book-info temp-dir-name)
+            (println "Clone error!"))))
+
+(defn empty-book-info?
+    [book-info]
+    (not (and (:component-name book-info)
+              (:component-product book-info)
+              (:document-title book-info)
+              (:product-name book-info)
+              (:product-number book-info))))
+
+(defn read-trimmed-parameter-default-string
+    [params param-name]
+    (.trim (get params param-name "")))
+
+(defn read-trimmed-parameter-default-nil
+    [params param-name]
+    (if params
+        (if (get params param-name)
+            (empty-string-to-nil (.trim (get params param-name)))
+            nil)
+        nil))
+
 (defn count-books
     [books]
     (let [out-data (new java.util.TreeSet)]



More information about the docs-commits mailing list