本文整理汇总了Python中pyasm.biz.Schema.get_by_code方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.get_by_code方法的具体用法?Python Schema.get_by_code怎么用?Python Schema.get_by_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.biz.Schema
的用法示例。
在下文中一共展示了Schema.get_by_code方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from pyasm.biz import Schema [as 别名]
# 或者: from pyasm.biz.Schema import get_by_code [as 别名]
def execute(self):
from pyasm.search import DbContainer
from pyasm.security import Security
delete_group = "admin"
security = Environment.get_security()
if not security.is_in_group(delete_group):
raise Exception("Only users in [%s] can delete projects"%delete_group)
project_code = self.kwargs.get("project_code")
if project_code:
project = Project.get_by_code(project_code)
else:
search_key = self.kwargs.get("search_key")
project = Search.get_by_search_key(search_key)
project_code = project.get_code()
assert project_code
assert project
# dump the database
# remove all dependencies the sthpw database
related_types = self.kwargs.get("related_types")
if related_types:
for related_type in related_types:
search = Search(related_type)
if related_type == "sthpw/schema":
search.add_filter("code", project_code)
else:
search.add_filter("project_code", project_code)
count = search.get_count()
sobjects = search.get_sobjects()
for sobject in sobjects:
if related_type == 'sthpw/snapshot':
self.delete_snapshot(sobject)
else:
sobject.delete()
sthpw_project = Project.get_by_code('sthpw')
# delete the database
sthpw_db_resource = sthpw_project.get_project_db_resource()
db_resource = project.get_project_db_resource()
impl = sthpw_db_resource.get_database_impl()
deleted_impl = db_resource.get_database_impl()
if not impl.database_exists(db_resource):
# remove the project entry
project.delete()
return
# close this connection to the project to be deleted
sql = DbContainer.get(db_resource)
sql.close()
if sql.get_database_type() == 'Sqlite':
DbContainer.release_thread_sql()
result = impl.drop_database(db_resource)
# this is just extra check
if result and "failed" in result:
raise TacticException(result)
Container.put("Sql:database_exists:%s"%db_resource.get_key(), None)
sql = DbContainer.get(db_resource, connect=True)
if sql:
try:
if sql.get_database_type() != 'Sqlite':
if sql.get_connection() and sql.connect():
raise TacticException("Database [%s] still exists. There could still be connections to it."%project_code)
except SqlException as e:
pass
# remove the project entry
project.delete(triggers=False)
schema = Schema.get_by_code(project_code)
if schema:
schema.delete()
# Delete project specific login group and login in group entries
expr = "@SOBJECT(sthpw/login_group['project_code','%s'])"%project_code
expr2 = "@SOBJECT(sthpw/login_group['project_code','%s'].sthpw/login_in_group)"%project_code
sobjs = Search.eval(expr2)
for sobj in sobjs:
sobj.delete()
sobjs = Search.eval(expr)
#.........这里部分代码省略.........
示例2: get_display
# 需要导入模块: from pyasm.biz import Schema [as 别名]
# 或者: from pyasm.biz.Schema import get_by_code [as 别名]
def get_display(my):
from pyasm.biz import Project
security = Environment.get_security()
if not security.check_access("builtin", "side_bar_schema", "allow", default="deny"):
return DivWdg()
section_div = LabeledHidableWdg(label="Schema Views")
section_div.set_attr('spt_class_name', Common.get_full_class_name(my) )
palette = Palette.get()
color = palette.color("background3")
project_div = RoundedCornerDivWdg(hex_color_code=color,corner_size="10")
project_div.set_dimensions( width_str='175px', content_height_str='100px' )
project = Project.get()
project_code = project.get_code()
project_type = project.get_type()
div = DivWdg()
section_div.add(project_div)
project_div.add(div)
# get project type schema
schema = Schema.get_by_code(project_code)
if schema:
div.add( my.get_schema_wdg(schema) )
#if not project_type:
# raise SetupException("Project type not found for this [%s]" %project_code)
if project_type:
schema = Schema.get_predefined_schema(project_type)
if schema:
div.add( my.get_schema_wdg(schema) )
schema = Schema.get_predefined_schema('config')
div.add( my.get_schema_wdg(schema) )
schema = Schema.get_admin_schema()
div.add( my.get_schema_wdg(schema) )
return section_div
# create a fake schema
project = Project.get()
db_name = project.get_database()
sql = DbContainer.get(db_name)
tables = sql.get_tables()
tables.sort()
tables_str = "\n".join( ['<search_type name="%s"/>'%x for x in tables] )
# look at all of the search objects for mapped tables
search = Search("sthpw/search_object")
#search.add_where('''"namespace" = 'MMS' or namespace = '{project}' ''')
search.add_filter("namespace", 'MMS')
search.add_filter("namespace", '{project}')
search.add_where("or")
search_types = search.get_sobjects()
#for search_type in search_types:
# print "hhhh: ", search_type
schema_xml = '''
<schema>
%s
</schema>
''' % tables_str
schema = SearchType.create("sthpw/schema")
schema.set_value("code", "table")
schema.set_value("schema", schema_xml)
#div.add( my.get_schema_wdg(schema) )
return section_div