osmith has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-gsm-manuals/+/32689 )

Change subject: VTY references: set git version and date
......................................................................

VTY references: set git version and date

Fix that VTY references currently don't have the version from which they
were generated. Set the same REVNUMBER and GIT_DATE variables in
Makefile.docbook.inc (gets included in Makefile.vty-rference.inc)
as in Makefile.asciidoc.inc. Use them with a new script to rewrite the
<revhistory> block of vty references.

Closes: OS#4063
Change-Id: I68a8c3893d3c3a3b1bc1aee442a17635b60ac531
---
M build/Makefile.docbook.inc
A build/docbook-set-revhistory.py
2 files changed, 109 insertions(+), 2 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, but someone else must approve
  osmith: Looks good to me, approved




diff --git a/build/Makefile.docbook.inc b/build/Makefile.docbook.inc
index eb0ee25..eff6c66 100644
--- a/build/Makefile.docbook.inc
+++ b/build/Makefile.docbook.inc
@@ -34,9 +34,22 @@
 %.xml-lint: %.xml
        xmllint --xinclude --postvalid --noout $<

+GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags)
+GIT_DATE := $(shell $(OSMO_GSM_MANUALS_DIR)/build/unix-time-to-fmt.py `git log 
-n 1 "--pretty=%at" ../.`)
+ifeq (,$(BUILD_RELEASE))
+       REVNUMBER := DRAFT $(GIT_VERSION)
+else
+       REVNUMBER := $(GIT_VERSION)
+endif
+
 # Create a PDF file and lint it before
 # xslt path: find includes in both $(OSMO_GSM_MANUALS_DIR)/common/chapters and 
$(builddir)/generated
 %.pdf: %.xml %.xml-lint $(DOCBOOKS_DEPS) build common
+       set -x && \
+       export GIT_DATE="$(GIT_DATE)" && \
+       export REVNUMBER="$(REVNUMBER)" && \
+       export TEMPFILE="$(INC_DIR)/_temp_$(notdir $<)" && \
+       $(OSMO_GSM_MANUALS_DIR)/build/docbook-set-revhistory.py "$<" && \
        dblatex --xslt-opts="--path $(realpath 
$(OSMO_GSM_MANUALS_DIR))/common/chapters:$(INC_DIR)" \
-               $(dblatex_quiet) -P draft.mode=no -o $@ $<
-
+               $(dblatex_quiet) -P draft.mode=no -o $@ "$$TEMPFILE" && \
+       rm $$TEMPFILE
diff --git a/build/docbook-set-revhistory.py b/build/docbook-set-revhistory.py
new file mode 100755
index 0000000..8494ff0
--- /dev/null
+++ b/build/docbook-set-revhistory.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python3
+# Rewrite the revhistory part of the document for vty reference (OS#4063)
+import os
+import shutil
+import sys
+
+xml_in = sys.argv[1]
+xml_out = os.environ["TEMPFILE"]
+git_date = os.environ["GIT_DATE"]
+revnumber = os.environ["REVNUMBER"]
+
+
+def get_author_initials(line):
+    return line.split("<authorinitials>")[1].split("</authorinitials>")[0]
+
+
+def write_revhistory_block(h_out, author_initials):
+    h_out.write("<revhistory>\n")
+    h_out.write("<revision>\n")
+    h_out.write(f"<revnumber>{revnumber}</revnumber>\n")
+    h_out.write(f"<date>{git_date}</date>\n")
+    h_out.write(f"<authorinitials>{author_initials}</authorinitials>\n")
+    h_out.write("<revremark>Automatically Generated VTY 
Reference</revremark>\n")
+    h_out.write("</revision>\n")
+    h_out.write("</revhistory>\n")
+
+
+def set_revhistory():
+    """
+    Replace the part of the docbook that looks like the following, and copy
+    all other lines. Just using python's xml library would be better, but it
+    fails on docbook's custom DTDs.
+    <revhistory>
+        <revision>
+            <revnumber>v1</revnumber>
+            <date>18th September 2017</date>
+            <authorinitials>nh</authorinitials>
+            <revremark>Initial</revremark>
+        </revision>
+    </revhistory>
+    """
+    before = 0
+    inside = 1
+    after = 2
+
+    pos = before
+    author_initials = ""
+
+    with open(xml_out, "w") as h_out:
+        with open(xml_in, "r") as h_in:
+            for line in h_in.readlines():
+                if pos == before:
+                    if "<revhistory>" in line:
+                        h_out.write(line.split("<revhistory>")[0] + "\n")
+                        pos = inside
+
+                if pos in [before, after]:
+                    h_out.write(line)
+
+                if pos == inside:
+                    if "<authorinitials>" in line:
+                        author_initials = get_author_initials(line)
+                    if "</revhistory>" in line:
+                        write_revhistory_block(h_out, author_initials)
+                        h_out.write(line.split("</revhistory>")[1])
+                        pos = after
+
+
+def main():
+    if xml_in.endswith("-vty-reference.xml"):
+        print(f"Changing revhistory to {revnumber}, {git_date}...")
+        set_revhistory()
+    else:
+        print("Copying without change of revhistory...")
+        shutil.copyfile(xml_in, xml_out)
+
+
+main()

--
To view, visit https://gerrit.osmocom.org/c/osmo-gsm-manuals/+/32689
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-manuals
Gerrit-Branch: master
Gerrit-Change-Id: I68a8c3893d3c3a3b1bc1aee442a17635b60ac531
Gerrit-Change-Number: 32689
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <[email protected]>
Gerrit-Reviewer: daniel <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to