Skip to content

Instantly share code, notes, and snippets.

@lovesh
Last active March 29, 2017 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lovesh/f9e547dd1502c401e87428919cb0fe5b to your computer and use it in GitHub Desktop.
Save lovesh/f9e547dd1502c401e87428919cb0fe5b to your computer and use it in GitHub Desktop.
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