-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathcreate_module_inventory_file.py
More file actions
77 lines (60 loc) · 3.18 KB
/
Copy pathcreate_module_inventory_file.py
File metadata and controls
77 lines (60 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import argparse
import json
from pathlib import Path
from typing import List, Dict, Optional, Any
from common._maven_module.maven_module_reader import MavenModuleReader, ExceptionCollection
from common._maven_module.maven_module_reader_configuration import MavenModuleReaderConfiguration
from common.maven_module import MavenModule
def create_module_inventory_file(sdk_root: Path,
output_file: Path,
reader_config_file: Optional[Path] = None,
verbose: bool = False) -> List[MavenModule]:
reader_config: Optional[MavenModuleReaderConfiguration] = None
if reader_config_file is not None:
reader_config = MavenModuleReaderConfiguration.from_dictionary(json.load(reader_config_file.open("r")))
if verbose and len(reader_config.ignored_modules) > 0:
ignored_modules: str = "\n".join(m.identifier for m in reader_config.ignored_modules)
print(f"Following modules will be ignored:\n{ignored_modules}")
if verbose and len(reader_config.ignored_poms) > 0:
ignored_poms: str = "\n".join(p.path for p in reader_config.ignored_poms)
print(f"Following pom files will be ignored:\n{ignored_poms}")
try:
modules: List[MavenModule] = MavenModuleReader.read_recursively(sdk_root, reader_config, verbose)
except ExceptionCollection as exception_collection:
if verbose:
print("===================================================================================================")
print("Unable to generate the latest module inventory due to following errors:")
print(exception_collection)
exit(1)
return []
sorted_modules: List[MavenModule] = sorted(modules, key=lambda m: m.identifier)
serializable_modules: List[Dict[str, str]] = [module.to_dictionary() for module in sorted_modules]
with open(output_file, "w+") as f:
json.dump(serializable_modules, f, indent=2)
f.write("\n")
return sorted_modules
def main() -> None:
parser: argparse.ArgumentParser = argparse.ArgumentParser(
description="Generates a file containing the module configuration.")
parser.add_argument("--sdk-root-directory",
type=Path,
help="Path of the SDK root directory.",
required=True)
parser.add_argument("--output-file",
type=Path,
help="Path to where to store the module inventory file.",
required=True)
parser.add_argument("--script-config",
type=Path,
help="Path to the configuration file of this script.",
required=False,
default=None)
parser.add_argument("--verbose",
action="store_true",
help="Enable verbose output.",
required=False,
default=False)
args: Any = parser.parse_args()
create_module_inventory_file(args.sdk_root_directory, args.output_file, args.script_config, args.verbose)
if __name__ == "__main__":
main()