fix filenotfound error in softreset, added softreset event

master
Kevin Froman 2019-09-20 09:47:14 -05:00
parent 0405eda30e
commit fbe1766aea
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
2 changed files with 17 additions and 9 deletions

View File

@ -23,15 +23,24 @@ import shutil
from onionrutils import localcommand
from coredb import dbfiles
import filepaths
import onionrevents
import logger
def _ignore_not_found_delete(path):
try:
os.remove(path)
except FileNotFoundError:
pass
def soft_reset():
if localcommand.local_command('/ping') == 'pong!':
logger.warn('Cannot soft reset while Onionr is running', terminal=True)
return
path = filepaths.block_data_location
shutil.rmtree(path)
os.remove(dbfiles.block_meta_db)
os.remove(filepaths.upload_list)
_ignore_not_found_delete(dbfiles.block_meta_db)
_ignore_not_found_delete(filepaths.upload_list)
onionrevents.event('softreset')
logger.info("Soft reset Onionr", terminal=True)
soft_reset.onionr_help = "Deletes Onionr blocks and their associated metadata, except for any exported block files."

View File

@ -99,13 +99,12 @@ class OnionrFlow:
def on_flow_cmd(api, data=None):
OnionrFlow().start()
def on_init(api, data = None):
'''
This event is called after Onionr is initialized, but before the command
inputted is executed. Could be called when daemon is starting or when
just the client is running.
'''
return
def on_softreset(api, data=None):
try:
os.remove(identifyhome.identify_home() + '/board-index.cache.json')
logger.info('Cleared Circles board cache')
except FileNotFoundError:
pass
def on_processblocks(api, data=None):
metadata = data['block'].bmetadata # Get the block metadata