-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateFile.py
More file actions
37 lines (27 loc) · 946 Bytes
/
GenerateFile.py
File metadata and controls
37 lines (27 loc) · 946 Bytes
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
import errno
import os
import json_handling
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
class SettingFile:
def __init__(self, sample_values: dict):
self.data = sample_values.copy()
def clone(self):
out = SettingFile(self.data)
return out
def write_to_file(self, directory, name):
if directory[-1] != '/':
directory += '/'
final_address = f'{directory}{name}'
mkdir_p(os.path.dirname(final_address))
json_handling.unflatten_and_write_setting(final_address, self.data)
if __name__ == '__main__':
test = SettingFile(
json_handling.read_and_flatten_setting('/home/arad/robocup/cyrus/team/src/data/settings/hel.json'))
test.write_to_file('./', 'example.json')