-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1650 from adenishchenko/migration_mainnet
Add script for remove ledger
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |