From 3eefb4396723e63e06145bb8e9c38d2f334f38bf Mon Sep 17 00:00:00 2001 From: Jeff Scheel Date: Mon, 8 May 2017 15:11:30 -0500 Subject: [PATCH] Add support for retrieving Git Log history as revision history in RST. Signed-off-by: Jeff Scheel --- rst_template/bk_main.xml | 11 ++--------- rst_template/opf_docbook.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/rst_template/bk_main.xml b/rst_template/bk_main.xml index 7419b39..3ed5502 100644 --- a/rst_template/bk_main.xml +++ b/rst_template/bk_main.xml @@ -66,15 +66,8 @@ TBD - - - - 2017-02-17 - - TBD - - - + + TBD diff --git a/rst_template/opf_docbook.py b/rst_template/opf_docbook.py index f89a70d..7496cd4 100644 --- a/rst_template/opf_docbook.py +++ b/rst_template/opf_docbook.py @@ -136,7 +136,33 @@ def insert_toc_into_book(toc_file, book_file): if not inserted_toc: print 'Error: key string of "', key_string, '" not found in ', book_file sys.exit(-7) - + +def build_revhistory() + from subprocess import Popen, PIPE + + # Variables for formating git log + log_format = '%h%x01%an%x01%ad%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x01%s%x02' + log_fields = ['id', 'author', 'date', 'subject'] + + # Retrieve log + pipe = Popen('git log --date=iso --format="%s"' % log_format, shell=True, stdout=PIPE) + log, _ = pipe.communicate() + log = log.replace('&','&').replace('<','<').replace('>','>').replace('\n','').strip('\x02').split('\x02') + log = [row.split('\01') for row in log] + log = [dict(zip(log_fields, row)) for row in log] + + # Format log into revision history + revision = '\n' + for entry in log: + revision = revision + '' + entry['date'] + '' +\ + entry['subject'] + ' (' + entry['id'] + ')\n' + revision = revision + '\n' + + # Update file + rev_str = 'TBD' + update_file('bk_main.xml', rev_str, revision) + + def main(argv): build_dir = '' db_dir = '' @@ -201,6 +227,9 @@ def main(argv): # Update link to first file insert_toc_into_book(full_toc_file_tmp2, book_file) + + # Create revision history from Git Log + build_revhistory() sys.exit(0)