17 def _pskpath(project_path): |
17 def _pskpath(project_path): |
18 return os.path.join(project_path, 'psk') |
18 return os.path.join(project_path, 'psk') |
19 |
19 |
20 def _mgtpath(project_path): |
20 def _mgtpath(project_path): |
21 return os.path.join(_pskpath(project_path), 'management.json') |
21 return os.path.join(_pskpath(project_path), 'management.json') |
|
22 |
|
23 def _ensurePSKdir(project_path): |
|
24 pskpath = _pskpath(project_path) |
|
25 if not os.path.exists(pskpath): |
|
26 os.mkdir(pskpath) |
|
27 return pskpath |
22 |
28 |
23 def _default(ID): |
29 def _default(ID): |
24 return [ID, |
30 return [ID, |
25 '', # default description |
31 '', # default description |
26 None, # last known URI |
32 None, # last known URI |
60 def DeleteID(project_path, ID): |
66 def DeleteID(project_path, ID): |
61 secret_path = os.path.join(_pskpath(project_path), ID+'.secret') |
67 secret_path = os.path.join(_pskpath(project_path), ID+'.secret') |
62 os.remove(secret_path) |
68 os.remove(secret_path) |
63 |
69 |
64 def SaveData(project_path, data): |
70 def SaveData(project_path, data): |
65 pskpath = _pskpath(project_path) |
71 _ensurePSKdir(project_path) |
66 if not os.path.isdir(pskpath): |
|
67 os.mkdir(pskpath) |
|
68 with open(_mgtpath(project_path), 'w') as f: |
72 with open(_mgtpath(project_path), 'w') as f: |
69 f.write(json.dumps(data)) |
73 f.write(json.dumps(data)) |
70 |
74 |
71 |
|
72 def UpdateID(project_path, ID, secret, URI): |
75 def UpdateID(project_path, ID, secret, URI): |
73 pskpath = _pskpath(project_path) |
76 pskpath = _ensurePSKdir(project_path) |
74 if not os.path.exists(pskpath): |
77 if not os.path.exists(pskpath): |
75 os.mkdir(pskpath) |
78 os.mkdir(pskpath) |
76 |
79 |
77 secpath = os.path.join(pskpath, ID+'.secret') |
80 secpath = os.path.join(pskpath, ID+'.secret') |
78 with open(secpath, 'w') as f: |
81 with open(secpath, 'w') as f: |