From: Martin Skorupski Date: Fri, 3 Nov 2023 15:46:05 +0000 (+0100) Subject: Move all business logic code under template folder X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=c8e3bd35883f540afe023fd077ad64cde327e18a;p=oam.git Move all business logic code under template folder - starting py goes to cli.py Issue-ID: OAM-385 Change-Id: I1b13ed74028cf1045f1d942e9d242e23da6678fa Signed-off-by: Martin Skorupski --- diff --git a/code/network-generator/network_generation/__init__.py b/code/network-generator/network_generation/__init__.py new file mode 100644 index 0000000..21a1465 --- /dev/null +++ b/code/network-generator/network_generation/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2023 highstreet technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# inspired by https://github.com/rochacbruno/python-project-template diff --git a/code/network-generator/network_generation/__main__.py b/code/network-generator/network_generation/__main__.py new file mode 100644 index 0000000..5f86ae6 --- /dev/null +++ b/code/network-generator/network_generation/__main__.py @@ -0,0 +1,22 @@ +# Copyright 2023 highstreet technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# inspired by https://github.com/rochacbruno/python-project-template + +"""Entry point for network_generation.""" + +from network_generation.cli import main # pragma: no cover + +if __name__ == "__main__": # pragma: no cover + main() diff --git a/code/network-generator/network_generation/cli.py b/code/network-generator/network_generation/cli.py new file mode 100644 index 0000000..8067273 --- /dev/null +++ b/code/network-generator/network_generation/cli.py @@ -0,0 +1,78 @@ +# Copyright 2023 highstreet technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# inspired by https://github.com/rochacbruno/python-project-template + +"""CLI interface for network_generation project. + +Be creative! do whatever you want! + +- Install click or typer and create a CLI app +- Use builtin argparse +- Start a web application +- Import things from your .base module +""" + + + +""" +Module as entry point to generate an ietf topology json +""" +import os +import sys + +from network_generation.view.network_viewer import NetworkViewer +from network_generation.controller.network_generator import NetworkGenerator +from network_generation.controller.parameter_validator import ParameterValidator + +def main(): # pragma: no cover + """ + The main function executes on commands: + `python -m network_generation`. + + """ + validator: ParameterValidator = ParameterValidator(sys.argv) + print("I'm in", sys.argv) + + if validator.is_valid(): + configuration = validator.configuration() + generator = NetworkGenerator(configuration['network']) + network = generator.generate() + viewer = NetworkViewer(network) + + output_folder:str = configuration['output-folder'] + # If folder doesn't exist, then create it. + if not os.path.isdir(output_folder): + os.makedirs(output_folder) + + name: str = configuration['network']['name'] + + # topology json + if configuration['generation-tasks']['topology'] is True: + filename: str = output_folder + "/" + name + "-operational.json" + viewer.json().save(filename) + + # svg xml + if configuration['generation-tasks']['svg'] is True: + filename: str = output_folder + "/" + name + ".svg" + viewer.svg(filename) + + # kml xml + if configuration['generation-tasks']['kml'] is True: + filename: str = output_folder + "/" + name + ".kml" + viewer.kml(filename) + + else: + print(validator.error_message()) + diff --git a/code/network-generator/network_generator.py b/code/network-generator/network_generator.py deleted file mode 100644 index 054a23f..0000000 --- a/code/network-generator/network_generator.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2023 highstreet technologies GmbH -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#!/usr/bin/python - -""" -Module as entry point to generate an ietf topology json -""" -import os -import sys - -from view.network_viewer import NetworkViewer -from controller.network_generator import NetworkGenerator -from controller.parameter_validator import ParameterValidator - -validator: ParameterValidator = ParameterValidator(sys.argv) - -if validator.is_valid(): - configuration = validator.configuration() - generator = NetworkGenerator(configuration['network']) - network = generator.generate() - viewer = NetworkViewer(network) - - output_folder:str = configuration['output-folder'] - # If folder doesn't exist, then create it. - if not os.path.isdir(output_folder): - os.makedirs(output_folder) - - name: str = configuration['network']['name'] - - # topology json - if configuration['generation-tasks']['topology'] is True: - filename: str = output_folder + "/" + name + "-operational.json" - viewer.json().save(filename) - - # svg xml - if configuration['generation-tasks']['svg'] is True: - filename: str = output_folder + "/" + name + ".svg" - viewer.svg(filename) - - # kml xml - if configuration['generation-tasks']['kml'] is True: - filename: str = output_folder + "/" + name + ".kml" - viewer.kml(filename) - -else: - print(validator.error_message())