# Path: elevator/constants.py
# OS_ERROR = 5
# 
# DATABASE_ERROR = 6
# 
# Path: elevator/utils/patterns.py
# def enum(*sequential, **named):
#     enums = dict(zip(sequential, range(len(sequential))), **named)
#     return type('Enum', (), enums)
# 
# Path: elevator/helpers/internals.py
# def failure(err_code, err_msg):
#     """Returns a formatted error status and content"""
#     return (FAILURE_STATUS, [err_code, err_msg])
# 
# def success(content=None):
#     """Returns a formatted success status and content"""
#     return (SUCCESS_STATUS, content)


import os
import uuid
import logging
import plyvel
import ujson as json
from shutil import rmtree
from plyvel import CorruptionError
from .constants import OS_ERROR, DATABASE_ERROR
from .utils.patterns import enum
from .helpers.internals import failure, success
    def status(self, db_name):
        """Returns the mounted/unmounted database status"""

        db_uid = self.index['name_to_uid'][db_name] if db_name in self.index['name_to_uid'] else None
        return self[db_uid].status

    def mount(self, db_name):
        db_uid = self.index['name_to_uid'][db_name] if db_name in self.index['name_to_uid'] else None
        return self[db_uid].mount()

    def umount(self, db_name):
        db_uid = self.index['name_to_uid'][db_name] if db_name in self.index['name_to_uid'] else None
        return self[db_uid].umount()

    def add(self, db_name, db_options=None):
        """Adds a db to the DatabasesStore object, and sync it
        to the store file"""
        db_options = db_options or DatabaseOptions()
        db_name_is_path = db_name.startswith('.') or ('/' in db_name)
        is_abspath = lambda: not db_name.startswith('.') and ('/' in db_name)

        # Handle case when a db is a path
        if db_name_is_path:
            if not is_abspath():
                return failure(DATABASE_ERROR, "Canno't create database from relative path")
            try:
                new_db_path = db_name
                if not os.path.exists(new_db_path):
                    os.mkdir(new_db_path)
            except OSError as e:

# Path: elevator/constants.py
# OS_ERROR = 5
# 
# DATABASE_ERROR = 6
# 
# Path: elevator/utils/patterns.py
# def enum(*sequential, **named):
#     enums = dict(zip(sequential, range(len(sequential))), **named)
#     return type('Enum', (), enums)
# 
# Path: elevator/helpers/internals.py
# def failure(err_code, err_msg):
#     """Returns a formatted error status and content"""
#     return (FAILURE_STATUS, [err_code, err_msg])
# 
# def success(content=None):
#     """Returns a formatted success status and content"""
#     return (SUCCESS_STATUS, content)


# Path: elevator/db.py
import os
import uuid
import logging
import plyvel
import ujson as json
from shutil import rmtree
from plyvel import CorruptionError
from .constants import OS_ERROR, DATABASE_ERROR
from .utils.patterns import enum
from .helpers.internals import failure, success

    def status(self, db_name):
        """Returns the mounted/unmounted database status"""

        db_uid = self.index['name_to_uid'][db_name] if db_name in self.index['name_to_uid'] else None
        return self[db_uid].status

    def mount(self, db_name):
        db_uid = self.index['name_to_uid'][db_name] if db_name in self.index['name_to_uid'] else None
        return self[db_uid].mount()

    def umount(self, db_name):
        db_uid = self.index['name_to_uid'][db_name] if db_name in self.index['name_to_uid'] else None
        return self[db_uid].umount()

    def add(self, db_name, db_options=None):
        """Adds a db to the DatabasesStore object, and sync it
        to the store file"""
        db_options = db_options or DatabaseOptions()
        db_name_is_path = db_name.startswith('.') or ('/' in db_name)
        is_abspath = lambda: not db_name.startswith('.') and ('/' in db_name)

        # Handle case when a db is a path
        if db_name_is_path:
            if not is_abspath():
                return failure(DATABASE_ERROR, "Canno't create database from relative path")
            try:
                new_db_path = db_name
                if not os.path.exists(new_db_path):
                    os.mkdir(new_db_path)
            except OSError as e:

                return failure(OS_ERROR, e.strerror)