2019-12-19 10:34:19 +00:00
|
|
|
"""Onionr - Private P2P Communication.
|
2019-09-05 09:40:31 +00:00
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
Command to soft-reset Onionr (deletes blocks)
|
2019-09-05 09:40:31 +00:00
|
|
|
"""
|
2019-12-19 10:34:19 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
from onionrutils import localcommand
|
|
|
|
from coredb import dbfiles
|
|
|
|
import filepaths
|
|
|
|
from onionrplugins import onionrevents
|
|
|
|
import logger
|
2019-09-05 09:40:31 +00:00
|
|
|
"""
|
2022-03-18 00:56:31 +00:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2019-09-05 09:40:31 +00:00
|
|
|
|
2022-03-18 00:56:31 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2019-09-05 09:40:31 +00:00
|
|
|
|
2022-03-18 00:56:31 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-09-05 09:40:31 +00:00
|
|
|
"""
|
|
|
|
|
2019-09-20 14:47:14 +00:00
|
|
|
|
|
|
|
def _ignore_not_found_delete(path):
|
|
|
|
try:
|
|
|
|
os.remove(path)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
|
2019-09-05 09:40:31 +00:00
|
|
|
def soft_reset():
|
2019-12-19 10:34:19 +00:00
|
|
|
"""Command to soft reset Onionr home data.
|
|
|
|
|
|
|
|
Onionr must not be running
|
|
|
|
"""
|
2019-09-05 09:40:31 +00:00
|
|
|
if localcommand.local_command('/ping') == 'pong!':
|
2019-12-19 10:34:19 +00:00
|
|
|
logger.warn('Cannot soft reset while Onionr is running',
|
|
|
|
terminal=True)
|
2019-09-05 09:40:31 +00:00
|
|
|
return
|
|
|
|
path = filepaths.block_data_location
|
|
|
|
shutil.rmtree(path)
|
2019-09-20 14:47:14 +00:00
|
|
|
_ignore_not_found_delete(dbfiles.block_meta_db)
|
|
|
|
_ignore_not_found_delete(filepaths.upload_list)
|
2020-01-20 03:05:55 +00:00
|
|
|
_ignore_not_found_delete(filepaths.usage_file)
|
2019-09-20 14:47:14 +00:00
|
|
|
onionrevents.event('softreset')
|
2019-09-05 09:40:31 +00:00
|
|
|
logger.info("Soft reset Onionr", terminal=True)
|
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
|
|
|
|
soft_reset.onionr_help = "Deletes Onionr blocks and their " # type: ignore
|
|
|
|
soft_reset.onionr_help += "associated metadata, except for " # type: ignore
|
|
|
|
soft_reset.onionr_help += "any exported block files. Does NOT " # type: ignore
|
|
|
|
soft_reset.onionr_help += "delete data on " # type: ignore
|
|
|
|
soft_reset.onionr_help += "other nodes in the network." # type: ignore
|