Skip to content

Commit

Permalink
Merge pull request #1650 from adenishchenko/migration_mainnet
Browse files Browse the repository at this point in the history
Add script for remove ledger
  • Loading branch information
Toktar authored Feb 16, 2021
2 parents 4d1ab46 + 263c38c commit 7ec31dc
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions scripts/remove_ledger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3

from pathlib import Path
import shutil
from sys import argv
from indy_common.config_util import getConfig
from indy_common.config_helper import ConfigHelper


def warn(ledger_name, directories_path):
print('The following directories will be deleted:')

for path in directories_path:
print(str(path))

print('Deleting a ledger is an irrevocable operation.\nProceed only if you know the consequences.')
answer = input('Do you want to delete ledger ' + ledger_name + '?\n Press [y/N]')

if answer.lower() == 'yes' or answer.lower() == 'y':
return True

return False


def remove(ledger_name):
exceptions = ["domain", "config", "pool", "audit"]
if ledger_name not in exceptions:
directories_path = []

for path in Path(config_helper.ledger_data_dir).rglob(ledger_name + "_*"):
directories_path.append(path)

if not len(directories_path):
print('Ledger doesn`t exist: ' + ledger_name)

elif warn(ledger_name, directories_path):
for path in directories_path:
shutil.rmtree(str(path))
print('Ledger removed successfully!')

else:
print('Can`t delete built in ledger: ' + ledger_name)


if __name__ == '__main__':
config = getConfig()
config_helper = ConfigHelper(config)
script, ledger_name = argv
remove(ledger_name)

0 comments on commit 7ec31dc

Please sign in to comment.