本文整理汇总了Python中pyasm.common.Xml.create_element方法的典型用法代码示例。如果您正苦于以下问题:Python Xml.create_element方法的具体用法?Python Xml.create_element怎么用?Python Xml.create_element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.common.Xml
的用法示例。
在下文中一共展示了Xml.create_element方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_main_config
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import create_element [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 create_element [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: _get_edit_config
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import create_element [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
示例4: serialize
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import create_element [as 别名]
def serialize(my):
'''provide the ability for a widget to serialize itself'''
xml = Xml()
xml.create_doc("config")
# create the top element
element = xml.create_element("element")
xml.set_attribute(element, "name", my.name)
# create the display handler
display = xml.create_element("display")
xml.set_attribute(display, "class", Common.get_full_class_name(my) )
element.appendChild(display)
# create the options
for name, value in my.kwargs.items():
if value:
option = xml.create_text_element(name, value)
else: # avoid the \n in the textContent of the textNode
option = xml.create_element(name)
display.appendChild(option)
return xml.to_string(element)
示例5: dump
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import create_element [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()
示例6: export_template
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import create_element [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")
#.........这里部分代码省略.........
示例7: execute
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import create_element [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")
#.........这里部分代码省略.........
示例8: PageNavContainerWdg
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import create_element [as 别名]
#.........这里部分代码省略.........
def set_state(self, panel_name, widget_class, options, values):
'''this is called by side_bar.js mostly'''
# set the class name
display_node = self.config_xml.get_node("config/application/element[@name='%s']/display" % (panel_name) )
self.config_xml.set_attribute(display_node, "class", widget_class)
# remove all the old options
#display_node = self.config_xml.get_node("config/application/element[@name='%s']/display" % panel_name )
for child_node in self.config_xml.get_children(display_node):
self.config_xml.remove_child(display_node, child_node)
# set the options
for name, value in options.items():
node = self.config_xml.get_node("config/application/element[@name='%s']/display/%s" % (panel_name, name) )
if isinstance( value, basestring ):
#print("WARNING: set application: skipping [%s] with value [%s]" % (name, value))
#continue
element = self.config_xml.create_text_element(name, value)
self.config_xml.append_child(display_node, element)
elif isinstance( value, dict): # if it is a dictionary
# TODO: run recursively.. supports 2 level only now
sub_element = self.config_xml.create_element(name)
self.config_xml.append_child(display_node, element)
for name2, value2 in value.items():
if isinstance(value2, dict):
sub_element2 = self.config_xml.create_element(name2)
self.config_xml.append_child(sub_element, sub_element2)
for name3, value3 in value2.items():
element = self.config_xml.create_text_element(name3, value3)
self.config_xml.append_child(sub_element2, element)
else:
element = self.config_xml.create_text_element(name2, value2)
self.config_xml.append_child(sub_element, element)
# web value node
value_node = self.config_xml.get_node("config/application/element[@name='%s']/web" % (panel_name) )
if value_node != None:
for child_node in self.config_xml.get_children(value_node):
self.config_xml.remove_child(value_node, child_node)
else: # create it
value_node = self.config_xml.create_element('web')
element_node = self.config_xml.get_node("config/application/element[@name='%s']" % (panel_name) )
self.config_xml.append_child(element_node, value_node)
# set the values
for name, value in values.items():
node = self.config_xml.get_node("config/application/element[@name='%s']/web/%s" % (panel_name, name) )
if not isinstance(value, basestring):
print("WARNING: set application: skipping [%s] with value [%s]" % (name, value))
continue
element = self.config_xml.create_text_element(name, value)
self.config_xml.append_child(value_node, element)
示例9: SObjectDefaultConfig
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import create_element [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)
#.........这里部分代码省略.........