Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Auto-Delete Bootstrap File #986

Merged
merged 2 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ All notable changes to this project are documented in this file.
- Fix ``BigInteger`` division for negative dividend values
- Add functionality for RawTransaction class
- Fix ``GetPriceForSysCall()`` for a ``Neo.Contract.Create`` syscall with invalid contract properties
- Updated ``np-bootstrap`` to delete the downloaded bootstrap file by default `#986 <https://github.com/CityOfZion/neo-python/pull/986>`_


[0.8.4] 2019-02-14
Expand Down
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ np-bootstrap Usage
-c CONFIG, --config CONFIG
Use a specific config file
-n, --notifications Bootstrap notification database
-s, --skipconfirm Bypass warning about overwritting data in Chains/SC234
-s, --skipconfirm Bypass warning about overwriting data in Chains
-k, --keep-bootstrap-file
Keep the downloaded bootstrap file
--datadir DATADIR Absolute path to use for database directories

Bootrapping Testnet
Expand Down
13 changes: 9 additions & 4 deletions neo/Prompt/Commands/Bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os


def BootstrapBlockchainFile(target_dir, download_location, bootstrap_name, require_confirm=True):
def BootstrapBlockchainFile(target_dir, download_location, bootstrap_name, require_confirm=True, delete_bootstrap_file=True):
if download_location is None:
print("no bootstrap location file specified. Please update your configuration file.")
sys.exit(0)
Expand All @@ -20,20 +20,21 @@ def BootstrapBlockchainFile(target_dir, download_location, bootstrap_name, requi
except KeyboardInterrupt:
confirm = False
if confirm == 'confirm':
return do_bootstrap(download_location, bootstrap_name, target_dir)
return do_bootstrap(download_location, bootstrap_name, target_dir, delete_bootstrap_file=delete_bootstrap_file)
else:

return do_bootstrap(download_location,
bootstrap_name,
target_dir,
tmp_file_name=os.path.join(settings.DATA_DIR_PATH, 'btest.tar.gz'),
tmp_chain_name='btestchain')
tmp_chain_name='btestchain',
delete_bootstrap_file=delete_bootstrap_file)

print("bootstrap cancelled")
sys.exit(0)


def do_bootstrap(download_location, bootstrap_name, destination_dir, tmp_file_name=None, tmp_chain_name='tmpchain'):
def do_bootstrap(download_location, bootstrap_name, destination_dir, tmp_file_name=None, tmp_chain_name='tmpchain', delete_bootstrap_file=True):
if tmp_file_name is None:
tmp_file_name = os.path.join(settings.DATA_DIR_PATH, 'bootstrap.tar.gz')

Expand Down Expand Up @@ -100,6 +101,10 @@ def do_bootstrap(download_location, bootstrap_name, destination_dir, tmp_file_na
if os.path.exists(tmp_chain_name):
shutil.rmtree(tmp_chain_name)

if delete_bootstrap_file and os.path.exists(tmp_file_name):
print("removing temp bootstrap file %s " % tmp_file_name)
os.remove(tmp_file_name)

if success:
print("Successfully downloaded bootstrap chain!")

Expand Down
12 changes: 10 additions & 2 deletions neo/bin/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def main():
help="Bootstrap notification database")

parser.add_argument("-s", "--skipconfirm", action="store_true", default=False,
help="Bypass warning about overwritting data in {}".format(settings.LEVELDB_PATH))
help="Bypass warning about overwriting data in {}".format(settings.LEVELDB_PATH))

parser.add_argument("-k", "--keep-bootstrap-file", action="store_true", default=False,
help="Keep the downloaded bootstrap file when finished")

# Where to store stuff
parser.add_argument("--datadir", action="store",
Expand All @@ -32,6 +35,11 @@ def main():
else:
require_confirm = True

if args.keep_bootstrap_file:
keep_bootstrap_file = True
else:
keep_bootstrap_file = False

# Setting the datadir must come before setting the network, else the wrong path is checked at net setup.
if args.datadir:
settings.set_data_dir(args.datadir)
Expand All @@ -48,7 +56,7 @@ def main():
bootstrap_name += "_notif"
destination_path = settings.notification_leveldb_path

BootstrapBlockchainFile(destination_path, settings.BOOTSTRAP_LOCATIONS, bootstrap_name, require_confirm)
BootstrapBlockchainFile(destination_path, settings.BOOTSTRAP_LOCATIONS, bootstrap_name, require_confirm, not keep_bootstrap_file)


if __name__ == "__main__":
Expand Down