diff --git a/CHANGELOG.md b/CHANGELOG.md index a98f34e..9bae6dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/Orange-OpenSource/floss-toolbox/compare/2.16.0..dev) +### Changed + +- [Utils] Default values for THIRD_PARTY generator script, shared configuration with prompt script + ## [2.16.0](https://github.com/Orange-OpenSource/floss-toolbox/compare/2.16.0..2.15.0) - 2024-03-16 ### Added diff --git a/toolbox/utils/third-party-generator/README.md b/toolbox/utils/third-party-generator/README.md index d1d0fca..a1ea915 100644 --- a/toolbox/utils/third-party-generator/README.md +++ b/toolbox/utils/third-party-generator/README.md @@ -34,6 +34,9 @@ so as to iterate on each component and build the final Markdown file. # --delimiter: to define how to split each row fields. Do not forget to escape it if ';' # --avoid: if a version or copyright field has "?" as value, do not add it in generated file python3.8 third-party-generator.py --file components.csv.result --delimiter \; --avoid \? + +# or use the default configuration +python3.8 third-party-generator.py ``` ### About the CSV file @@ -53,7 +56,7 @@ Meaning: - version: the verison of the component -For example, with the CSV file bellow +For example, with the CSV file bellow (without the first line containing headers, don't fill it, not used) ```csv SwiftUI-Flow;https://github.com/tevelee/SwiftUI-Flow;MIT;Copyright (c) 2023 Laszlo Teveli;1.2.0 BottomSheet;https://github.com/lucaszischka/BottomSheet;MIT;Copyright (c) 2021-2022 Lucas Zischka;3.1.1 @@ -99,8 +102,10 @@ Copyright (c) 2021-2023 Orange SA You may download the source code on the [following website](https://github.com/Orange-OpenSource/accessibility-statement-lib-ios). ``` -### About the licenses.py file +### About the configuration.py file There is plenty of licenses and also a lot of standards. It can be a pain or time-consuming to let the user write the license in use for a component, then find the URL pointing to the license text and write it. In fact, such details are still known so we can let the user choose within list items. -The *licenses.py* file lists main licenses we can meet during audits. Each entry in this dictionary has a license name in SPDX short-identifier format and the URL pointing to the license text. Thus these details will be added in the THIRD-PARTY file. +The *configuration.py* file lists main licenses we can meet during audits. Each entry in this dictionary has a license name in SPDX short-identifier format and the URL pointing to the license text. Thus these details will be added in the THIRD-PARTY file. + +It contains also shared configuration between scripts. diff --git a/toolbox/utils/third-party-generator/licenses.py b/toolbox/utils/third-party-generator/configuration.py similarity index 91% rename from toolbox/utils/third-party-generator/licenses.py rename to toolbox/utils/third-party-generator/configuration.py index 00a07a1..07590c4 100644 --- a/toolbox/utils/third-party-generator/licenses.py +++ b/toolbox/utils/third-party-generator/configuration.py @@ -10,10 +10,20 @@ # Authors: See CONTRIBUTORS.txt # Software description: A toolbox of scripts to help work of forges admins and open source referents -# Version.............: 1.0.0 +# Version.............: 1.1.0 # Since...............: 12/03/2024 # Description.........: Just to list managed licenses and share values between scripts +# Some configuration +# ------------------ + +DEFAULT_PROMPT_RESULT_FILE = "components.csv.result" +DEFAULT_PROMPT_RESULT_FILE_DELIMITER = ";" +DEFAULT_AVOID_FIELD_SYMBOL = "?" + +# Licenses to manage +# ------------------ + # Please refer to https://opensource.org/licenses or https://spdx.org/licenses/ # Use SPDX short identifier as key, URL of license text as value LICENSES = { diff --git a/toolbox/utils/third-party-generator/third-party-generator.py b/toolbox/utils/third-party-generator/third-party-generator.py index e8df016..d2536ef 100755 --- a/toolbox/utils/third-party-generator/third-party-generator.py +++ b/toolbox/utils/third-party-generator/third-party-generator.py @@ -10,16 +10,16 @@ # Authors: See CONTRIBUTORS.txt # Software description: A toolbox of scripts to help work of forges admins and open source referents -# Version.............: 2.0.0 +# Version.............: 3.0.0 # Since...............: 12/03/2024 -# Description.........: Builds a third-party Markdown based on a CSV file and a delimiter +# Description.........: Builds a third-party Markdown file based on a CSV file and a delimiter import argparse import csv import os import sys -from licenses import * +from configuration import * # Configuration # ------------- @@ -36,9 +36,9 @@ parser = argparse.ArgumentParser(description='This script will build a third-party file listing components based on a CSV file and a delimiter') required_args = parser.add_argument_group('Required arguments') -required_args.add_argument('-f', '--file', help='The CSV file file to process', required=True) -required_args.add_argument('-d', '--delimiter', help='The delimter symbol (e.g. ";" to split fields for each line of the CSV file', required=True) -required_args.add_argument('-a', '--avoid', help='The sequence to use to define wether or not a specific field (version or copyright) must be ignored (e.g. "?" in the CSV raw field', required=True) +required_args.add_argument('-f', '--file', help='The CSV file file to process', default=DEFAULT_PROMPT_RESULT_FILE) +required_args.add_argument('-d', '--delimiter', help='The delimter symbol (e.g. ";" to split fields for each line of the CSV file', default=DEFAULT_PROMPT_RESULT_FILE_DELIMITER) +required_args.add_argument('-a', '--avoid', help='The sequence to use to define wether or not a specific field (version or copyright) must be ignored (e.g. "?" in the CSV raw field', default=DEFAULT_AVOID_FIELD_SYMBOL) args = parser.parse_args() content_file_name = args.file diff --git a/toolbox/utils/third-party-generator/third-party-prompt.py b/toolbox/utils/third-party-generator/third-party-prompt.py index 2eb7456..3072f45 100755 --- a/toolbox/utils/third-party-generator/third-party-prompt.py +++ b/toolbox/utils/third-party-generator/third-party-prompt.py @@ -10,7 +10,7 @@ # Authors: See CONTRIBUTORS.txt # Software description: A toolbox of scripts to help work of forges admins and open source referents -# Version.............: 1.1.0 +# Version.............: 1.2.0 # Since...............: 12/03/2024 # Description.........: Builds a CSV file based on user inputs. @@ -19,7 +19,7 @@ import sys from collections import defaultdict -from licenses import * +from configuration import * # Configuration # ------------- @@ -28,10 +28,6 @@ EXIT_OK = 0 ERROR_BAD_ARGUMENTS = 1 -# Other config -SAVE_FILE = "components.csv.result" -SAVE_FILE_DELIMITER = ";" - # Methods # ------- @@ -44,8 +40,8 @@ def check_value(value): if not value: print("✋ Woops, value must be defined") return False - if SAVE_FILE_DELIMITER in value: - print(f'✋ Data are exported in CSV, avoid using "{SAVE_FILE_DELIMITER}"') + if DEFAULT_PROMPT_RESULT_FILE_DELIMITER in value: + print(f'✋ Data are exported in CSV, avoid using "{DEFAULT_PROMPT_RESULT_FILE_DELIMITER}"') return False return True @@ -62,20 +58,20 @@ def check_value(value): sys.exit(ERROR_BAD_ARGUMENTS) # Check if temporary file exists and ask to recover or delete it -if os.path.isfile(SAVE_FILE): +if os.path.isfile(DEFAULT_PROMPT_RESULT_FILE): print("⚠️ A previous backup exists") input_user_answer = input("❓ Do you want to use it? (yes/NO) ") if input_user_answer.lower() in ["yes", "y"]: print("🆗 Keeping current version of save file") - save_file = open(SAVE_FILE, "a") + save_file = open(DEFAULT_PROMPT_RESULT_FILE, "a") else: print("🆗 Deleting previous save file") - os.remove(SAVE_FILE) + os.remove(DEFAULT_PROMPT_RESULT_FILE) print("🔨 Creating new save file") - save_file = open(SAVE_FILE, "a") + save_file = open(DEFAULT_PROMPT_RESULT_FILE, "a") else: print("🔨 No previous backup, creating a new save file") - save_file = open(SAVE_FILE, "x") + save_file = open(DEFAULT_PROMPT_RESULT_FILE, "x") # Ask to user for component details: name, copyright, license, repository hyperlink print("🆗 Let's get the details of the components to add!") @@ -115,19 +111,19 @@ def check_value(value): continue # Copyright assigned to the component is optional - input_component_copyright = input("✏️ Copyright of the component ('bye' to exit, '?' if unknown): ") + input_component_copyright = input("✏️ Copyright of the component ('bye' to exit, '{escape}' if unknown): ".format(escape=DEFAULT_AVOID_FIELD_SYMBOL)) if not check_value(input_component_copyright): continue check_exit(input_component_copyright) # Version of the component is optional - input_component_version = input("✏️ Version of the component ('bye' to exit, '?' if unknown): ") + input_component_version = input("✏️ Version of the component ('bye' to exit, '{escape}' if unknown): ".format(escape=DEFAULT_AVOID_FIELD_SYMBOL)) if not check_value(input_component_version): continue check_exit(input_component_version) # Add the new entry in storage file - save_file.write(input_component_name + SAVE_FILE_DELIMITER + input_component_repo + SAVE_FILE_DELIMITER + input_component_license_name + SAVE_FILE_DELIMITER + input_component_copyright + SAVE_FILE_DELIMITER + input_component_version) + save_file.write(input_component_name + DEFAULT_PROMPT_RESULT_FILE_DELIMITER + input_component_repo + DEFAULT_PROMPT_RESULT_FILE_DELIMITER + input_component_license_name + DEFAULT_PROMPT_RESULT_FILE_DELIMITER + input_component_copyright + DEFAULT_PROMPT_RESULT_FILE_DELIMITER + input_component_version) save_file.write("\n") components_added += 1 @@ -146,7 +142,7 @@ def check_value(value): # Clean up save_file.close() print("\n") -print(f'🎉 Operation completed! Find your result file at "{SAVE_FILE}" with {components_added} new component(s)! 🎉') +print(f'🎉 Operation completed! Find your result file at "{DEFAULT_PROMPT_RESULT_FILE}" with {components_added} new component(s)! 🎉') if components_with_missing_licences > 0: print("\n") print(f'❗ But beware you have {components_with_missing_licences} components without managed licenses, you shall fix the result file with suitable names and URL ❗') @@ -154,8 +150,8 @@ def check_value(value): print("🧡 You can also submit an issue or a pull request to manage new licences: https://github.com/Orange-OpenSource/floss-toolbox/issues/new 🧡") # Some figures -result_file = open(SAVE_FILE, "r") -reader = csv.reader(result_file, delimiter=SAVE_FILE_DELIMITER) +result_file = open(DEFAULT_PROMPT_RESULT_FILE, "r") +reader = csv.reader(result_file, delimiter=DEFAULT_PROMPT_RESULT_FILE_DELIMITER) stats = defaultdict(int) for i, line in enumerate(reader):