2019-06-01 16:54:36 +00:00
|
|
|
'''
|
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
This file handles the command for exporting blocks to disk
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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-06-20 00:59:05 +00:00
|
|
|
import sys, os
|
2019-06-01 16:54:36 +00:00
|
|
|
import logger, onionrstorage
|
2019-06-25 23:07:35 +00:00
|
|
|
from onionrutils import stringvalidators
|
2019-06-01 16:54:36 +00:00
|
|
|
def doExport(o_inst, bHash):
|
|
|
|
exportDir = o_inst.dataDir + 'block-export/'
|
|
|
|
if not os.path.exists(exportDir):
|
|
|
|
if os.path.exists(o_inst.dataDir):
|
|
|
|
os.mkdir(exportDir)
|
|
|
|
else:
|
2019-06-20 00:59:05 +00:00
|
|
|
logger.error('Onionr Not initialized', terminal=True)
|
2019-06-01 16:54:36 +00:00
|
|
|
data = onionrstorage.getData(o_inst.onionrCore, bHash)
|
|
|
|
with open('%s/%s.dat' % (exportDir, bHash), 'wb') as exportFile:
|
|
|
|
exportFile.write(data)
|
2019-06-20 00:59:05 +00:00
|
|
|
logger.info('Block exported as file', terminal=True)
|
2019-06-01 16:54:36 +00:00
|
|
|
|
|
|
|
def export_block(o_inst):
|
|
|
|
exportDir = o_inst.dataDir + 'block-export/'
|
|
|
|
try:
|
2019-06-25 23:07:35 +00:00
|
|
|
assert stringvalidators.validate_hash(sys.argv[2])
|
2019-06-01 16:54:36 +00:00
|
|
|
except (IndexError, AssertionError):
|
2019-06-20 00:59:05 +00:00
|
|
|
logger.error('No valid block hash specified.', terminal=True)
|
2019-06-01 16:54:36 +00:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
bHash = sys.argv[2]
|
2019-06-20 00:59:05 +00:00
|
|
|
doExport(o_inst, bHash)
|