From owner-dev-commits-doc-all@freebsd.org Sun Jun 13 12:49:42 2021 Return-Path: Delivered-To: dev-commits-doc-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2A7CD65C95F for ; Sun, 13 Jun 2021 12:49:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4G2vYL0PLGz3Lfm; Sun, 13 Jun 2021 12:49:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EA509210FE; Sun, 13 Jun 2021 12:49:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 15DCnfbJ029040; Sun, 13 Jun 2021 12:49:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15DCnf0b029039; Sun, 13 Jun 2021 12:49:41 GMT (envelope-from git) Date: Sun, 13 Jun 2021 12:49:41 GMT Message-Id: <202106131249.15DCnf0b029039@gitrepo.freebsd.org> To: doc-committers@FreeBSD.org, dev-commits-doc-all@FreeBSD.org From: Ceri Davies Subject: git: c4db9c153e - main - tools/books*py: improve argument handling of DOC_LANG, and others MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ceri X-Git-Repository: doc X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c4db9c153e4664a3eec66a68de305a57845c4a5a Auto-Submitted: auto-generated X-BeenThere: dev-commits-doc-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the doc repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Jun 2021 12:49:42 -0000 The branch main has been updated by ceri: URL: https://cgit.FreeBSD.org/doc/commit/?id=c4db9c153e4664a3eec66a68de305a57845c4a5a commit c4db9c153e4664a3eec66a68de305a57845c4a5a Author: Ceri Davies AuthorDate: 2021-06-13 12:45:07 +0000 Commit: Ceri Davies CommitDate: 2021-06-13 12:45:07 +0000 tools/books*py: improve argument handling of DOC_LANG, and others 1) fix shebang lines; 2) add a -o option that makes no changes but prints the files that would be updated/created; 3) allow the -l argument (and therefore DOC_LANG) to be whitespace separated, comma separated, or a mixture of both Item 2 allows us to start tracking dependencies in Makefiles if we wish and therefore reintroduce incremental builds, reducing the amount of .PHONY targets that are not truly phony. Item 3 restores compability with the documented DOC_LANG variable, which was previously whitespace separated. Reviewed by: dbaio, blackend Differential Revision: https://reviews.freebsd.org/D30732 --- documentation/tools/books-toc-creator.py | 30 +++++++++++----- documentation/tools/books-toc-examples-creator.py | 31 +++++++++++----- documentation/tools/books-toc-figures-creator.py | 33 +++++++++++------ documentation/tools/books-toc-parts-creator.py | 43 ++++++++++++++++------- documentation/tools/books-toc-tables-creator.py | 30 +++++++++++----- 5 files changed, 117 insertions(+), 50 deletions(-) diff --git a/documentation/tools/books-toc-creator.py b/documentation/tools/books-toc-creator.py index 340deec339..bd85b7e923 100644 --- a/documentation/tools/books-toc-creator.py +++ b/documentation/tools/books-toc-creator.py @@ -1,11 +1,11 @@ +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ BSD 2-Clause License Copyright (c) 2020-2021, The FreeBSD Project Copyright (c) 2020-2021, Sergio Carlavilla -This script will generate the Table of Contents of the Handbook +This script will generate the Table of Contents of the books. """ -#!/usr/bin/env python3 import sys, getopt import re @@ -124,19 +124,28 @@ def checkIsAppendix(chapterContent): def main(argv): + justPrintOutput = False + langargs = [] try: - opts, args = getopt.getopt(argv,"hl:",["language="]) + opts, args = getopt.gnu_getopt(argv,"hl:o",["language="]) except getopt.GetoptError: - print('books-toc-creator.py -l ') + print('books-toc-creator.py [-o] -l ') sys.exit(2) for opt, arg in opts: if opt == '-h': - print('books-toc-creator.py -l ') + print('books-toc-creator.py [-o] -l ') sys.exit() + elif opt == '-o': + justPrintOutput = True elif opt in ("-l", "--language"): - languages = arg.split(',') + langargs = arg.replace(" ",",").split(',') + + # treat additional arguments as languages, but check if they + # contain ',' + for l in args: + langargs.extend(l.replace(" ",",").split(',')) - for language in languages: + for language in langargs: with open('./content/{}/books/books.adoc'.format(language), 'r', encoding = 'utf-8') as booksFile: books = [line.strip() for line in booksFile] @@ -199,8 +208,11 @@ def main(argv): toc += "--\n" - with open('./content/{0}/books/{1}/toc.adoc'.format(language, book), 'w', encoding = 'utf-8') as tocFile: - tocFile.write(toc) + if justPrintOutput == False: + with open('./content/{0}/books/{1}/toc.adoc'.format(language, book), 'w', encoding = 'utf-8') as tocFile: + tocFile.write(toc) + else: + print('./content/{0}/books/{1}/toc.adoc'.format(language, book)) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/documentation/tools/books-toc-examples-creator.py b/documentation/tools/books-toc-examples-creator.py index f72ffa945e..423239c30d 100644 --- a/documentation/tools/books-toc-examples-creator.py +++ b/documentation/tools/books-toc-examples-creator.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ BSD 2-Clause License @@ -5,9 +6,9 @@ BSD 2-Clause License Copyright (c) 2020-2021, The FreeBSD Project Copyright (c) 2020-2021, Sergio Carlavilla -This script will generate the Table of Contents of the Handbook +This script will generate the Table of Contents of any [example]s in the +books. """ -#!/usr/bin/env python3 import sys, getopt import re @@ -54,19 +55,28 @@ def setTOCTitle(language): def main(argv): + justPrintOutput = False + langargs = [] try: - opts, args = getopt.getopt(argv,"hl:",["language="]) + opts, args = getopt.gnu_getopt(argv,"hl:o",["language="]) except getopt.GetoptError: - print('books-toc-examples-creator.py -l ') + print('books-toc-examples-creator.py [-o] -l ') sys.exit(2) for opt, arg in opts: if opt == '-h': - print('books-toc-examples-creator.py -l ') + print('books-toc-examples-creator.py [-o] -l ') sys.exit() + if opt == '-o': + justPrintOutput = True elif opt in ("-l", "--language"): - languages = arg.split(',') + langargs = arg.replace(" ",",").split(',') + + # treat additional arguments as languages, but check if they + # contain ',' + for l in args: + langargs.extend(l.replace(" ",",").split(',')) - for language in languages: + for language in langargs: with open('./content/{}/books/books.adoc'.format(language), 'r', encoding = 'utf-8') as booksFile: books = [line.strip() for line in booksFile] @@ -115,8 +125,11 @@ def main(argv): toc += "--\n" - with open('./content/{0}/books/{1}/toc-examples.adoc'.format(language, book), 'w', encoding = 'utf-8') as tocFile: - tocFile.write(toc) + if justPrintOutput == False: + with open('./content/{0}/books/{1}/toc-examples.adoc'.format(language, book), 'w', encoding = 'utf-8') as tocFile: + tocFile.write(toc) + else: + print('./content/{0}/books/{1}/toc-examples.adoc'.format(language, book)) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/documentation/tools/books-toc-figures-creator.py b/documentation/tools/books-toc-figures-creator.py index 46bea6226b..fbe1d62c65 100644 --- a/documentation/tools/books-toc-figures-creator.py +++ b/documentation/tools/books-toc-figures-creator.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ BSD 2-Clause License @@ -5,9 +6,9 @@ BSD 2-Clause License Copyright (c) 2020-2021, The FreeBSD Project Copyright (c) 2020-2021, Sergio Carlavilla -This script will generate the Table of Contents of the Handbook +This script will generate the Table of Contents for any figures/images +in the books. """ -#!/usr/bin/env python3 import sys, getopt import re @@ -53,20 +54,29 @@ def setTOCTitle(language): return languages.get(language) def main(argv): - + + justPrintOutput = False + langargs = [] try: - opts, args = getopt.getopt(argv,"hl:",["language="]) + opts, args = getopt.gnu_getopt(argv,"hl:o",["language="]) except getopt.GetoptError: - print('books-toc-figures-creator.py -l ') + print('books-toc-figures-creator.py [-o] -l ') sys.exit(2) for opt, arg in opts: if opt == '-h': - print('books-toc-figures-creator.py -l ') + print('books-toc-figures-creator.py [-o] -l ') sys.exit() + if opt == '-o': + justPrintOutput = True elif opt in ("-l", "--language"): - languages = arg.split(',') + langargs = arg.replace(" ",",").split(',') + + # treat additional arguments as languages, but check if they + # contain ',' + for l in args: + langargs.extend(l.replace(" ",",").split(',')) - for language in languages: + for language in langargs: with open('./content/{}/books/books.adoc'.format(language), 'r', encoding = 'utf-8') as booksFile: books = [line.strip() for line in booksFile] @@ -114,8 +124,11 @@ def main(argv): toc += "--\n" - with open('./content/{0}/books/{1}/toc-figures.adoc'.format(language, book), 'w', encoding = 'utf-8') as tocFile: - tocFile.write(toc) + if justPrintOutput == False: + with open('./content/{0}/books/{1}/toc-figures.adoc'.format(language, book), 'w', encoding = 'utf-8') as tocFile: + tocFile.write(toc) + else: + print('./content/{0}/books/{1}/toc-figures.adoc'.format(language, book)) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/documentation/tools/books-toc-parts-creator.py b/documentation/tools/books-toc-parts-creator.py index b05aeb9dc5..aeb035b8cb 100644 --- a/documentation/tools/books-toc-parts-creator.py +++ b/documentation/tools/books-toc-parts-creator.py @@ -1,11 +1,12 @@ +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ BSD 2-Clause License Copyright (c) 2020-2021, The FreeBSD Project Copyright (c) 2020-2021, Sergio Carlavilla -This script will generate the Table of Contents of the Handbook +This script will generate the Table of Contents for any [preface], +[appendix] or other "parts" as defined by asciidoc. """ -#!/usr/bin/env python3 import sys, getopt import re @@ -14,12 +15,18 @@ import os.path languages = [] def cleanTocFile(language, tocCounter, book): - path = './content/{0}/books/{1}/toc-{2}.adoc'.format(language, book, tocCounter) + path = './content/{0}/books/{1}/toc-{2}.adoc'.format(language, book, tocCounter) + if justPrintOutput == True: + print(path) + else: if os.path.exists(path): - tocFile = open(path, 'r+', encoding = 'utf-8') - tocFile.truncate(0) + tocFile = open(path, 'r+', encoding = 'utf-8') + tocFile.truncate(0) + +def prependCommentAndTitle(language, tocCounter, tocContent, book): + if justPrintOutput == True: + return True -def appendCommendAndTitle(language, tocCounter, tocContent, book): toc = "// Code generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" toc += "// Please don't change this file manually but run `make` to update it.\n" toc += "// For more information, please read the FreeBSD Documentation Project Primer\n\n" @@ -112,20 +119,30 @@ def setTOCTitle(language): return languages.get(language) def main(argv): + global justPrintOutput + justPrintOutput = False + langargs=[] try: - opts, args = getopt.getopt(argv,"hl:",["language="]) + opts, args = getopt.gnu_getopt(argv,"hl:o",["language="]) except getopt.GetoptError: - print('books-toc-creator.py -l ') + print('books-toc-creator.py [-o] -l ') sys.exit(2) for opt, arg in opts: if opt == '-h': - print('books-toc-creator.py -l ') + print('books-toc-creator.py [-o] -l ') sys.exit() + elif opt == '-o': + justPrintOutput = True elif opt in ("-l", "--language"): - languages = arg.split(',') + langargs = arg.replace(" ",",").split(',') + + # treat additional arguments as languages, but check if they + # contain ',' + for l in args: + langargs.extend(l.replace(" ",",").split(',')) - for language in languages: + for language in langargs: with open('./content/{}/books/books.adoc'.format(language), 'r', encoding = 'utf-8') as booksFile: books = [line.strip() for line in booksFile] @@ -149,7 +166,7 @@ def main(argv): if partCounter > 0: cleanTocFile(language, partCounter, book) - appendCommendAndTitle(language, partCounter, toc, book) + prependCommentAndTitle(language, partCounter, toc, book) toc = "" # Clean toc content partCounter += 1 @@ -181,7 +198,7 @@ def main(argv): if partCounter > 0: cleanTocFile(language, partCounter, book) - appendCommendAndTitle(language, partCounter, toc, book) # For the last part + prependCommentAndTitle(language, partCounter, toc, book) # For the last part if __name__ == "__main__": main(sys.argv[1:]) diff --git a/documentation/tools/books-toc-tables-creator.py b/documentation/tools/books-toc-tables-creator.py index 592330b7a4..67f1733d45 100644 --- a/documentation/tools/books-toc-tables-creator.py +++ b/documentation/tools/books-toc-tables-creator.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ BSD 2-Clause License @@ -5,9 +6,8 @@ BSD 2-Clause License Copyright (c) 2020-2021, The FreeBSD Project Copyright (c) 2020-2021, Sergio Carlavilla -This script will generate the Table of Contents of the Handbook +This script will generate the Table of Contents for tables in the books. """ -#!/usr/bin/env python3 import sys, getopt import re @@ -54,19 +54,28 @@ def setTOCTitle(language): def main(argv): + justPrintOutput = False + langargs= [] try: - opts, args = getopt.getopt(argv,"hl:",["language="]) + opts, args = getopt.gnu_getopt(argv,"hl:o",["language="]) except getopt.GetoptError: - print('books-toc-tables-creator.py -l ') + print('books-toc-tables-creator.py [-o] -l ') sys.exit(2) for opt, arg in opts: if opt == '-h': - print('books-toc-tables-creator.py -l ') + print('books-toc-tables-creator.py [-o] -l ') sys.exit() + if opt == '-o': + justPrintOutput = True elif opt in ("-l", "--language"): - languages = arg.split(',') + langargs = arg.replace(" ",",").split(',') + + # treat additional arguments as languages, but check if they + # contain ',' + for l in args: + langargs.extend(l.replace(" ",",").split(',')) - for language in languages: + for language in langargs: with open('./content/{}/books/books.adoc'.format(language), 'r', encoding = 'utf-8') as booksFile: books = [line.strip() for line in booksFile] @@ -114,8 +123,11 @@ def main(argv): toc += "--\n" - with open('./content/{0}/books/{1}/toc-tables.adoc'.format(language, book), 'w', encoding = 'utf-8') as tocFile: - tocFile.write(toc) + if justPrintOutput == False: + with open('./content/{0}/books/{1}/toc-tables.adoc'.format(language, book), 'w', encoding = 'utf-8') as tocFile: + tocFile.write(toc) + else: + print('./content/{0}/books/{1}/toc-tables.adoc'.format(language, book)) if __name__ == "__main__": main(sys.argv[1:])