3
3
# SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com>
4
4
#
5
5
# SPDX-License-Identifier: Apache-2.0
6
-
7
-
8
6
import logging
9
7
import sys
10
8
from pathlib import Path
11
9
12
10
import click
13
11
14
- from opossum_lib .opossum .file_generation import OpossumFileWriter
15
- from opossum_lib .opossum .opossum_file_content import OpossumFileContent
16
- from opossum_lib .opossum .read_opossum_file import read_opossum_file
17
- from opossum_lib .scancode .convert_scancode_to_opossum import (
18
- convert_scancode_file_to_opossum ,
12
+ from opossum_lib .core .services .generate_impl import (
13
+ generate_impl ,
14
+ )
15
+ from opossum_lib .core .services .input_reader import InputReader
16
+ from opossum_lib .input_formats .opossum .services .opossum_file_reader import (
17
+ OpossumFileReader ,
18
+ )
19
+ from opossum_lib .input_formats .scancode .services .scancode_file_reader import (
20
+ ScancodeFileReader ,
19
21
)
20
22
21
23
@@ -47,12 +49,13 @@ def opossum_file() -> None:
47
49
default = "output.opossum" ,
48
50
show_default = True ,
49
51
help = "The file path to write the generated opossum document to. "
50
- 'If appropriate, the extension ".opossum" will be appended.' ,
52
+ 'If appropriate, the extension ".opossum" is appended. '
53
+ "If the output file already exists, it is overwritten." ,
51
54
)
52
55
def generate (
53
- scancode_json_files : list [str ],
54
- opossum_files : list [str ],
55
- outfile : str ,
56
+ scancode_json_files : list [Path ],
57
+ opossum_files : list [Path ],
58
+ outfile : Path ,
56
59
) -> None :
57
60
"""
58
61
Generate an Opossum file from various other file formats.
@@ -62,41 +65,19 @@ def generate(
62
65
- ScanCode
63
66
- Opossum
64
67
"""
65
- validate_input_and_exit_on_error (scancode_json_files , opossum_files )
66
- opossum_file_content = convert_after_valid_input (scancode_json_files , opossum_files )
67
-
68
- if not outfile .endswith (".opossum" ):
69
- outfile += ".opossum"
70
68
71
- if Path .is_file (Path (outfile )):
72
- logging .warning (f"{ outfile } already exists and will be overwritten." )
73
-
74
- OpossumFileWriter .write_opossum_information_to_file (
75
- opossum_file_content , Path (outfile )
76
- )
77
-
78
-
79
- def validate_input_and_exit_on_error (
80
- scancode_json_files : list [str ], opossum_files : list [str ]
81
- ) -> None :
82
69
total_number_of_files = len (scancode_json_files ) + len (opossum_files )
83
70
if total_number_of_files == 0 :
84
71
logging .warning ("No input provided. Exiting." )
85
72
sys .exit (1 )
86
73
if total_number_of_files > 1 :
87
74
logging .error ("Merging of multiple files not yet supported!" )
88
75
sys .exit (1 )
76
+ input_readers : list [InputReader ] = []
77
+ input_readers += [ScancodeFileReader (path = path ) for path in scancode_json_files ]
78
+ input_readers += [OpossumFileReader (path = path ) for path in opossum_files ]
89
79
90
-
91
- def convert_after_valid_input (
92
- scancode_json_files : list [str ], opossum_files : list [str ]
93
- ) -> OpossumFileContent :
94
- if len (scancode_json_files ) == 1 :
95
- scancode_json_input_file = scancode_json_files [0 ]
96
- return convert_scancode_file_to_opossum (scancode_json_input_file )
97
- else :
98
- opossum_input_file = opossum_files [0 ]
99
- return read_opossum_file (opossum_input_file )
80
+ generate_impl (input_readers = input_readers , output_file = Path (outfile ))
100
81
101
82
102
83
if __name__ == "__main__" :
0 commit comments