-
Notifications
You must be signed in to change notification settings - Fork 1
/
reset.py
42 lines (33 loc) · 1.19 KB
/
reset.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
40
41
42
#!/usr/bin/python
"""
a reset script to attempt recovery from file-related issues
"""
import json
import sys
import os
if __name__ == '__main__':
try:
parent_path = 'src/RaBit/app_data'
# delete completed torrents db
if os.path.exists(path := os.path.join(parent_path, 'completed_torrents.db')):
os.remove(path)
# delete banned peers db
# if os.path.exists(path := os.path.join(parent_path, 'banned_peers.db')):
# os.remove(path)
# remove ongoing torrents
with open(os.path.join(parent_path, 'ongoing_torrents.json'), 'r+') as json_file:
json_file.seek(0)
json_file.truncate()
json.dump([], json_file)
# reset config
with open(os.path.join(parent_path, 'default_config.json'), 'r') as json_file:
default = json.load(json_file)
with open(os.path.join(parent_path, 'config.json'), 'r+') as json_file:
json_file.seek(0)
json_file.truncate()
json.dump(default, json_file)
print('Reset was successful!')
except Exception as e:
print('Reset was unsuccessful due to ', e)
finally:
sys.exit()