本文整理汇总了Python中pyasm.common.Xml.get_root_node方法的典型用法代码示例。如果您正苦于以下问题:Python Xml.get_root_node方法的具体用法?Python Xml.get_root_node怎么用?Python Xml.get_root_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.common.Xml
的用法示例。
在下文中一共展示了Xml.get_root_node方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_main_config
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_root_node [as 别名]
def _get_main_config(self, view, process_names):
'''get the main config for this table layout'''
xml = Xml()
xml.create_doc("config")
root = xml.get_root_node()
view_node = xml.create_element(view)
#root.appendChild(view_node)
xml.append_child(root, view_node)
for idx, process_name in enumerate(process_names):
element = xml.create_element('element')
Xml.set_attribute(element, 'name', process_name)
#view_node.appendChild(element)
xml.append_child(view_node, element)
display = xml.create_element('display')
if self.element_class:
Xml.set_attribute(display, 'class',self.element_class)
else:
Xml.set_attribute(display, 'class', "tactic.ui.app.NoteTableElementWdg")
#element.appendChild(display)
xml.append_child(element, display)
op_element = xml.create_data_element('parent_key', self.search_key)
xml.append_child(display, op_element)
config_xml = xml.to_string()
widget_config = WidgetConfig.get(view=view, xml = config_xml)
widget_config_view = WidgetConfigView('sthpw/note', view, [widget_config])
return widget_config_view
示例2: execute
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_root_node [as 别名]
def execute(my):
class_names = my.kwargs.get("class_names")
attrs_list = my.kwargs.get("attrs_list")
kwargs_list = my.kwargs.get("kwargs_list")
xml = Xml()
xml.create_doc("config")
root = xml.get_root_node()
view = xml.create_element("tab")
xml.append_child(root, view)
for class_name, attrs, kwargs in zip(class_names, attrs_list, kwargs_list):
element = xml.create_element("element")
xml.append_child(view, element)
for key, value in attrs.items():
xml.set_attribute(element, key, value)
display = xml.create_element("display")
xml.append_child(element, display)
xml.set_attribute(display, "class", class_name)
for key, value in kwargs.items():
attr = xml.create_text_element(key, value, node=display)
xml.append_child(display, attr)
xml_string = xml.to_string()
from pyasm.web import WidgetSettings
WidgetSettings.set_value_by_key("tab", xml_string)
示例3: dump
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_root_node [as 别名]
def dump(my, plugin_code, project_code, search_types):
xml = Xml()
my.xml = xml
xml.create_doc("manifest")
manifest_node = xml.get_root_node()
xml.set_attribute(manifest_node, "code", plugin_code)
# DUMP the data
for search_type in search_types:
data_node = xml.create_element("search_type")
xml.append_child(manifest_node, data_node)
xml.set_attribute(data_node, "code", search_type)
# This exports the data
"""
data_node = xml.create_element("sobject")
xml.append_child(manifest_node, data_node)
xml.set_attribute(data_node, "search_type", search_type)
# find the currval
st_obj = SearchType.get(search_type)
# have to call nextval() to initiate this sequence in the session in psql since Postgres 8.1
seq_id = st_obj.sequence_nextval()
seq_id = st_obj.sequence_currval()
seq_id -= 1
if seq_id > 0:
st_obj.sequence_setval(seq_id)
xml.set_attribute(data_node, "seq_max", seq_id)
"""
print xml.to_string()
# create a virtual plugin
plugin = SearchType.create("sthpw/plugin")
plugin.set_value("version", "1.0.0")
plugin.set_value("code", "%s_project" % project_code)
base_dir = "./templates"
creator = PluginCreator( base_dir=base_dir, plugin=plugin, manifest=xml.to_string() )
creator.execute()
示例4: create
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_root_node [as 别名]
def create(pipeline_name, desc, pipe_search_type):
'''will only create if it does not exist, otherwise it just updates'''
sobject = Pipeline.get_by_name(pipeline_name)
if sobject == None:
#sobject = Pipeline( Pipeline.SEARCH_TYPE )
sobject = SearchType.create( Pipeline.SEARCH_TYPE )
else:
return sobject
xml = Xml()
xml.create_doc('pipeline')
root = xml.get_root_node()
#Xml.set_attribute(root, 'type', type)
sobject.set_value("pipeline", xml.get_xml())
sobject.set_value('timestamp', Sql.get_default_timestamp_now(), quoted=False )
sobject.set_value('code', pipeline_name)
sobject.set_value('search_type', pipe_search_type)
sobject.set_value('description', desc)
sobject.commit()
return sobject
示例5: _get_edit_config
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_root_node [as 别名]
def _get_edit_config(self, view, process_names):
xml = Xml()
xml.create_doc("config")
root = xml.get_root_node()
view_node = xml.create_element(view)
#root.appendChild(view_node)
xml.append_child(root, view_node)
for idx, process_name in enumerate(process_names):
element = xml.create_element('element')
Xml.set_attribute(element, 'name', process_name)
#view_node.appendChild(element)
xml.append_child(view_node, element)
display = xml.create_element('display')
Xml.set_attribute(display, 'class', "pyasm.widget.TextAreaWdg")
#element.appendChild(display)
xml.append_child(element, display)
config_xml = xml.to_string()
widget_config = WidgetConfig.get(view=view, xml = config_xml)
widget_config_view = WidgetConfigView('sthpw/note', view, [widget_config])
return widget_config_view
示例6: execute
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_root_node [as 别名]
def execute(self):
web = WebContainer.get_web()
alter_mode = self.kwargs.get("alter_mode")
title = self.kwargs.get("title")
config_mode = web.get_form_value("config_mode")
view = web.get_form_value('view')
constraint = web.get_form_value("config_constraint")
data_type = ''
if config_mode == "advanced" :
config_string = web.get_form_value("config_xml")
if config_string:
xml = Xml()
xml.read_string(config_string)
node = xml.get_root_node()
data_type = xml.get_attribute(node, "data_type")
nullable = xml.get_attribute(node, "nullable") in ['true','True']
else:
data_type = web.get_form_value("config_data_type")
if data_type == 'Other...':
data_type = web.get_form_value("config_data_type_custom")
cb = CheckboxWdg("config_nullable")
nullable = cb.is_checked()
# if advanced is selected in the Widget Column view, data_type is ''
# read from UI
if not data_type and view == 'definition':
data_type = web.get_form_value("config_data_type")
if data_type == 'Other...':
data_type = web.get_form_value("config_data_type_custom")
cb = CheckboxWdg("config_nullable")
nullable = cb.is_checked()
column_name = web.get_form_value("column_name")
search_type = web.get_form_value("target_search_type")
if alter_mode == ManageSearchTypeDetailWdg.REMOVE_COLUMN:
cmd = ColumnDropCmd(search_type, column_name)
Command.execute_cmd(cmd)
# delete widget config from definition view
widget_config = WidgetDbConfig.get_by_search_type(search_type, 'definition')
if widget_config:
config = WidgetConfig.get('definition', xml=widget_config.get_xml_value('config'))
config.remove_xml_element(column_name)
new_xml = config.get_xml().to_string()
widget_config.set_value("config", new_xml)
widget_config.commit()
# set cache to {}
from pyasm.common import Container
Container.put("WidgetConfigView:config_cache", {})
#Container.put("WidgetConfig:config_cache", {})
elif alter_mode == ManageSearchTypeDetailWdg.MODIFY_COLUMN:
cmd = ColumnAlterCmd(search_type, column_name, data_type, nullable)
Command.execute_cmd(cmd)
element_options = {}
element_options['type'] = data_type
if title:
element_options['title'] = title
# handle the "default" view
# update the widget config data type in the xml
view = self.DEFAULT_VIEW
config = WidgetDbConfig.get_by_search_type(search_type, view)
if config:
config.append_display_element(column_name, options={}, \
element_attrs=element_options)
config.commit_config()
elif alter_mode == ManageSearchTypeDetailWdg.ADD_COLUMN:
cmd = ColumnAddCmd(search_type, column_name, data_type, nullable)
Command.execute_cmd(cmd)
if constraint:
# add constraint
from pyasm.command import ColumnAddIndexWdg
cmd = ColumnAddIndexWdg()
cmd.execute()
else:
# remove constraint
pass
示例7: export_template
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_root_node [as 别名]
def export_template(my):
xml = Xml()
my.xml = xml
xml.create_doc("manifest")
manifest_node = xml.get_root_node()
# Old implementation. Code is now on the data node
xml.set_attribute(manifest_node, "code", my.template_project_code)
# dump the notification entries
data_node = xml.create_element("data")
xml.append_child(manifest_node, data_node)
code_node = xml.create_element("code")
xml.append_child(data_node, code_node)
xml.set_node_value(code_node, my.template_project_code)
version = my.kwargs.get("version") or ""
version_node = xml.create_element("version")
xml.append_child(data_node, version_node)
xml.set_node_value(version_node, version)
# dump the project entry
data_node = xml.create_element("sobject")
xml.append_child(manifest_node, data_node)
xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/project['code','%s'])" % my.project_code)
xml.set_attribute(data_node, "search_type", "sthpw/project")
xml.set_attribute(data_node, "unique", "true")
# dump the project_type entry
data_node = xml.create_element("sobject")
xml.append_child(manifest_node, data_node)
xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/project['code','%s'].sthpw/project_type)" % my.project_code)
xml.set_attribute(data_node, "search_type", "sthpw/project_type")
xml.set_attribute(data_node, "unique", "true")
# dump the schema entry
data_node = xml.create_element("sobject")
xml.append_child(manifest_node, data_node)
xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/schema['code','%s'])" % my.project_code)
xml.set_attribute(data_node, "search_type", "sthpw/schema")
xml.set_attribute(data_node, "unique", "true")
# find the project template search types
namespace = my.project_type
if not namespace or namespace == "default":
namespace = my.project_code
project_search_types = Search.eval("@GET(sthpw/search_object['namespace','%s'].search_type)" % namespace)
#project_types = Search.eval("@GET(sthpw/search_object['namespace','%s'].search_type)" % my.project_code)
# just dump the definition for data
for search_type in project_search_types:
data_node = xml.create_element("search_type")
xml.append_child(manifest_node, data_node)
xml.set_attribute(data_node, "code", search_type)
search_types = [
"config/custom_script",
"config/widget_config",
"config/naming",
"config/client_trigger",
"config/process",
"config/trigger",
"config/url",
#"config/ingest_rule",
#"config/ingest_session",
]
for search_type in search_types:
data_node = xml.create_element("sobject")
xml.append_child(manifest_node, data_node)
xml.set_attribute(data_node, "search_type", search_type)
# find the currval
st_obj = SearchType.get(search_type)
# have to call nextval() to initiate this sequence in the session in psql since Postgres 8.1
seq_id = SearchType.sequence_nextval(search_type)
seq_id = SearchType.sequence_currval(search_type)
seq_id -= 1
if seq_id > 0:
SearchType.sequence_setval(search_type, seq_id)
xml.set_attribute(data_node, "seq_max", seq_id)
#xml.set_attribute(data_node, "path", "data.spt")
#.........这里部分代码省略.........
示例8: execute
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_root_node [as 别名]
def execute(self):
import datetime
now = datetime.datetime.now()
version = now.strftime("%Y%m%d_%H%M%S")
project_code = self.kwargs.get("project_code")
if project_code:
project = Project.get_by_code(project_code)
else:
project = Project.get()
project_code = project.get_code()
server_code = self.kwargs.get("server")
assert server_code
if not isinstance(server_code, basestring):
server_code = server_code.get_value("code")
base_dir = self.kwargs.get('base_dir')
ticket = Environment.get_ticket()
tmp_dir = "%s/sync_%s" % (Environment.get_tmp_dir(), ticket)
if not os.path.exists(tmp_dir):
os.makedirs(tmp_dir)
server = Search.get_by_code("sthpw/sync_server", server_code)
if server.get_value("sync_mode") == "file":
if not base_dir:
base_dir = server.get_value("base_dir")
else:
raise Exception("sync mode [%s] not support" % sync_mode)
# FIXME: not sure if this is valid anymore
asset_dir = Environment.get_asset_dir()
base_dir = "%s/_temp" % asset_dir
# create the project template
from tactic.command import ProjectTemplateCreatorCmd
cmd = ProjectTemplateCreatorCmd(project_code=project_code, version=version, base_dir=tmp_dir)
cmd.execute()
project_path = cmd.get_zip_path()
# create zip of the project files
from pyasm.common import ZipUtil
zip_util = ZipUtil()
asset_dir = Environment.get_asset_dir()
project_dir = "%s/%s" % (asset_dir, project_code)
zip_dir = "%s/%s" % (tmp_dir, project_code)
file_path = "%s-files-%s.zip" % (zip_dir, version)
if os.path.exists(file_path):
os.unlink(file_path)
zip_util.zip_dir2(project_dir, zip_path=file_path)
# create a manifest for all the data in the project.
xml = Xml()
self.xml = xml
xml.create_doc("manifest")
manifest_node = xml.get_root_node()
xml.set_attribute(manifest_node, "code", "%s-data" % project_code)
search_types = project.get_search_types()
# just dump the data
for search_type in search_types:
data_node = xml.create_element("sobject")
xml.append_child(manifest_node, data_node)
xml.set_attribute(data_node, "search_type", search_type.get_value("search_type"))
# dump the note entries
data_node = xml.create_element("sobject")
xml.append_child(manifest_node, data_node)
xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/note['project_code','%s'])" % project_code)
xml.set_attribute(data_node, "search_type", "sthpw/note")
# dump the task entries
data_node = xml.create_element("sobject")
xml.append_child(manifest_node, data_node)
xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/task['project_code','%s'])" % project_code)
xml.set_attribute(data_node, "search_type", "sthpw/task")
# dump the snapshot entries
data_node = xml.create_element("sobject")
xml.append_child(manifest_node, data_node)
xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/snapshot['project_code','%s'])" % project_code)
xml.set_attribute(data_node, "search_type", "sthpw/snapshot")
#.........这里部分代码省略.........
示例9: SObjectDefaultConfig
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_root_node [as 别名]
class SObjectDefaultConfig(Base):
'''An artificial config file is made if none are found'''
def __init__(self, search_type, view, config_base=None, mode="columns"):
self.search_type = search_type
if view:
self.view = view
else:
self.view = config_base
if not self.view:
self.view = "table"
# bit of protection ... : have been known to show up in view names
self.view = self.view.replace(":", '_')
#mode = "basic"
self.xml = Xml()
if mode == 'columns':
self.handle_columns_mode()
else:
self.handle_basic_mode()
def get_columns(self, required_only=False):
if self.search_type == 'sthpw/virtual':
return []
search_type_obj = SearchType.get(self.search_type)
table = search_type_obj.get_table()
from pyasm.biz import Project
db_resource = Project.get_db_resource_by_search_type(self.search_type)
database_name = db_resource.get_database()
db = DbContainer.get(db_resource)
# table may not exist
try:
all_columns = db.get_columns(table)
columns = []
if required_only:
nullables = db.get_column_nullables(table)
for column in all_columns:
null_ok = nullables.get(column)
if not null_ok:
columns.append(column)
# if there are no required columns
if not columns:
columns = all_columns
else:
columns = all_columns
except SqlException:
Environment.add_warning('missing table', 'Table [%s] does not exist in database [%s]' %(table, database_name))
return []
return columns
def handle_basic_mode(self):
doc = self.xml.create_doc("config")
root = self.xml.get_root_node()
db_columns = self.get_columns()
if "code" in db_columns:
columns = ["preview", "code"]
elif "name" in db_columns:
columns = ["preview", "name"]
elif "id" in db_columns:
columns = ["preview", "id"]
table = self.xml.create_element("table")
Xml.append_child(root, table)
for column in ["preview", "code"]:
element = self.xml.create_element("element")
Xml.set_attribute(element, "name", column)
Xml.append_child(table, element)
# create the edit
edit = self.xml.create_element("edit")
Xml.append_child(root, edit)
for column in ["preview", "code"]:
element = self.xml.create_element("element")
Xml.set_attribute(element, "name", column)
Xml.append_child(edit, element)
# create the manual publish view
publish = self.xml.create_element("publish")
Xml.append_child(root, publish)
#.........这里部分代码省略.........
示例10: SyncFilter
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_root_node [as 别名]
class SyncFilter(object):
def __init__(self, **kwargs):
self.kwargs = kwargs
self.log = self.kwargs.get("transaction")
self.rules = self.kwargs.get("rules")
self.message = ""
def execute(self):
log = self.log
rules = self.rules
# Give rules. Only notes will get through
# we need heirarchical rules. This will ensure that only notes
# for project/assets will pass
# Here, the second one is much more difficult to do.
rulesXXX = '''
<rule group='heirarchy' key='project/asset.sthpw/note' access='allow'/>
<rule group='heirarchy' key="project/asset.sthpw/note['assigned','beth']" access='allow'/>"
'''
access_manager = AccessManager()
access_manager.add_xml_rules(rules)
# filter out project
namespace = log.get_value("namespace")
key1 = { 'code': namespace }
key2 = { 'code': '*' }
keys = [key1, key2]
if not access_manager.check_access("project", keys, "allow", default="deny"):
self.filtered_xml = Xml()
self.filtered_xml.read_string("<transaction/>")
self.message = "Transaction prevented due to project restriction"
return
# filter the transaction against the security model
xml = log.get_xml_value("transaction")
self.filtered_xml = Xml()
self.filtered_xml.create_doc("transaction")
root2 = self.filtered_xml.get_root_node()
nodes = xml.get_nodes("transaction/*")
num_nodes = len(nodes)
count = 0
for node in nodes:
if Xml.get_node_name(node) == "sobject":
search_type = xml.get_attribute(node, "search_type")
parts = search_type.split("?")
search_type = parts[0]
# filter search types
key1 = { 'code': search_type }
key2 = { 'code': "*" }
keys = [ key1, key2 ]
if not access_manager.check_access("search_type", keys, "allow", default="deny"):
continue
# check hierachical rule
parent_type = xml.get_attribute(node, "parent_type")
key = "%s.%s" % (parent_type, search_type)
self.filtered_xml.append_child(root2, node)
count += 1
else:
self.filtered_xml.append_child(root2, node)
count += 1
if len(nodes) != 0 and len(self.filtered_xml.get_nodes("transaction/*")) == 0:
self.message = "All actions filtered due to security restrictions (%s actions)" % num_nodes
def get_filtered_xml(self):
return self.filtered_xml
def get_message(self):
return self.message