Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153685144
D30732.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
12 KB
Referenced Files
None
Subscribers
None
D30732.diff
View Options
diff --git a/documentation/tools/books-toc-creator.py b/documentation/tools/books-toc-creator.py
--- 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 <carlavilla@FreeBSD.org>
-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 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 <language>')
+ print('books-toc-creator.py [-o] -l <language>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
- print('books-toc-creator.py -l <language>')
+ print('books-toc-creator.py [-o] -l <language>')
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 @@
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
--- 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 @@
Copyright (c) 2020-2021, The FreeBSD Project
Copyright (c) 2020-2021, Sergio Carlavilla <carlavilla@FreeBSD.org>
-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 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 <language>')
+ print('books-toc-examples-creator.py [-o] -l <language>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
- print('books-toc-examples-creator.py -l <language>')
+ print('books-toc-examples-creator.py [-o] -l <language>')
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 @@
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
--- 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 @@
Copyright (c) 2020-2021, The FreeBSD Project
Copyright (c) 2020-2021, Sergio Carlavilla <carlavilla@FreeBSD.org>
-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 @@
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 <language>')
+ print('books-toc-figures-creator.py [-o] -l <language>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
- print('books-toc-figures-creator.py -l <language>')
+ print('books-toc-figures-creator.py [-o] -l <language>')
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 @@
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
--- 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 <carlavilla@FreeBSD.org>
-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 @@
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 @@
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 <language>')
+ print('books-toc-creator.py [-o] -l <language>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
- print('books-toc-creator.py -l <language>')
+ print('books-toc-creator.py [-o] -l <language>')
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 @@
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 @@
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
--- 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 @@
Copyright (c) 2020-2021, The FreeBSD Project
Copyright (c) 2020-2021, Sergio Carlavilla <carlavilla@FreeBSD.org>
-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 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 <language>')
+ print('books-toc-tables-creator.py [-o] -l <language>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
- print('books-toc-tables-creator.py -l <language>')
+ print('books-toc-tables-creator.py [-o] -l <language>')
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 @@
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:])
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 23, 10:14 PM (3 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32047513
Default Alt Text
D30732.diff (12 KB)
Attached To
Mode
D30732: doc tools/books*py: improve argument handling of DOC_LANG, and others
Attached
Detach File
Event Timeline
Log In to Comment