本文整理汇总了Python中pyasm.security.Site.get_db_resource方法的典型用法代码示例。如果您正苦于以下问题:Python Site.get_db_resource方法的具体用法?Python Site.get_db_resource怎么用?Python Site.get_db_resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.security.Site
的用法示例。
在下文中一共展示了Site.get_db_resource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_db_resource_by_search_type
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get_db_resource [as 别名]
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: get_project_db_resource
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get_db_resource [as 别名]
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