-
-
Save lovesh/f9e547dd1502c401e87428919cb0fe5b to your computer and use it in GitHub Desktop.
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
import shutil | |
import os | |
from importlib import import_module | |
from importlib.util import module_from_spec, spec_from_file_location | |
import pyorient | |
configFileName = 'sovrin_config.py' | |
def getOrientDBDetails(): | |
homeDir = os.path.expanduser("~") | |
configDir = os.path.join(homeDir, ".sovrin") | |
configPath = os.path.join(configDir, configFileName) | |
if os.path.exists(configPath): | |
spec = spec_from_file_location(configFileName, configPath) | |
spec = spec_from_file_location(configFileName, configPath) | |
config = module_from_spec(spec) | |
spec.loader.exec_module(config) | |
r = config.OrientDB | |
return r['user'], r['password'] | |
else: | |
raise FileNotFoundError("No file found at location {}". | |
format(configPath)) | |
client = pyorient.OrientDB("localhost", 2424) | |
user, password = getOrientDBDetails() | |
session_id = client.connect(user, password) | |
def dropdbs(): | |
i = 0 | |
names = [n for n in client.db_list().oRecordData['databases'].keys()] | |
for nm in names: | |
try: | |
client.db_drop(nm) | |
i += 1 | |
except: | |
continue | |
return i | |
def drop(): | |
paths = [(".sovrin", "data"), (".sovrin", "keyrings")] | |
for path in paths: | |
try: | |
shutil.rmtree(os.path.join(os.path.expanduser("~"), *path)) | |
except Exception as e: | |
print("directory not found {}".format(e)) | |
return dropdbs() | |
drop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment