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.controller.network_generator import NetworkGenerator
37 from network_generation.controller.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)
46 print("I'm in", sys.argv)
48 if validator.is_valid():
49 configuration = validator.configuration()
50 generator = NetworkGenerator(configuration['network'])
51 network = generator.generate()
52 viewer = NetworkViewer(network)
54 output_folder:str = configuration['output-folder']
55 # If folder doesn't exist, then create it.
56 if not os.path.isdir(output_folder):
57 os.makedirs(output_folder)
59 name: str = configuration['network']['name']
62 if configuration['generation-tasks']['topology'] is True:
63 filename: str = output_folder + "/" + name + "-operational.json"
64 viewer.json().save(filename)
67 if configuration['generation-tasks']['svg'] is True:
68 filename: str = output_folder + "/" + name + ".svg"
72 if configuration['generation-tasks']['kml'] is True:
73 filename: str = output_folder + "/" + name + ".kml"
77 print(validator.error_message())