Ejemplo n.º 1
0
    def get_tables_wdg(my):
        
        div = DivWdg()
        div.set_name("Tables")

        div.add("In order to fully register a database, you must bind it to a TACTIC project")
        div.add("<br/>")



        project_code = "mongodb"
        database = "test_database"

        db_resource = DbResource(
                server='localhost',
                vendor='MongoDb',
                database=database
        )


        try:
            connect = DbContainer.get(db_resource)
        except Exception, e:
            div.add("Could not connect")
            div.add_style("padding: 30px")
            div.add("<br/>"*2)
            div.add(str(e))
            return div
Ejemplo n.º 2
0
def execute(db_resource):

    # This works if there is a project set up already with the appropriate
    # db_resource.
    search_type = "table/foofoo?project=db2_test"
    search_type_obj = SearchType.get(search_type)
    search = Search(search_type)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)

    # or (note that there is no project here).  The two arguments
    # are sufficient to determine a search.  Here we want to just "casually"
    # connect to a separate database resource.
    table = 'foofoo'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("description")

    table = 'widget_config'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("config")

    db_resource = DbResource(vendor="MySQL", database="fifi", user="******")
    introspect = DbIntrospect()
    introspect.register("fifi", db_resource)
    table = 'cards'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("description")

    print "sqlite: transaction_log"
    db_resource = DbResource.get_by_code('sqlite', 'sthpw')
    introspect = DbIntrospect()
    introspect.register("sqlite", db_resource)
    search = db_resource.get_search("transaction_log")
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)

    print "mysql: fifi"
    db_resource = DbResource.get_by_code('mysql', 'fifi')
    introspect = DbIntrospect()
    introspect.register("fifi", db_resource)
    search = db_resource.get_search("cards")
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)

    print "mysql: fifi"
    search_type = "table/node0?project=db3_test"
    search = Search(search_type)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
Ejemplo n.º 3
0
    def get_project_db_resource(my):
        # get the db resource for attached to this particular project.
        # Not the db_resource for "sthpw/project" for which
        # project.get_db_resource() does
        key = "Project:db_resource:%s" % my.get_code()
        resource = Container.get(key)
        if resource != None:
            return resource

        # the project defines the resource
        database = my.get_database_name()
        assert database

        if database == 'sthpw':
            # get if from the config
            db_resource_code = None
        else:
            db_resource_code = my.get_value("db_resource", no_exception=True)

        if not db_resource_code:
            # this could be any project, not just sthpw
            # already looked at cache, so set use_cache to False
            db_resource = DbResource.get_default(database, use_cache=False)
            Container.put(key, db_resource)
            return db_resource
        #elif isinstance(db_resource_code, DbResource):
        elif DbResource.is_instance(db_resource_code):
            db_resource = db_resource_code
            Container.put(key, db_resource)
            return db_resource

        db_resource_code = db_resource_code.strip()
        search = Search("sthpw/db_resource")
        search.add_filter("code", db_resource_code)
        db_resource_sobj = search.get_sobject()
        if not db_resource_sobj:
            raise TacticException("Database Resource [%s] does not exist" %
                                  db_resource_code)

        host = db_resource_sobj.get_value("host")
        vendor = db_resource_sobj.get_value("vendor")
        host = db_resource_sobj.get_value("host")
        port = db_resource_sobj.get_value("port")
        user = db_resource_sobj.get_value("login")
        password = db_resource_sobj.get_value("password")

        db_resource = DbResource(database=database,
                                 host=host,
                                 port=port,
                                 vendor=vendor,
                                 password=password)
        Container.put(key, db_resource)

        return db_resource
Ejemplo n.º 4
0
    search = db_resource.get_search("cards")
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)

    print "mysql: fifi"
    search_type = "table/node0?project=db3_test"
    search = Search(search_type)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)


if __name__ == '__main__':

    from pyasm.security import Batch
    Batch(project_code="project")

    # register this resource
    db_resource = DbResource(vendor="MySQL",
                             host="localhost",
                             database="db2_test",
                             user="******")

    # auto register all of the tables there
    introspect = DbIntrospect()
    import time
    start = time.time()
    introspect.register("db2_test", db_resource)
    print "time: ", time.time() - start

    execute(db_resource)
Ejemplo n.º 5
0
    def get_tables_wdg(self):

        div = DivWdg()
        div.set_name("Tables")

        div.add(
            "In order to fully register a database, you must bind it to a TACTIC project"
        )
        div.add("<br/>")

        project_code = "mongodb"
        database = "test_database"

        db_resource = DbResource(server='localhost',
                                 vendor='MongoDb',
                                 database=database)

        try:
            connect = DbContainer.get(db_resource)
        except Exception as e:
            div.add("Could not connect")
            div.add_style("padding: 30px")
            div.add("<br/>" * 2)
            div.add(str(e))
            return div

        # Bind project to this resource
        database_text = TextWdg("database")
        div.add("Database: ")
        div.add(database_text)

        div.add("<br/>" * 2)

        project_text = TextWdg("project")
        div.add("Project Code: ")
        div.add(project_text)

        div.add("<br/>")
        div.add("<hr/>")

        # connect and introspect the tables in this database
        tables = connect.get_tables()

        table = Table()
        div.add(table)
        table.set_max_width()

        for table_name in tables:
            table.add_row()
            search_type = "table/%s?project=%s" % (table_name, project_code)

            td = table.add_cell()
            icon = IconWdg("View Table", IconWdg.FOLDER_GO)
            td.add(icon)
            icon.add_behavior({
                'type':
                'click_up',
                'search_type':
                search_type,
                'cbjs_action':
                '''
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type
                }
                spt.panel.load_popup("table", class_name, kwargs);
                '''
            })

            td = table.add_cell()
            td.add(table_name)

            td = table.add_cell()
            search = Search(search_type)
            count = search.get_count()
            td.add(" %s item/s" % count)

            columns = search.get_columns()
            td = table.add_cell()
            td.add(columns)

            # search_type
            td = table.add_cell()
            text = TextWdg("search_type")
            td.add(text)
            new_search_type = "%s/%s" % (project_code, table_name)
            text.set_value(new_search_type)

        register_div = DivWdg()
        div.add(register_div)
        register_div.add_style("padding: 20px")

        button = ActionButtonWdg(title="Register")
        register_div.add(button)

        return div