-
Notifications
You must be signed in to change notification settings - Fork 2
/
insert_into_config.py
39 lines (31 loc) · 1.07 KB
/
insert_into_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import json
import platform
import sys
json_file_name = "config.json"
def insert_for_test_backup():
list = []
list.append("/unitTestFiles/jewel")
list.append("/unitTestFiles/jewel2")
list.append("/unitTestFiles/jewel3")
table_name = 'jewel_sources'
key = "testCases"
data = list
write_json(table_name, key, data)
table_name = 'destination'
data2 = "unitTestFiles/backupLocation"
write_json(table_name, key, data2)
table_name = 'restore_destination'
data3 = "unitTestFiles/restoreLocation"
write_json(table_name, key, data3)
# print("done with insert_into_config.py")
def write_json(table_name, key, value, filename=json_file_name):
with open(filename, 'r+') as file:
# First we load existing data into a dict.
file_data = json.load(file)
# Join new_data with file_data inside emp_details
file_data[table_name][key] = value
# Sets file's current position at offset.
file.seek(0)
# convert back to json.
json.dump(file_data, file, indent=4)
file.truncate()