1 # Copyright 2023 highstreet technologies GmbH
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # inspired by https://github.com/rochacbruno/python-project-template
17 """CLI interface for network_generation project.
19 Be creative! do whatever you want!
21 - Install click or typer and create a CLI app
22 - Use builtin argparse
23 - Start a web application
24 - Import things from your .base module
30 Module as entry point to generate an ietf topology json
35 from network_generation.view.network_viewer import NetworkViewer
36 from network_generation.base import NetworkGenerator
37 from network_generation.parameter_validator import ParameterValidator
39 def main(): # pragma: no cover
41 The main function executes on commands:
42 `python -m network_generation`.
45 validator: ParameterValidator = ParameterValidator(sys.argv)
47 if validator.is_valid():
48 configuration = validator.configuration()
49 generator = NetworkGenerator(configuration['network'])
50 network = generator.generate()
51 viewer = NetworkViewer(network)
53 output_folder:str = configuration['output-folder']
54 # If folder doesn't exist, then create it.
55 if not os.path.isdir(output_folder):
56 os.makedirs(output_folder)
58 name: str = configuration['network']['name']
61 if configuration['generation-tasks']['topology'] is True:
62 filename: str = output_folder + "/" + name + "-operational.json"
63 viewer.json().save(filename)
66 if configuration['generation-tasks']['svg'] is True:
67 filename: str = output_folder + "/" + name + ".svg"
71 if configuration['generation-tasks']['kml'] is True:
72 filename: str = output_folder + "/" + name + ".kml"
76 print(validator.error_message())