Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for remove ledger #1650

Merged
merged 7 commits into from
Feb 16, 2021
Merged
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
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)