mirror of
				https://github.com/Telecominfraproject/oopt-gnpy.git
				synced 2025-10-30 17:47:50 +00:00 
			
		
		
		
	 a0758d0da5
			
		
	
	a0758d0da5
	
	
	
		
			
			Co-authored-by: Rodrigo Sasse David <rodrigo.sassedavid@orange.com> Signed-off-by: EstherLerouzic <esther.lerouzic@orange.com> Change-Id: Ib961c5c0e203f2225a0f1e2e7a091485567189c3
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| #!/usr/bin/env python3
 | |
| # -*- coding: utf-8 -*-
 | |
| 
 | |
| # SPDX-License-Identifier: BSD-3-Clause
 | |
| # Reads JSON path result file and writes results to a CSV file
 | |
| # Copyright (C) 2025 Telecom Infra Project and GNPy contributors
 | |
| # see AUTHORS.rst for a list of contributors
 | |
| 
 | |
| """
 | |
| 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='Converting JSON path results into a CSV')
 | |
| parser.add_argument('filename', type=Path)
 | |
| parser.add_argument('output_filename', 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)
 |