示例#1
0
    def get_db_resource_by_search_type(cls, search_type):
        if search_type.startswith('sthpw/'):
            # get the local db_resource
            from pyasm.security import Site
            site = Site.get_site()
            db_resource = None
            if site:
                db_resource = Site.get_db_resource(site, "sthpw")
            if not db_resource:
                db_resource = DbResource.get_default("sthpw")
            return db_resource


        project_code = cls.get_database_by_search_type(search_type)
        project = Project.get_by_code(project_code)
        if not project:
            raise Exception("Error: Project [%s] does not exist" % project_code)


        if search_type.startswith("salesforce/"):
            db_resource_code = "Salesforce"
            db_resource = DbResource.get_by_code(db_resource_code, project_code)
            return db_resource


        db_resource = project.get_project_db_resource()

        return db_resource
示例#2
0
    def get_project_db_resource(my, database=None):
        # get the db resource for attached to this particular project.
        # Not the db_resource for "sthpw/project" for which
        # project.get_db_resource() does
        from pyasm.security import Site
        site = Site.get_site()
        if site:
            key = "Project:db_resource_cache:%s" % site
        else:
            key = "Project:db_resource_cache"

        resource_dict = Container.get(key)
        if resource_dict:
            resource = resource_dict.get(my.get_code())
            if resource != None:
                return resource
        else:
            resource_dict = {}
            Container.put(key, resource_dict)

        # the project defines the resource
        if not database:
            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 = Site.get_db_resource(site, database)
            if not db_resource:
                db_resource = DbResource.get_default(database, use_cache=False)
            #db_resource = DbResource.get_default(database, use_cache=False)
            resource_dict[key] = db_resource
            return db_resource
        #elif isinstance(db_resource_code, DbResource):
        elif DbResource.is_instance(db_resource_code):
            db_resource = db_resource_code
            resource_dict[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(user=user,
                                 database=database,
                                 host=host,
                                 port=port,
                                 vendor=vendor,
                                 password=password)
        #Container.put(key, db_resource)
        resource_dict[key] = db_resource

        return db_resource
示例#3
0
文件: project.py 项目: jayvdb/TACTIC
    def get_project_db_resource(my, database=None):
        # get the db resource for attached to this particular project.
        # Not the db_resource for "sthpw/project" for which
        # project.get_db_resource() does
        from pyasm.security import Site
        site = Site.get_site()
        if site:
            key = "Project:db_resource_cache:%s" % site
        else:
            key = "Project:db_resource_cache"

        resource_dict = Container.get(key)
        if resource_dict:
            resource = resource_dict.get( my.get_code() )
            if resource != None:
                return resource
        else:
            resource_dict = {}
            Container.put(key, resource_dict)


        # the project defines the resource
        if not database:
            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 = Site.get_db_resource(site, database)
            if not db_resource:
                db_resource = DbResource.get_default(database, use_cache=False)
            #db_resource = DbResource.get_default(database, use_cache=False)
            resource_dict[key] = db_resource
            return db_resource
        #elif isinstance(db_resource_code, DbResource):
        elif DbResource.is_instance(db_resource_code):   
            db_resource = db_resource_code
            resource_dict[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(user=user, database=database, host=host, port=port, vendor=vendor, password=password)
        #Container.put(key, db_resource)
        resource_dict[key] = db_resource

        return db_resource