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
|
@ -37,6 +37,7 @@ from .killdaemon import kill_daemon # noqa
|
|||
from utils.boxprint import bordered
|
||||
from lan import LANManager
|
||||
from lan.server import LANServer
|
||||
from sneakernet import sneakernet_import_thread
|
||||
"""
|
||||
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
|
||||
|
@ -169,6 +170,8 @@ def daemon():
|
|||
Thread(target=LANServer(shared_state).start_server,
|
||||
daemon=True).start()
|
||||
LANManager(shared_state).start()
|
||||
if config.get('transports.sneakernet', True):
|
||||
Thread(target=sneakernet_import_thread, daemon=True).start()
|
||||
communicator.startCommunicator(shared_state)
|
||||
|
||||
clean_ephemeral_services()
|
||||
|
|
|
@ -8,6 +8,7 @@ import logger
|
|||
import onionrstorage
|
||||
from utils import createdirs
|
||||
from onionrutils import stringvalidators
|
||||
from etc.onionrvalues import BLOCK_EXPORT_FILE_EXT
|
||||
import filepaths
|
||||
|
||||
import os
|
||||
|
@ -31,23 +32,26 @@ from coredb import blockmetadb
|
|||
def _do_export(b_hash):
|
||||
createdirs.create_dirs()
|
||||
data = onionrstorage.getData(b_hash)
|
||||
with open('%s/%s.dat' % (filepaths.export_location,
|
||||
b_hash), 'wb') as export:
|
||||
with open('%s/%s%s' % (filepaths.export_location,
|
||||
b_hash, BLOCK_EXPORT_FILE_EXT), 'wb') as export:
|
||||
export.write(data)
|
||||
logger.info('Block exported as file', terminal=True)
|
||||
|
||||
|
||||
def export_block():
|
||||
def export_block(*args):
|
||||
"""Export block based on hash from stdin or argv."""
|
||||
try:
|
||||
if not stringvalidators.validate_hash(sys.argv[2]):
|
||||
raise ValueError
|
||||
except (IndexError, ValueError):
|
||||
logger.error('No valid block hash specified.', terminal=True)
|
||||
sys.exit(1)
|
||||
if args:
|
||||
b_hash = args[0]
|
||||
else:
|
||||
b_hash = sys.argv[2]
|
||||
_do_export(b_hash)
|
||||
try:
|
||||
if not stringvalidators.validate_hash(sys.argv[2]):
|
||||
raise ValueError
|
||||
except (IndexError, ValueError):
|
||||
logger.error('No valid block hash specified.', terminal=True)
|
||||
sys.exit(1)
|
||||
else:
|
||||
b_hash = sys.argv[2]
|
||||
_do_export(b_hash)
|
||||
|
||||
|
||||
export_block.onionr_help = "<block hash>: Export block to " # type: ignore
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue