Skip to content

Commit 6ff8f30

Browse files
committed
[Utils] Share configuration between 3rd parties related scripts
- Now the THIRD-PARTY generator has default values - Prompt and generator scripts share configuration values Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
1 parent d6a1ed2 commit 6ff8f30

File tree

5 files changed

+44
-29
lines changed

5 files changed

+44
-29
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased](https://github.com/Orange-OpenSource/floss-toolbox/compare/2.16.0..dev)
99

10+
### Changed
11+
12+
- [Utils] Default values for THIRD_PARTY generator script, shared configuration with prompt script
13+
1014
## [2.16.0](https://github.com/Orange-OpenSource/floss-toolbox/compare/2.16.0..2.15.0) - 2024-03-16
1115

1216
### Added

toolbox/utils/third-party-generator/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ so as to iterate on each component and build the final Markdown file.
3434
# --delimiter: to define how to split each row fields. Do not forget to escape it if ';'
3535
# --avoid: if a version or copyright field has "?" as value, do not add it in generated file
3636
python3.8 third-party-generator.py --file components.csv.result --delimiter \; --avoid \?
37+
38+
# or use the default configuration
39+
python3.8 third-party-generator.py
3740
```
3841

3942
### About the CSV file
@@ -53,7 +56,7 @@ Meaning:
5356
- version: the verison of the component
5457

5558

56-
For example, with the CSV file bellow
59+
For example, with the CSV file bellow (without the first line containing headers, don't fill it, not used)
5760
```csv
5861
SwiftUI-Flow;https://github.com/tevelee/SwiftUI-Flow;MIT;Copyright (c) 2023 Laszlo Teveli;1.2.0
5962
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
99102
You may download the source code on the [following website](https://github.com/Orange-OpenSource/accessibility-statement-lib-ios).
100103
```
101104

102-
### About the licenses.py file
105+
### About the configuration.py file
103106

104107
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,
105108
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.
106-
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.
109+
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.
110+
111+
It contains also shared configuration between scripts.

toolbox/utils/third-party-generator/licenses.py renamed to toolbox/utils/third-party-generator/configuration.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@
1010
# Authors: See CONTRIBUTORS.txt
1111
# Software description: A toolbox of scripts to help work of forges admins and open source referents
1212

13-
# Version.............: 1.0.0
13+
# Version.............: 1.1.0
1414
# Since...............: 12/03/2024
1515
# Description.........: Just to list managed licenses and share values between scripts
1616

17+
# Some configuration
18+
# ------------------
19+
20+
DEFAULT_PROMPT_RESULT_FILE = "components.csv.result"
21+
DEFAULT_PROMPT_RESULT_FILE_DELIMITER = ";"
22+
DEFAULT_AVOID_FIELD_SYMBOL = "?"
23+
24+
# Licenses to manage
25+
# ------------------
26+
1727
# Please refer to https://opensource.org/licenses or https://spdx.org/licenses/
1828
# Use SPDX short identifier as key, URL of license text as value
1929
LICENSES = {

toolbox/utils/third-party-generator/third-party-generator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
# Authors: See CONTRIBUTORS.txt
1111
# Software description: A toolbox of scripts to help work of forges admins and open source referents
1212

13-
# Version.............: 2.0.0
13+
# Version.............: 3.0.0
1414
# Since...............: 12/03/2024
15-
# Description.........: Builds a third-party Markdown based on a CSV file and a delimiter
15+
# Description.........: Builds a third-party Markdown file based on a CSV file and a delimiter
1616

1717
import argparse
1818
import csv
1919
import os
2020
import sys
2121

22-
from licenses import *
22+
from configuration import *
2323

2424
# Configuration
2525
# -------------
@@ -36,9 +36,9 @@
3636

3737
parser = argparse.ArgumentParser(description='This script will build a third-party file listing components based on a CSV file and a delimiter')
3838
required_args = parser.add_argument_group('Required arguments')
39-
required_args.add_argument('-f', '--file', help='The CSV file file to process', required=True)
40-
required_args.add_argument('-d', '--delimiter', help='The delimter symbol (e.g. ";" to split fields for each line of the CSV file', required=True)
41-
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)
39+
required_args.add_argument('-f', '--file', help='The CSV file file to process', default=DEFAULT_PROMPT_RESULT_FILE)
40+
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)
41+
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)
4242
args = parser.parse_args()
4343

4444
content_file_name = args.file

toolbox/utils/third-party-generator/third-party-prompt.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Authors: See CONTRIBUTORS.txt
1111
# Software description: A toolbox of scripts to help work of forges admins and open source referents
1212

13-
# Version.............: 1.1.0
13+
# Version.............: 1.2.0
1414
# Since...............: 12/03/2024
1515
# Description.........: Builds a CSV file based on user inputs.
1616

@@ -19,7 +19,7 @@
1919
import sys
2020

2121
from collections import defaultdict
22-
from licenses import *
22+
from configuration import *
2323

2424
# Configuration
2525
# -------------
@@ -28,10 +28,6 @@
2828
EXIT_OK = 0
2929
ERROR_BAD_ARGUMENTS = 1
3030

31-
# Other config
32-
SAVE_FILE = "components.csv.result"
33-
SAVE_FILE_DELIMITER = ";"
34-
3531
# Methods
3632
# -------
3733

@@ -44,8 +40,8 @@ def check_value(value):
4440
if not value:
4541
print("✋ Woops, value must be defined")
4642
return False
47-
if SAVE_FILE_DELIMITER in value:
48-
print(f'✋ Data are exported in CSV, avoid using "{SAVE_FILE_DELIMITER}"')
43+
if DEFAULT_PROMPT_RESULT_FILE_DELIMITER in value:
44+
print(f'✋ Data are exported in CSV, avoid using "{DEFAULT_PROMPT_RESULT_FILE_DELIMITER}"')
4945
return False
5046
return True
5147

@@ -62,20 +58,20 @@ def check_value(value):
6258
sys.exit(ERROR_BAD_ARGUMENTS)
6359

6460
# Check if temporary file exists and ask to recover or delete it
65-
if os.path.isfile(SAVE_FILE):
61+
if os.path.isfile(DEFAULT_PROMPT_RESULT_FILE):
6662
print("⚠️ A previous backup exists")
6763
input_user_answer = input("❓ Do you want to use it? (yes/NO) ")
6864
if input_user_answer.lower() in ["yes", "y"]:
6965
print("🆗 Keeping current version of save file")
70-
save_file = open(SAVE_FILE, "a")
66+
save_file = open(DEFAULT_PROMPT_RESULT_FILE, "a")
7167
else:
7268
print("🆗 Deleting previous save file")
73-
os.remove(SAVE_FILE)
69+
os.remove(DEFAULT_PROMPT_RESULT_FILE)
7470
print("🔨 Creating new save file")
75-
save_file = open(SAVE_FILE, "a")
71+
save_file = open(DEFAULT_PROMPT_RESULT_FILE, "a")
7672
else:
7773
print("🔨 No previous backup, creating a new save file")
78-
save_file = open(SAVE_FILE, "x")
74+
save_file = open(DEFAULT_PROMPT_RESULT_FILE, "x")
7975

8076
# Ask to user for component details: name, copyright, license, repository hyperlink
8177
print("🆗 Let's get the details of the components to add!")
@@ -115,19 +111,19 @@ def check_value(value):
115111
continue
116112

117113
# Copyright assigned to the component is optional
118-
input_component_copyright = input("✏️ Copyright of the component ('bye' to exit, '?' if unknown): ")
114+
input_component_copyright = input("✏️ Copyright of the component ('bye' to exit, '{escape}' if unknown): ".format(escape=DEFAULT_AVOID_FIELD_SYMBOL))
119115
if not check_value(input_component_copyright):
120116
continue
121117
check_exit(input_component_copyright)
122118

123119
# Version of the component is optional
124-
input_component_version = input("✏️ Version of the component ('bye' to exit, '?' if unknown): ")
120+
input_component_version = input("✏️ Version of the component ('bye' to exit, '{escape}' if unknown): ".format(escape=DEFAULT_AVOID_FIELD_SYMBOL))
125121
if not check_value(input_component_version):
126122
continue
127123
check_exit(input_component_version)
128124

129125
# Add the new entry in storage file
130-
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)
126+
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)
131127
save_file.write("\n")
132128
components_added += 1
133129

@@ -146,16 +142,16 @@ def check_value(value):
146142
# Clean up
147143
save_file.close()
148144
print("\n")
149-
print(f'🎉 Operation completed! Find your result file at "{SAVE_FILE}" with {components_added} new component(s)! 🎉')
145+
print(f'🎉 Operation completed! Find your result file at "{DEFAULT_PROMPT_RESULT_FILE}" with {components_added} new component(s)! 🎉')
150146
if components_with_missing_licences > 0:
151147
print("\n")
152148
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 ❗')
153149
print("👉 Please refer to either https://opensource.org/licenses or https://spdx.org/licenses/ 👈")
154150
print("🧡 You can also submit an issue or a pull request to manage new licences: https://github.com/Orange-OpenSource/floss-toolbox/issues/new 🧡")
155151

156152
# Some figures
157-
result_file = open(SAVE_FILE, "r")
158-
reader = csv.reader(result_file, delimiter=SAVE_FILE_DELIMITER)
153+
result_file = open(DEFAULT_PROMPT_RESULT_FILE, "r")
154+
reader = csv.reader(result_file, delimiter=DEFAULT_PROMPT_RESULT_FILE_DELIMITER)
159155
stats = defaultdict(int)
160156

161157
for i, line in enumerate(reader):

0 commit comments

Comments
 (0)