aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-05-29 14:08:53 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-05-29 16:11:18 +0000
commit3be012086ed261ae41547b454189f6806fa9e375 (patch)
tree8a41a5c8d9062790b089b143b780318224259a98 /sources/pyside2
parent5be78207ef21c8fe6170aa4e711ce52ef0dca485 (diff)
Fix qtattributionsscannertorst.py
The tool was originally written to handle a license embedded in a Python file. This has changed, the license now exists as a text file. Rewrite the tool to concatenate the output piece-wise instead of using fixed formats to be able to cope with missing URLs and versions. Add the copyrights, which were previously missing. Task-number: PSYIDE-363 Change-Id: I5ec0bd7a4b81e9f794f56f6b2b09062c331936ae Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'sources/pyside2')
-rw-r--r--sources/pyside2/doc/qtattributionsscannertorst.py65
1 files changed, 28 insertions, 37 deletions
diff --git a/sources/pyside2/doc/qtattributionsscannertorst.py b/sources/pyside2/doc/qtattributionsscannertorst.py
index ac651ca8d..54982c1a0 100644
--- a/sources/pyside2/doc/qtattributionsscannertorst.py
+++ b/sources/pyside2/doc/qtattributionsscannertorst.py
@@ -41,7 +41,7 @@
Tool to run qtattributionsscanner and convert its output to rst
"""
-import os, json, subprocess, sys
+import os, json, subprocess, sys, warnings
def indent(lines, indent):
result = ''
@@ -76,38 +76,21 @@ licensed under third-party open-source licenses:
"""
-rstEntryFormat = """{}
+def rstHeadline(title):
+ return '{}\n{}\n'.format(title, '-' * len(title))
-{}
+def rstUrl(title, url):
+ return '`{} <{}>`_'.format(title, url)
-{}
+def rstLiteralBlock(lines):
+ return '::\n\n' + indent(lines, ' ') + '\n\n'
-{}
+def rstLiteralBlockFromText(text):
+ return rstLiteralBlock(text.strip().split('\n'))
-`Project Homepage <{}>`_ , upstream version: {}
-
-::
-
-{}
-
-
-"""
-
-# Extract the license which is embedded in triple quotes
-def extractLicense(fileName):
- result = []
+def readFile(fileName):
with open(fileName, 'r') as file:
- recording = False
- for line in file.readlines():
- line = line.strip("\n\r\xc2\xb6")
- if line == '"""':
- if recording:
- break
- else:
- recording = True
- elif recording:
- result.append(line)
- return result
+ return file.readlines()
def runScanner(directory, targetFileName):
# qtattributionsscanner recursively searches for qt_attribution.json files
@@ -120,17 +103,25 @@ def runScanner(directory, targetFileName):
with open(targetFileName, 'w') as targetFile:
targetFile.write(rstHeader)
for entry in json.loads(jsonS.decode('utf-8')):
- name = entry['Name']
- title = "{}\n{}".format(name, '-' * len(name))
- brief = entry['License']
+ content = '{}\n{}\n{}\n\n'.format(rstHeadline(entry['Name']),
+ entry['Description'], entry['QtUsage'])
url = entry['Homepage']
version = entry['Version']
- description = entry['Description']
- qtUsage = entry['QtUsage']
- content = extractLicense(entry['LicenseFile'])
- rst = rstEntryFormat.format(title, brief, description, qtUsage,
- url, version, indent(content, ' '))
- targetFile.write(rst)
+ if url and version:
+ content += '{}, upstream version: {}\n\n'.format(
+ rstUrl('Project Homepage', url), version)
+ copyright = entry['Copyright']
+ if copyright:
+ content += rstLiteralBlockFromText(copyright)
+ content += entry['License'] + '\n\n'
+ licenseFile = entry['LicenseFile']
+ if licenseFile:
+ if os.path.isfile(licenseFile):
+ content += rstLiteralBlock(readFile(licenseFile))
+ else:
+ warnings.warn('"{}" is not a file'.format(licenseFile),
+ RuntimeWarning)
+ targetFile.write(content)
if len(sys.argv) < 3:
print("Usage: qtattributionsscannertorst [directory] [file]'")