mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-11-02 02:57:52 +00:00
distribute example data along GNPy
I would like to create a package for distribution to PIP, and this seems like the path of least resistance. This is, apparently, the way for shippign arbitrary data with Python [1]. I've at least tried to make it user-firendly via adding a simple utility which just prints out whatever that data path is. [1] https://python-packaging.readthedocs.io/en/latest/non-code-files.html Change-Id: I220ecad84b1d57d01e3f98f15befc700bd97c0b8
This commit is contained in:
35
gnpy/example-data/write_path_jsontocsv.py
Normal file
35
gnpy/example-data/write_path_jsontocsv.py
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
write_path_jsontocsv.py
|
||||
========================
|
||||
|
||||
Reads JSON path result file in accordance with the Yang model for requesting
|
||||
path computation and writes results to a CSV file.
|
||||
|
||||
See: draft-ietf-teas-yang-path-computation-01.txt
|
||||
"""
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from pathlib import Path
|
||||
from json import loads
|
||||
from gnpy.tools.json_io import load_equipment
|
||||
from gnpy.topology.request import jsontocsv
|
||||
|
||||
|
||||
parser = ArgumentParser(description='A function that writes json path results in an excel sheet.')
|
||||
parser.add_argument('filename', nargs='?', type=Path)
|
||||
parser.add_argument('output_filename', nargs='?', type=Path)
|
||||
parser.add_argument('eqpt_filename', nargs='?', type=Path, default=Path(__file__).parent / 'eqpt_config.json')
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parser.parse_args()
|
||||
|
||||
with open(args.output_filename, 'w', encoding='utf-8') as file:
|
||||
with open(args.filename, encoding='utf-8') as f:
|
||||
print(f'Reading {args.filename}')
|
||||
json_data = loads(f.read())
|
||||
equipment = load_equipment(args.eqpt_filename)
|
||||
print(f'Writing in {args.output_filename}')
|
||||
jsontocsv(json_data, equipment, file)
|
||||
Reference in New Issue
Block a user