refactor local installer
[doctor.git] / tests / utils.py
1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 import json
10 import os
11
12
13 def load_json_file(full_path):
14     """Loads JSON from file
15     :param target_filename:
16     :return:
17     """
18     if not os.path.isfile(full_path):
19         raise Exception('File(%s) does not exist' % full_path)
20
21     with open(full_path, 'r') as file:
22         return json.load(file)
23
24
25 def write_json_file(full_path, data):
26     """write JSON from file
27     :param target_filename:
28     :return:
29     """
30
31     with open(full_path, 'w+') as file:
32         file.write(json.dumps(data))
33