go.ligato.io/vpp-agent/v3@v3.5.0/tests/robot/libraries/basic_operations.py (about) 1 import json 2 import os 3 4 # used for sorting elements in json only 5 def sort(obj): 6 if isinstance(obj, dict): 7 return {k: sort(v) for k, v in obj.items()} 8 if isinstance(obj, list): 9 return sorted(sort(x) for x in obj) 10 else: 11 return obj 12 13 # input - json 14 # output - pretty printed json with sorted elements 15 def ordered_json(data): 16 if data=="": 17 return "" 18 # obj=json.loads(data.replace('\r', '\\r').replace('\n', '\\n').replace('\t', '\\t')) 19 obj=json.loads(data) 20 return json.dumps(sort(obj), sort_keys=True, indent=4, separators=(',', ': ')) 21 22 # input - path to file 23 # output - True if file exists, else False 24 def file_exists(path): 25 if os.path.isfile(path): 26 exists = True 27 else: 28 exists = False 29 return exists 30 31 def replace_rn_n(mytext): 32 if mytext=="": 33 return "" 34 mytext=mytext.replace("\r\n", "\n") 35 return mytext