Skip to content

Commit a571dd0

Browse files
authored
[Utils] Add metrics and improve outputs for third-party generating scripts (#122)
- Add metrics computations in prompt script to have a better look on licenses use - Fix some typo in both scripts - Improve generation of third-party markdown file without undefined lines for version and copyrights - Improve CHANGELOG Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com>
1 parent d1e9384 commit a571dd0

File tree

4 files changed

+86
-41
lines changed

4 files changed

+86
-41
lines changed

CHANGELOG.md

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

88
## Unreleased
99

10+
### Changed
11+
12+
- [Utils] Add metrics and improve outputs for third-party generator scripts
13+
- [Project] Improve a bit CHANGELOG by leading scope keyword for each line
14+
1015
## [2.15.0] - 2024-03-12
1116

1217
### Added
1318

14-
- Project - Generate THIRD-PARTY.md based on user inputs ([#119](https://github.com/Orange-OpenSource/floss-toolbox/issues/119))
19+
- [Project] Generate THIRD-PARTY.md based on user inputs ([#119](https://github.com/Orange-OpenSource/floss-toolbox/issues/119))
1520

1621
## [2.14.0] - 2024-03-01
1722

1823
### Added
1924

20-
- Generate template-based text using variables ([#84](https://github.com/Orange-OpenSource/floss-toolbox/issues/84))
25+
- [Utils] Generate template-based text using variables ([#84](https://github.com/Orange-OpenSource/floss-toolbox/issues/84))
2126

2227
### Changed
2328

24-
- Make CHANGELOG more compliant ([#103](https://github.com/Orange-OpenSource/floss-toolbox/issues/103))
29+
- [Project] Make CHANGELOG more compliant ([#103](https://github.com/Orange-OpenSource/floss-toolbox/issues/103))
2530

2631
## [2.13.0] - 2023-07-19
2732

2833
### Added
2934

30-
- Diver - Compute metrics with in parameter URL to clone repo ([#98](https://github.com/Orange-OpenSource/floss-toolbox/issues/98))
35+
- [Diver] Compute metrics with in parameter URL to clone repo ([#98](https://github.com/Orange-OpenSource/floss-toolbox/issues/98))
3136

3237
### Fixed
3338

34-
- Project - Broken links in README ([#96](https://github.com/Orange-OpenSource/floss-toolbox/issues/96))
39+
- [Project] Broken links in README ([#96](https://github.com/Orange-OpenSource/floss-toolbox/issues/96))
3540

3641
## [2.12.0] - 2023-07-18
3742

3843
### Added
3944

40-
- Diver - Lines of codes and useful metrics ([#28](https://github.com/Orange-OpenSource/floss-toolbox/issues/28))
45+
- [Diver] Lines of codes and useful metrics ([#28](https://github.com/Orange-OpenSource/floss-toolbox/issues/28))
4146

4247
### Changed
4348

44-
- Project - Add DCO ([#87](https://github.com/Orange-OpenSource/floss-toolbox/issues/87))
45-
- Project - Add security policy file ([#90](https://github.com/Orange-OpenSource/floss-toolbox/issues/90))
46-
- Project - Split README files ([#85](https://github.com/Orange-OpenSource/floss-toolbox/issues/85))
47-
- Licenses Inventory - Move HTML test files to archives of release ([#86](https://github.com/Orange-OpenSource/floss-toolbox/issues/86))
48-
- GitHub - Add in dry-run Gemfiles ([#93](https://github.com/Orange-OpenSource/floss-toolbox/issues/93))
49+
- [Project] Add DCO ([#87](https://github.com/Orange-OpenSource/floss-toolbox/issues/87))
50+
- [Project] Add security policy file ([#90](https://github.com/Orange-OpenSource/floss-toolbox/issues/90))
51+
- [Project] Split README files ([#85](https://github.com/Orange-OpenSource/floss-toolbox/issues/85))
52+
- [Licenses Inventory] Move HTML test files to archives of release ([#86](https://github.com/Orange-OpenSource/floss-toolbox/issues/86))
53+
- [GitHub] Add in dry-run Gemfiles ([#93](https://github.com/Orange-OpenSource/floss-toolbox/issues/93))
4954

5055
## [2.11.0] - 2023-06-28
5156

5257
### Added
5358

54-
- GitHub - Set teams permissions to read ([#82](https://github.com/Orange-OpenSource/floss-toolbox/issues/82))
59+
- [GitHub] Set teams permissions to read ([#82](https://github.com/Orange-OpenSource/floss-toolbox/issues/82))
5560

5661
## [2.10.1] - 2023-05-31
5762

5863
### Fixed
5964

60-
- Diver - Path variables not protected ([#80](https://github.com/Orange-OpenSource/floss-toolbox/issues/80))
65+
- [Diver] Path variables not protected ([#80](https://github.com/Orange-OpenSource/floss-toolbox/issues/80))
6166

6267
## [2.10.0] - 2023-05-30
6368

6469
### Added
6570

66-
- Licenses Inventory - New release ([#77](https://github.com/Orange-OpenSource/floss-toolbox/issues/77))
71+
- [Licenses Inventory] New release ([#77](https://github.com/Orange-OpenSource/floss-toolbox/issues/77))
6772

6873
## [2.9.0] - 2023-03-31
6974

7075
### Added
7176

72-
- Licenses Inventory - New release ([#64](https://github.com/Orange-OpenSource/floss-toolbox/issues/64))
77+
- [Licenses Inventory] New release ([#64](https://github.com/Orange-OpenSource/floss-toolbox/issues/64))
7378

7479
## [2.8.0] - 2023-03-10
7580

7681
### Added
7782

78-
- Project - Split dry run ([#68](https://github.com/Orange-OpenSource/floss-toolbox/issues/68))
83+
- [Project] Split dry run ([#68](https://github.com/Orange-OpenSource/floss-toolbox/issues/68))
7984

8085
### Changed
8186

82-
- Project - Update copyright ([#70](https://github.com/Orange-OpenSource/floss-toolbox/issues/70))
83-
- Project - Improve README ([#69](https://github.com/Orange-OpenSource/floss-toolbox/issues/69))
87+
- [Project] Update copyright ([#70](https://github.com/Orange-OpenSource/floss-toolbox/issues/70))
88+
- [Project] Improve README ([#69](https://github.com/Orange-OpenSource/floss-toolbox/issues/69))
8489

8590
## [2.7.1]
8691

@@ -115,7 +120,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
115120

116121
### Added
117122

118-
- Look for leaks (GitHub) ([#44](https://github.com/Orange-OpenSource/floss-toolbox/issues/44))
123+
- [GitHub] Look for leaks ([#44](https://github.com/Orange-OpenSource/floss-toolbox/issues/44))
119124
- Dry run ([#29](https://github.com/Orange-OpenSource/floss-toolbox/issues/29))
120125

121126
### Changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ so as to iterate on each component and build the final Markdown file.
3232
```shell
3333
# --file: the path to the CSV file containing the details
3434
# --delimiter: to define how to split each row fields. Do not forget to escape it if ';'
35-
python3.8 third-party-generator.py --file components.csv.result --delimiter \;
35+
# --avoid: if a version or copyright field has "?" as value, do not add it in generated file
36+
python3.8 third-party-generator.py --file components.csv.result --delimiter \; --avoid \?
3637
```
3738

3839
### About the CSV file
@@ -72,7 +73,7 @@ requirements of the relevant license of the Third Party Software they are using.
7273

7374
Version 1.2.0
7475

75-
Copyright Copyright (c) 2023 Laszlo Teveli
76+
Copyright (c) 2023 Laszlo Teveli
7677

7778
**SwiftUI-Flow** is distributed under the terms and conditions of the [MIT License](https://opensource.org/license/mit).
7879
You may download the source code on the [following website](https://github.com/tevelee/SwiftUI-Flow).
@@ -82,7 +83,7 @@ You may download the source code on the [following website](https://github.com/t
8283

8384
Version 3.1.1
8485

85-
Copyright Copyright (c) 2021-2022 Lucas Zischka
86+
Copyright (c) 2021-2022 Lucas Zischka
8687

8788
**BottomSheet** is distributed under the terms and conditions of the [MIT License](https://opensource.org/license/mit).
8889
You may download the source code on the [following website](https://github.com/lucaszischka/BottomSheet).
@@ -92,7 +93,7 @@ You may download the source code on the [following website](https://github.com/l
9293

9394
Version 1.2.0
9495

95-
Copyright Copyright (c) 2021-2023 Orange SA
96+
Copyright (c) 2021-2023 Orange SA
9697

9798
**DeclarationAccessibility** is distributed under the terms and conditions of the [Apache-2.0 License](https://opensource.org/license/apache-2-0).
9899
You may download the source code on the [following website](https://github.com/Orange-OpenSource/accessibility-statement-lib-ios).

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

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
# Author: Pierre-Yves LAPERSONNE <pierreyves(dot)lapersonne(at)orange(dot)com> et al.
99

10-
# Version.............: 1.0.0
10+
# Version.............: 2.0.0
1111
# Since...............: 12/03/2024
1212
# Description.........: Builds a third-party Markdown based on a CSV file and a delimiter
1313

@@ -21,9 +21,6 @@
2121
# Configuration
2222
# -------------
2323

24-
# Script version
25-
VERSION = "1.0.0"
26-
2724
# Error codes
2825
EXIT_OK = 0
2926
ERROR_BAD_ARGUMENTS = 1
@@ -38,10 +35,12 @@
3835
required_args = parser.add_argument_group('Required arguments')
3936
required_args.add_argument('-f', '--file', help='The CSV file file to process', required=True)
4037
required_args.add_argument('-d', '--delimiter', help='The delimter symbol (e.g. ";" to split fields for each line of the CSV file', required=True)
38+
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)
4139
args = parser.parse_args()
4240

4341
content_file_name = args.file
4442
content_file_delimiter = args.delimiter
43+
content_file_avoid_field_symbol = args.avoid
4544

4645
if not os.path.isfile(content_file_name):
4746
print("❌ Error: the file parameter is not a file.")
@@ -55,6 +54,7 @@
5554
# Process file to build the results
5655
print(f'🆗 Let\'s now build the {RESULT_FILE_NAME} file!')
5756
computed_components = 0
57+
unique_computed_components = set()
5858
components_with_missing_licences = 0
5959
with open(content_file_name, 'r') as content_file:
6060
with open(RESULT_FILE_NAME, 'w') as result_file:
@@ -65,24 +65,47 @@
6565
6666
Third Party Software may impose additional restrictions and it is the user's responsibility to ensure that they have met the licensing
6767
requirements of the relevant license of the Third Party Software they are using.
68-
""")
68+
69+
""")
6970
csv_reader = csv.reader(content_file, delimiter=content_file_delimiter)
71+
csv_reader = sorted(csv_reader, key=lambda x: x[0]) # Sort entries by component name, i.e. first column of CSV
7072
for component_fields in csv_reader: # Iterator on each component returning one row (i.e. component) as array of fieds
7173
name = component_fields[0]
74+
75+
# Do not add component already added
76+
if name in unique_computed_components:
77+
print(f"- The component '{name}' has several occurences in the content file, won't process it anymore")
78+
computed_components += 1
79+
continue
80+
81+
unique_computed_components.add(name)
7282
repository = component_fields[1]
7383
license_name = component_fields[2]
7484
copyright = component_fields[3]
7585
version = component_fields[4]
7686
license_url = LICENSES[license_name]
77-
component_entry = """
78-
## {name}
79-
87+
component_entry = """## {name}
88+
""".format(name=name)
89+
90+
# Add version only if defined
91+
if version != content_file_avoid_field_symbol:
92+
component_entry += """
8093
Version {version}
94+
""".format(version=version)
95+
else:
96+
print(f"- No version defined for component '{name}'")
8197

98+
# Add copyright only if defined
99+
if copyright != content_file_avoid_field_symbol:
100+
component_entry += """
82101
Copyright {copyright}
102+
""".format(copyright=copyright)
103+
else:
104+
print(f"- No copyright defined for component '{name}'")
83105

106+
component_entry += """
84107
**{name}** is distributed under the terms and conditions of the [{license} License]({url}).
85-
You may download the source code on the [following website]({repository}).""".format(name=name, version=version, copyright=copyright, license=license_name, url=license_url, repository=repository)
108+
You may download the source code on the [following website]({repository}).""".format(name=name, license=license_name, url=license_url, repository=repository)
86109
result_file.write(component_entry)
87110
result_file.write("\n\n")
88111
computed_components += 1
@@ -93,10 +116,10 @@
93116
content_file.close()
94117
result_file.close()
95118
print("\n")
96-
print(f'🎉 Operation completed! Find your result file at "{RESULT_FILE_NAME}" with {computed_components} components!')
119+
print(f'🎉 Operation completed! Find your result file at "{RESULT_FILE_NAME}" with {computed_components} components (and {len(unique_computed_components)} unique)!')
97120
if components_with_missing_licences > 0:
98121
print("\n")
99-
print(f'❗ But beware you have {components_with_missing_licences} components without managed licenses, you shall fix they result file with suitable names and URL ❗')
122+
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 ❗')
100123
print("👉 Please refer to either https://opensource.org/licenses or https://spdx.org/licenses/ 👈")
101124
print("🧡 You can also submit an issue or a pull request to manage new licences: https://github.com/Orange-OpenSource/floss-toolbox/issues/new 🧡")
102125

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,20 @@
77
#
88
# Author: Pierre-Yves LAPERSONNE <pierreyves(dot)lapersonne(at)orange(dot)com> et al.
99

10-
# Version.............: 1.0.0
10+
# Version.............: 1.1.0
1111
# Since...............: 12/03/2024
1212
# Description.........: Builds a CSV file based on user inputs.
1313

1414
import csv
1515
import os
1616
import sys
1717

18+
from collections import defaultdict
1819
from licenses import *
1920

2021
# Configuration
2122
# -------------
2223

23-
# Script version
24-
VERSION = "1.0.0"
25-
2624
# Error codes
2725
EXIT_OK = 0
2826
ERROR_BAD_ARGUMENTS = 1
@@ -114,13 +112,13 @@ def check_value(value):
114112
continue
115113

116114
# Copyright assigned to the component is optional
117-
input_component_copyright = input("✏️ Copyright of the component ('bye' to exit): ")
115+
input_component_copyright = input("✏️ Copyright of the component ('bye' to exit, '?' if unknown): ")
118116
if not check_value(input_component_copyright):
119117
continue
120118
check_exit(input_component_copyright)
121119

122120
# Version of the component is optional
123-
input_component_version = input("✏️ Version of the component ('bye' to exit): ")
121+
input_component_version = input("✏️ Version of the component ('bye' to exit, '?' if unknown): ")
124122
if not check_value(input_component_version):
125123
continue
126124
check_exit(input_component_version)
@@ -148,8 +146,26 @@ def check_value(value):
148146
print(f'🎉 Operation completed! Find your result file at "{SAVE_FILE}" with {components_added} new component(s)! 🎉')
149147
if components_with_missing_licences > 0:
150148
print("\n")
151-
print(f'❗ But beware you have {components_with_missing_licences} components without managed licenses, you shall fix they result file with suitable names and URL ❗')
149+
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 ❗')
152150
print("👉 Please refer to either https://opensource.org/licenses or https://spdx.org/licenses/ 👈")
153151
print("🧡 You can also submit an issue or a pull request to manage new licences: https://github.com/Orange-OpenSource/floss-toolbox/issues/new 🧡")
154152

153+
# Some figures
154+
result_file = open(SAVE_FILE, "r")
155+
reader = csv.reader(result_file, delimiter=SAVE_FILE_DELIMITER)
156+
stats = defaultdict(int)
157+
158+
for i, line in enumerate(reader):
159+
license_name = line[2]
160+
stats[license_name] += 1
161+
162+
result_file.close()
163+
flat_stats = [(license, count) for license, count in stats.items()]
164+
sorted_stats = sorted(flat_stats, key=lambda x: x[1], reverse=True)
165+
166+
print("\n")
167+
print("ℹ️ Here are some metrics about the licences: ")
168+
for license, count in sorted_stats:
169+
print(f"\t {count} component(s) under license {license}")
170+
155171
sys.exit(EXIT_OK)

0 commit comments

Comments
 (0)