use data based importer in importnewblocks and fixed file exists error in createdirs

This commit is contained in:
Kevin Froman 2019-11-16 11:29:18 -06:00
parent b4225d3750
commit d27ebd7f19
2 changed files with 9 additions and 4 deletions

View File

@ -21,6 +21,7 @@ import glob
import logger import logger
from onionrutils import blockmetadata from onionrutils import blockmetadata
from coredb import blockmetadb from coredb import blockmetadb
from onionrblocks import blockimporter
import filepaths import filepaths
import onionrcrypto as crypto import onionrcrypto as crypto
def import_new_blocks(scanDir=''): def import_new_blocks(scanDir=''):
@ -40,9 +41,10 @@ def import_new_blocks(scanDir=''):
with open(block, 'rb') as newBlock: with open(block, 'rb') as newBlock:
block = block.replace(scanDir, '').replace('.dat', '') block = block.replace(scanDir, '').replace('.dat', '')
if crypto.hashers.sha3_hash(newBlock.read()) == block.replace('.dat', ''): if crypto.hashers.sha3_hash(newBlock.read()) == block.replace('.dat', ''):
blockmetadb.add_to_block_DB(block.replace('.dat', ''), dataSaved=True) if blockimporter.importBlockFromData(newBlock.read()):
logger.info('Imported block %s.' % block, terminal=True) logger.info('Imported block %s.' % block, terminal=True)
blockmetadata.process_block_metadata(block) else:
logger.warn('Unable to import block %s.' % block, terminal=True)
else: else:
logger.warn('Failed to verify hash for %s' % block, terminal=True) logger.warn('Failed to verify hash for %s' % block, terminal=True)
if not exist: if not exist:

View File

@ -29,7 +29,10 @@ def create_dirs():
gen_dirs = [home, filepaths.block_data_location, filepaths.contacts_location, filepaths.export_location] gen_dirs = [home, filepaths.block_data_location, filepaths.contacts_location, filepaths.export_location]
for path in gen_dirs: for path in gen_dirs:
if not os.path.exists(path): if not os.path.exists(path):
os.mkdir(path) try:
os.mkdir(path)
except FileExistsError:
pass
for db in dbcreator.create_funcs: for db in dbcreator.create_funcs:
try: try: