示例#1
0
 def setUp(self):
     util = Utility()
     self.conf = util.CONFIG
     self.connections = util.get_all_plugins(
         self.conf.PATH_CONNECTION_MANAGERS, {'SQLITE': SQLite})
     self.browsers = util.get_all_plugins(self.conf.PATH_BROWSER,
                                          {'SQLITE': SQLite})
示例#2
0
def _repo_manager(repo_conn):
    """Returns an instance of repository manager"""
    util = Utility()
    config = util.CONFIG
    repo_mgr = util.get_plugin(config.PATH_REPO_MGR)
    repo_mgr.connect(repo_conn)
    return repo_mgr
示例#3
0
def _browser(wh_conn):
    """Returns instance of database browser"""
    util = Utility()
    config = util.CONFIG
    br = util.get_plugin(config.PATH_BROWSER)
    br.connect(wh_conn)
    return br
示例#4
0
def _wh_connect():
    """Connects to an repository database for storing and reading back the metadata objects
    """
    utils = Utility()
    config = utils.CONFIG
    conn = utils.get_plugin(config.PATH_CONNECTION_MANAGERS)
    conn.connect(config.URL_TEST_DB)
    return conn
示例#5
0
文件: browser.py 项目: singajeet/bipy
def connect():
    """Connects to an browser interface and returns
        the connection
    """
    util = Utility()
    config = util.CONFIG
    conns = util.get_plugin(config.PATH_CONNECTION_MANAGERS)
    conns.connect(config.URL_TEST_DB)
    return conns
示例#6
0
 def __init__(self):
     self.__util = Utility()
     self.__config = self.__util.CONFIG
     self.__connection_mgr = self.__util.get_plugin(
         self.__config.PATH_CONNECTION_MANAGERS)
     self.__connection_mgr.connect(self.__config.URL_TEST_DB)
     self.__engine = self.__connection_mgr.get_engine()
     self.__session = self.__connection_mgr.ConnectedSession
     self.__metadata = MetaData(self.__engine)
     self.__metadata.reflect(bind=self.__engine)
示例#7
0
 def connect_repo(self, params):
     """Connects to either warehouse or repo based on params passed
     """
     if params.__len__() == 0:
         if self._repo_conn is None:
             util = Utility()
             config = util.CONFIG
             self._repo_conn = util.get_plugin(config.PATH_CONNECTION_MANAGERS)
             self._repo_conn.connect(config.URL_META_DB)
         return self._repo_conn
     elif str(params[0]).lower() == "--help":
         print("")
         print("HELP:")
         print("-----")
         print("Connects to an Repository database configured in the system")
         print("No parameters are required to run this command")
         print("")
示例#8
0
 def setUp(self):
     """ Setups the test case for testing the repo mgr class
     """
     utils = Utility()
     self.__conf = utils.CONFIG
     #---------- Load Connection Mgr plugin for Warehouse ------------
     conns = utils.get_all_plugins(self.__conf.PATH_CONNECTION_MANAGERS)
     self.__conn_wh = conns[0].plugin_object
     self.__conn_wh.connect(self.__conf.URL_TEST_DB)
     #---------- Load Warehouse Browser plugin -----------------------
     browsers = utils.get_all_plugins(self.__conf.PATH_BROWSER)
     self.__browser = browsers[0].plugin_object
     self.__browser.connect(self.__conn_wh)
     #--------- Load Base Meta Generator plugin ----------------------
     base_meta_gen = utils.get_all_plugins(self.__conf.PATH_BASE_META_GEN)
     self.__meta_gen = base_meta_gen[0].plugin_object
     #--------- Load Repository Manager plugin -----------------------
     repo_mgrs = utils.get_all_plugins(self.__conf.PATH_REPO_MGR)
     self.__repo_mgr = repo_mgrs[0].plugin_object
     #----- Load Connection Mgr plugin for repository / meta db ------
     repo_conns = utils.get_all_plugins(
         self.__conf.PATH_CONNECTION_MANAGERS)
     self.__conn_repo = repo_conns[0].plugin_object
     self.__conn_repo.connect(self.__conf.URL_META_DB)
     self.__repo_mgr.connect(self.__conn_repo)
示例#9
0
 def wrapper(*args, **kwargs):
     """ Authorization logic that will init the SecurityManager class
         and executes the logic to check whether function call
         is allowed or not
     """
     util = Utility()
     conf = util.CONFIG
     cms = util.get_all_plugins(conf.PATH_CONNECTION_MANAGERS)
     _cm = cms[0].plugin_object
     _cm.connect(conf.URL_META_DB)
     _sm = SecurityManager(_cm)
     result = _sm.authorize(privilege)
     if result:
         func(*args, **kwargs)
     # else throw exception
     else:
         raise Exception("User is not authorized \
                         to use this functionality")
示例#10
0
 def __init__(self):
     """Default constructor
     """
     self.__SESSION = PromptSession()
     self._util = Utility()
     self._config = self._util.CONFIG
     self._sub_commands = BrowserSubCmds()
     self._connect_sub_cmds = ConnectSubCmds()
     self._select_sub_cmds = SelectionSubCmds()
     self.run()
示例#11
0
def get_logger(log_name):
    """ Returns the logger configured using the log_config.json file
    """
    util = Utility()
    conf = util.CONFIG
    with open(conf.PATH_LOG_CONFIG, 'rt') as logging_configuration_file:
        config_dict = json.load(logging_configuration_file)
        handlers = config_dict["handlers"]
        file_handler = handlers["file_handler"]
        file_name = file_handler["filename"]
        file_name = os.path.abspath(
            os.path.join(conf.PATH_ROOT_PARENT, file_name))
        #replace the filename with the absolute path to root's parent
        file_handler["filename"] = file_name
        logging.config.dictConfig(config_dict)
        # Do not show debug and info message from 3rd party
        logging.getLogger("yapsy").setLevel(logging.WARNING)
        return logging.getLogger(log_name)
示例#12
0
def _base_meta_gen():
    """Returns an instance of base meta generator"""
    util = Utility()
    config = util.CONFIG
    bmg = util.get_plugin(config.PATH_BASE_META_GEN)
    return bmg
示例#13
0
文件: browser.py 项目: singajeet/bipy
def _browser():
    """Returns an instance of Browser plugin"""
    util = Utility()
    config = util.CONFIG
    browser = util.get_plugin(config.PATH_BROWSER)
    return browser
示例#14
0
 def __init__(self):
     """Default constructor"""
     AbstractCategory.__init__(self)
     self.__UTIL = Utility()
     self.__CONF = self.__UTIL.CONFIG
     LOGGER.debug("Project Manager instance created")
示例#15
0
class Reflector:
    """Class to explore database through reflection APIs
    """

    __connection_mgr = None
    __session = None
    __engine = None
    __metadata = None
    __INSTANCE = None
    __util = None
    __config = None

    def __new__(cls):
        if Reflector.__INSTANCE is None:
            Reflector.__INSTANCE = object.__new__(cls)
        return Reflector.__INSTANCE

    def __init__(self):
        self.__util = Utility()
        self.__config = self.__util.CONFIG
        self.__connection_mgr = self.__util.get_plugin(
            self.__config.PATH_CONNECTION_MANAGERS)
        self.__connection_mgr.connect(self.__config.URL_TEST_DB)
        self.__engine = self.__connection_mgr.get_engine()
        self.__session = self.__connection_mgr.ConnectedSession
        self.__metadata = MetaData(self.__engine)
        self.__metadata.reflect(bind=self.__engine)

    def get_table(self, table_name):
        """Returns an instance of the table that exists in the target
            warehouse

            Args:
                table_name (String): Name of the table available in warehouse
        """
        if self.__metadata is not None:
            table = self.__metadata.tables.get(table_name)
            if table is not None:
                return table
            else:
                raise ValueError(
                    "Provided table '%s' doesn't exist in the warehouse" %
                    (table_name))
        else:
            raise ReferenceError(
                "The referenced metadata is not available yet. \
                Please check the configuration file to make sure the path to the \
                warehouse is correct!")

    def get_columns_list(self, columns):
        """Returns an list of columns casted to `sqlalchemy.column` type

            Args:
                columns (String): A comma seperated list of column names
        """
        column_array = str(columns).split(',')
        column_list = []
        for col in column_array:
            col_obj = column(col)  # Wrap with sqlalchemy.column object
            column_list.append(col_obj)
        return column_list

    def get_where_conditon(self, condition_string):
        """returns an object of sqlalchemy.text for the given string condition

            Args:
                condition_string (String): An where condition provided in string form
        """
        return text(condition_string)

    def get_order_by_condition(self, order_by_string):
        """Returns an object of sqlalchemy.text for the given order by condition

            Args:
                order_by_string (strinng): An order by text string
        """
        return text(order_by_string)

    def prepare_query(self,
                      table,
                      columns=None,
                      where_cond=None,
                      order_by_cond=None):
        """Combines all parameters to prepare an SQL statement for execution
        This will return the statement only not the result set

            Args:
                table (sqlalchemy.table): An table object
                columns (List[sqlalchemy.column]): An list of columns
                where_cond (sqlalchemy.text): A where condition wrapped in text object
                order_by (sqlalchemy.text): An order by condition wrapped in text object
        """
        statement = table.select()

        if columns is not None:
            statement = statement.with_only_columns(columns)

        statement = statement.select_from(table)

        if where_cond is not None:
            statement = statement.where(where_cond)

        if order_by_cond is not None:
            statement = statement.order(order_by_cond)

        return statement

    def execute_statement(self, statement):
        """Executes the provided statement and returns back the result set

            Args:
                statement (sqlalchemy.select): An select statement
        """
        return self.__session.execute(statement)
示例#16
0
 def setUp(self):
     testmetadata.BrowserTestCase.setUp(self)
     util = Utility()
     self.conf = util.CONFIG
     self.bmg = util.get_all_plugins(self.conf.PATH_BASE_META_GEN)