Merge remote-tracking branch 'upstream/develop' into develop

This commit is contained in:
ojnas
2018-10-30 09:37:27 +01:00
12 changed files with 26 additions and 28 deletions

View File

@@ -25,7 +25,7 @@ if __name__ == '__main__':
basicConfig(level={2: DEBUG, 1: INFO, 0: CRITICAL}.get(args.verbose, CRITICAL))
logger.info(f'Converting Service sheet {args.workbook!r} into gnpy JSON format')
if args.output is None:
data = convert_service_sheet(args.workbook,'eqpt_config.json')
print(dumps(data, indent=2))
data = convert_service_sheet(args.workbook, 'eqpt_config.json')
print(dumps(data, indent=2, ensure_ascii=False))
else:
data = convert_service_sheet(args.workbook,'eqpt_config.json',args.output)

View File

@@ -70,7 +70,7 @@ def read_excel(input_filename):
def create_eqt_template(links,nodes, links_by_src , links_by_dest, input_filename):
output_filename = f'{input_filename[:-4]}_eqpt_sheet.txt'
with open(output_filename,'w') as my_file :
with open(output_filename, 'w', encoding='utf-8') as my_file:
# print header similar to excel
my_file.write('OPTIONAL\n\n\n\
\t\tNode a egress amp (from a to z)\t\t\t\t\tNode a ingress amp (from z to a) \

View File

@@ -74,7 +74,7 @@ def load_requests(filename,eqpt_filename):
logger.info('Automatically converting requests from XLS to JSON')
json_data = convert_service_sheet(filename,eqpt_filename)
else:
with open(filename) as f:
with open(filename, encoding='utf-8') as f:
json_data = loads(f.read())
return json_data
@@ -159,7 +159,7 @@ if __name__ == '__main__':
for p in test:
result.append(Result_element(pths[test.index(p)],p))
with open(args.output, 'w') as f:
f.write(dumps(path_result_json(result), indent=2))
f.write(dumps(path_result_json(result), indent=2, ensure_ascii=False))
fnamecsv = next(s for s in args.output.split('.')) + '.csv'
with open(fnamecsv,"w") as fcsv :
jsontocsv(path_result_json(result),equipment,fcsv)

View File

@@ -26,8 +26,8 @@ parser.add_argument('eqpt_filename', nargs='?', type = Path, default=Path(__file
if __name__ == '__main__':
args = parser.parse_args()
with open(args.output_filename,"w") as file :
with open(args.filename) as f:
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)

View File

@@ -214,14 +214,12 @@ def convert_file(input_filename, filter_region=[]):
for x in nodes_by_city.values() if x.node_type.lower()=='roadm'])))
}
#print(dumps(data, indent=2))
# output_json_file_name = input_filename.split(".")[0]+".json"
suffix_filename = str(input_filename.suffixes[0])
full_input_filename = str(input_filename)
split_filename = [full_input_filename[0:len(full_input_filename)-len(suffix_filename)] , suffix_filename[1:]]
output_json_file_name = split_filename[0]+'.json'
with open(output_json_file_name,'w') as edfa_json_file:
edfa_json_file.write(dumps(data, indent=2))
with open(output_json_file_name, 'w', encoding='utf-8') as edfa_json_file:
edfa_json_file.write(dumps(data, indent=2, ensure_ascii=False))
return output_json_file_name
def parse_excel(input_filename):

View File

@@ -43,13 +43,13 @@ class Amp(AmpBase):
@classmethod
def from_advanced_json(cls, filename, **kwargs):
with open(filename) as f:
with open(filename, encoding='utf-8') as f:
json_data = load(f)
return cls(**{**kwargs, **json_data, 'type_def':None, 'nf_model':None})
@classmethod
def from_default_json(cls, filename, **kwargs):
with open(filename) as f:
with open(filename, encoding='utf-8') as f:
json_data = load(f)
type_variety = kwargs['type_variety']
type_def = kwargs.get('type_def', 'variable_gain') #default compatibility with older json eqpt files

View File

@@ -181,7 +181,7 @@ def convert_service_sheet(input_filename, eqpt_filename, output_filename='', fil
if n.json[1] is not None]
}
with open(output_filename, 'w') as f:
f.write(dumps(data, indent=2))
f.write(dumps(data, indent=2, ensure_ascii=False))
return data
# to be used from dutc

View File

@@ -18,14 +18,14 @@ from scipy import constants
def load_json(filename):
with open(filename, 'r') as f:
with open(filename, 'r', encoding='utf-8') as f:
data = json.load(f)
return data
def save_json(obj, filename):
with open(filename, 'w') as f:
json.dump(obj, f, indent=2)
with open(filename, 'w', encoding='utf-8') as f:
json.dump(obj, f, indent=2, ensure_ascii=False)
def write_csv(obj, filename):
"""
@@ -55,7 +55,7 @@ def write_csv(obj, filename):
result_category 2
...
"""
with open(filename, 'w') as f:
with open(filename, 'w', encoding='utf-8') as f:
w = writer(f)
for data_key, data_list in obj.items():
#main header

View File

@@ -105,16 +105,16 @@ def encode_sets(obj):
if __name__ == '__main__':
args = parser.parse_args()
with open(args.expected_output) as f:
with open(args.expected_output, encoding='utf-8') as f:
expected = load(f)
with open(args.actual_output) as f:
with open(args.actual_output, encoding='utf-8') as f:
actual = load(f)
result = COMPARISONS[args.comparison](expected, actual)
if args.output:
with open(args.output, 'w') as f:
dump(result, f, default=encode_sets, indent=2)
with open(args.output, 'w', encoding='utf-8') as f:
dump(result, f, default=encode_sets, indent=2, ensure_ascii=False)
else:
print(str(result))

View File

@@ -5,7 +5,7 @@
from gnpy.core.elements import Edfa
from numpy import zeros, array
from json import load, dumps
from json import load
from gnpy.core.elements import Transceiver, Fiber, Edfa
from gnpy.core.utils import lin2db, db2lin
from gnpy.core.info import create_input_spectral_information, SpectralInformation, Channel, Power, Pref

View File

@@ -37,11 +37,11 @@ def test_excel_json_generation(xls_input, expected_json_output):
convert_file(xls_input)
actual_json_output = xls_input.with_suffix('.json')
with open(actual_json_output) as f:
with open(actual_json_output, encoding='utf-8') as f:
actual = load(f)
unlink(actual_json_output)
with open(expected_json_output) as f:
with open(expected_json_output, encoding='utf-8') as f:
expected = load(f)
results = compare_networks(expected, actual)
@@ -65,11 +65,11 @@ def test_excel_service_json_generation(xls_input, expected_json_output):
convert_service_sheet(xls_input, eqpt_filename)
actual_json_output = f'{str(xls_input)[:-4]}_services.json'
with open(actual_json_output) as f:
with open(actual_json_output, encoding='utf-8') as f:
actual = load(f)
unlink(actual_json_output)
with open(expected_json_output) as f:
with open(expected_json_output, encoding='utf-8') as f:
expected = load(f)
results = compare_services(expected, actual)

View File

@@ -5,7 +5,7 @@
from gnpy.core.elements import Edfa
import numpy as np
from json import load, dumps
from json import load
import pytest
from gnpy.core.elements import Transceiver, Fiber, Edfa
from gnpy.core.utils import lin2db, db2lin