Skip to content
Snippets Groups Projects
Commit 12f8046f authored by Torben's avatar Torben Committed by Timo Koch
Browse files

[extract module] add option to include GPLv3 license to new module

So far there was no option to automatically add a a GPLv3 license to a new module that was created with the 'extract_as_new_module.py' script.
This led to many modules being published without proper licensing. This extension adds the option to automatically add said license interactively during the module setup with the script.
Information about licensing is also added to the README.md file of the module.
The license text can be found in a file within the 'bin/license_for_module_extraction/' directory.
parent 69d3921f
No related branches found
No related tags found
1 merge request!3368[extract module] add option to include GPLv3 license to new module
...@@ -270,6 +270,33 @@ def removeFolder(modulePath, subFolder): ...@@ -270,6 +270,33 @@ def removeFolder(modulePath, subFolder):
removeAddSubdirectoryCommand(parentCML, subFolderName) removeAddSubdirectoryCommand(parentCML, subFolderName)
shutil.rmtree(subFolderPath) shutil.rmtree(subFolderPath)
def guideAddLicenseFile(modulePath, baseFolder, readme):
"""Optionally add a GPLv3 LICENSE.md file to the new module"""
addLicense = queryYesNo("Do you want to add a GPLv3 license file as LICENSE.md?")
if addLicense:
# delete existing license file
moduleLicense = os.path.join(newModulePath, "LICENSE")
if os.path.exists(moduleLicense):
os.remove(moduleLicense)
# copy the LICENCE file from dumux
licensePath = os.path.join(baseFolder, "dumux/bin/license_for_module_extraction/gplv3.md")
if not os.path.exists(licensePath):
print("WARNING: Could not find the GPLv3 license file. Skipping license file addition.")
else:
# copy GPLv3 license file to new module
newLicensePath = os.path.join(newModulePath, "LICENSE.md")
shutil.copy(licensePath, newLicensePath)
# commit license to git
runGitCommand(modulePath, "git add LICENSE.md")
runGitCommand(modulePath, 'git commit -m "Add GLPv3 license file"')
# include license information to README.md
appendFileContent(readme, infoReadmeLicense())
runGitCommand(modulePath, "git add README.md")
runGitCommand(modulePath, 'git commit -m "Add license information to README.md"')
# check if license file was added
if os.path.exists(newLicensePath):
print("License file was successfully added to the new module.")
print("\n")
def guideFolderDeletion(modulePath, candidates): def guideFolderDeletion(modulePath, candidates):
"""Interactive process to delete folders that may not be needed""" """Interactive process to delete folders that may not be needed"""
...@@ -512,6 +539,18 @@ def infoReadmeMain(moduleDirectory, subFolder, sourceFiles): ...@@ -512,6 +539,18 @@ def infoReadmeMain(moduleDirectory, subFolder, sourceFiles):
""" """
).format(moduleDirectory, subFolderString, sourceString) ).format(moduleDirectory, subFolderString, sourceString)
def infoReadmeLicense():
"""License part of the README.md document"""
return textwrap.dedent(
"""\
## License
This project is licensed under the terms and conditions of the GNU General Public License (GPL) version 3 or - at your option - any later version.
The GPL can be found in the [LICENSE.md](LICENSE.md) file provided in the topmost directory of the source code tree.
"""
)
def infoReadmeInstallation(remoteURL, installScriptName, newModuleName): def infoReadmeInstallation(remoteURL, installScriptName, newModuleName):
"""Installation part of the README.md document""" """Installation part of the README.md document"""
...@@ -683,6 +722,9 @@ if __name__ == "__main__": ...@@ -683,6 +722,9 @@ if __name__ == "__main__":
if not remoteURL: if not remoteURL:
print(noRemoteURLInfo(newModuleName)) print(noRemoteURLInfo(newModuleName))
# optionally add a license file
guideAddLicenseFile(newModulePath, baseFolder, newReadme)
# make install script & finalize readme # make install script & finalize readme
deps = dependenciesAndPatches(newModulePath, [modulePath]) deps = dependenciesAndPatches(newModulePath, [modulePath])
if deps: if deps:
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment