added sneakernet auto importing
exportblocks now takes argument
This commit is contained in:
parent
160469f50f
commit
1bd0aa9419
17 changed files with 131 additions and 91 deletions
|
@ -23,6 +23,7 @@ from onionrutils import blockmetadata
|
|||
from coredb import blockmetadb
|
||||
import filepaths
|
||||
import onionrcrypto as crypto
|
||||
from etc.onionrvalues import BLOCK_EXPORT_FILE_EXT
|
||||
def import_new_blocks(scanDir=''):
|
||||
'''
|
||||
This function is intended to scan for new blocks ON THE DISK and import them
|
||||
|
@ -33,19 +34,19 @@ def import_new_blocks(scanDir=''):
|
|||
scanDir = filepaths.block_data_location
|
||||
if not scanDir.endswith('/'):
|
||||
scanDir += '/'
|
||||
for block in glob.glob(scanDir + "*.dat"):
|
||||
if block.replace(scanDir, '').replace('.dat', '') not in blockList:
|
||||
for block in glob.glob(scanDir + "*%s" % (BLOCK_EXPORT_FILE_EXT,)):
|
||||
if block.replace(scanDir, '').replace(BLOCK_EXPORT_FILE_EXT, '') not in blockList:
|
||||
exist = True
|
||||
logger.info('Found new block on dist %s' % block, terminal=True)
|
||||
with open(block, 'rb') as newBlock:
|
||||
block = block.replace(scanDir, '').replace('.dat', '')
|
||||
if crypto.hashers.sha3_hash(newBlock.read()) == block.replace('.dat', ''):
|
||||
blockmetadb.add_to_block_DB(block.replace('.dat', ''), dataSaved=True)
|
||||
logger.info('Imported block %s.' % block, terminal=True)
|
||||
block = block.replace(scanDir, '').replace(BLOCK_EXPORT_FILE_EXT, '')
|
||||
if crypto.hashers.sha3_hash(newBlock.read()) == block.replace(BLOCK_EXPORT_FILE_EXT, ''):
|
||||
blockmetadb.add_to_block_DB(block.replace(BLOCK_EXPORT_FILE_EXT, ''), dataSaved=True)
|
||||
logger.info('Imported block %s' % block, terminal=True)
|
||||
blockmetadata.process_block_metadata(block)
|
||||
else:
|
||||
logger.warn('Failed to verify hash for %s' % block, terminal=True)
|
||||
if not exist:
|
||||
logger.info('No blocks found to import', terminal=True)
|
||||
|
||||
import_new_blocks.onionr_help = f"Scans the Onionr data directory under {filepaths.block_data_location} for new block files (.dat, .db not supported) to import"
|
||||
import_new_blocks.onionr_help = f"Scans the Onionr data directory under {filepaths.block_data_location} for new block files (.db not supported) to import"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue