forked from PortSwigger/python-scripter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptstore.py
26 lines (21 loc) · 882 Bytes
/
scriptstore.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
import json
from models import ScriptCollection
class ScriptCollectionStore(object):
_SAVE_NAME = 'script_store'
def __init__(self, callbacks, helpers, extender):
self.callbacks = callbacks
self.helpers = helpers
self.extender = extender
def restore(self, scripts):
json_string = self.callbacks.loadExtensionSetting(ScriptCollectionStore._SAVE_NAME)
if json_string:
print('Restored scripts:')
print(json_string)
loaded = json.loads(json_string)
scripts.from_dict(loaded, self.callbacks, self.helpers, self.extender)
def save(self, scripts):
save = scripts.to_dict()
json_string = json.dumps(save, indent=2)
print('Saving scripts:')
print(json_string)
self.callbacks.saveExtensionSetting(ScriptCollectionStore._SAVE_NAME, json_string)