本文整理汇总了Python中pyasm.common.Xml类的典型用法代码示例。如果您正苦于以下问题:Python Xml类的具体用法?Python Xml怎么用?Python Xml使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Xml类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_input_snapshots
def get_input_snapshots(my, sobject, process_name, input_name, version='latest'):
'''gets the snapshots of the input'''
assert version in ['latest', 'current']
process_node = my.xml.get_node( "pipeline/process[@name='%s']/input[@name='%s']" % (process_name, input_name))
search_type = Xml.get_attribute(process_node, "search_type")
context = Xml.get_attribute(process_node, "context")
filter = Xml.get_attribute(process_node, "filter")
# get the sobjects
sobjects = sobject.get_all_children(search_type)
# get the snapshots
search = Search("sthpw/snapshot")
search.add_filter('context', context)
#if version == 'latest':
# search.add_filter("is_latest", 1)
#elif version == 'current':
# search.add_filter("is_current", 1)
# build filters for search_type, search_id combinations
filters = []
for sobject in sobjects:
filter = "(\"search_type\" = '%s' and \"search_id\" = %s)" % (sobject.get_search_type(), sobject.get_id() )
filters.append(filter)
search.add_where( "( %s )" % " or ".join(filters) )
snapshots = search.get_sobjects()
return snapshots
示例2: execute
def execute(my):
my.init()
# create the filters
my.filters = []
"""
for element_name in my.config.get_element_names():
filter = my.config.get_display_widget(element_name)
my.filters.append(filter)
# make sure there is at least one filter defined
assert my.filters
"""
config = "<config>\n"
config += "<filter>\n"
# get all of the serialized versions of the filters
"""
for filter in my.filters:
config += filter.serialize() + "\n"
"""
filter_data = FilterData.get()
json = filter_data.serialize()
value_type = "json"
config += "<values type='%s'>%s</values>\n" % (value_type, json)
config += "</filter>\n"
config += "</config>\n"
# format the xml
xml = Xml()
xml.read_string(config)
if not my.view:
saved_view = "saved_search:%s" % my.search_type
else:
saved_view = my.view
# if my.view.startswith("saved_search:"):
# saved_view = my.view
# else:
# saved_view = "saved_search:%s" % my.view
# use widget config instead
search = Search("config/widget_config")
search.add_filter("view", saved_view)
search.add_filter("search_type", my.search_type)
if my.personal:
search.add_user_filter()
config = search.get_sobject()
if not config:
config = SearchType.create("config/widget_config")
config.set_value("view", saved_view)
config.set_value("search_type", my.search_type)
if my.personal:
config.set_user()
config.set_value("config", xml.to_string())
config.commit()
示例3: get_related_search_types
def get_related_search_types(self, search_type, direction=None):
related_types = []
if not direction or direction == "parent":
xpath = "schema/connect[@from='%s']" %(search_type)
connects = self.xml.get_nodes(xpath)
for connect in connects:
related_type = Xml.get_attribute(connect,"to")
related_types.append(related_type)
if not direction or direction == "children":
xpath = "schema/connect[@to='%s']" %(search_type)
connects = self.xml.get_nodes(xpath)
for connect in connects:
related_type = Xml.get_attribute(connect,"from")
related_types.append(related_type)
if self.parent_schema:
search_types = self.parent_schema.get_related_search_types(search_type, direction=direction)
related_types.extend(search_types)
if self.sthpw_schema:
search_types = self.sthpw_schema.get_related_search_types(search_type, direction=direction)
related_types.extend(search_types)
return related_types
示例4: get_child_types
def get_child_types(self, search_type, relationship="hierarchy", hierarchy=True):
if search_type.find("?") != -1:
search_type, tmp = search_type.split("?", 1)
child_types = []
# first get the child types defined in the admin schema
if hierarchy and self.sthpw_schema:
sthpw_child_types = self.sthpw_schema.get_child_types(search_type, relationship)
child_types.extend(sthpw_child_types)
# get the child types in the project type schema
if hierarchy and self.parent_schema:
parent_child_types = self.parent_schema.get_child_types(search_type, relationship)
child_types.extend(parent_child_types)
# add new style
connects = self.xml.get_nodes("schema/connect[@to='%s'] | schema/connect[@to='*']" % search_type)
for connect in connects:
relationship = Xml.get_attribute(connect, "relationship")
# skip old style
if not relationship:
continue
child_type = Xml.get_attribute(connect, "from")
# skip identical type
if child_type == search_type:
continue
child_types.append(child_type)
return child_types
示例5: delete_files
def delete_files(my, nodes):
# clean out all of the files
for node in nodes:
name = my.xml.get_node_name(node)
if name == "include":
path = my.xml.get_attribute(node, "path")
if not path:
print("WARNING: No path found for search type in manifest")
continue
path = "%s/%s" % (my.plugin_dir, path)
if path.endswith(".py"):
from tactic.command import PythonCmd
cmd = PythonCmd(file_path=path)
manifest = cmd.execute()
if manifest:
xml = Xml()
xml.read_string(manifest)
include_nodes = xml.get_nodes("manifest/*")
my.delete_files(include_nodes)
elif name == "python":
# don't delete python node file
pass
else:
path = my.get_path_from_node(node)
if path and os.path.exists(path):
print "Deleting: ", path
os.unlink(path)
示例6: _test_accept
def _test_accept(my):
# try json
url = "http://localhost/tactic/unittest/rest"
headers = {
"Accept": "application/json"
}
ret_val = my.send_request(url, headers)
my.assertEquals( [3,2,1], ret_val)
# try xml
url = "http://localhost/tactic/unittest/rest"
headers = {
"Accept": "application/xml"
}
ret_val = my.send_request(url, headers)
xml = Xml(ret_val)
values = xml.get_values("arr/int")
my.assertEquals( ['1','2','3'], values)
# try json
url = "http://localhost/tactic/unittest/rest/CODE0123"
headers = {
"Accept": "application/json"
}
ret_val = my.send_request(url, headers)
my.assertEquals( "OK", ret_val)
示例7: handle_include
def handle_include(my, node):
path = my.xml.get_attribute(node, "path")
if not path:
raise TacticException("No path found for include in manifest")
path = "%s/%s" % (my.plugin_dir, path)
if path.endswith(".py"):
from tactic.command import PythonCmd
cmd = PythonCmd(file_path=path)
manifest = cmd.execute()
if not manifest:
print "No manifest discovered in [%s]" %path
return
xml = Xml()
xml.read_string(manifest)
nodes = xml.get_nodes("manifest/*")
sobjects = []
for i, node in enumerate(nodes):
name = my.xml.get_node_name(node)
if name == 'sobject':
dumped_sobjects = my.handle_sobject(node)
if not dumped_sobjects:
dumped_sobjects = []
sobjects.extend(dumped_sobjects)
elif name == 'search_type':
my.handle_search_type(node)
elif name == 'include':
my.handle_include(node)
示例8: add_attr_access
def add_attr_access(self, search_type, attr, level):
# find the group
group_xpath = "rules/group[@key='%s']" % (search_type)
group = self.xml.get_node(group_xpath)
if group == None:
# add the group (default to view)
group_level = "view"
group = self.add_sobject_access(search_type,group_level)
# get the attr rule
rule_xpath = "rules/group[@key='%s']/rule[@key='%s']" % (search_type,attr)
rule = self.xml.get_node(rule_xpath )
if rule != None:
# if nothing has changed, continue
access = Xml.get_attribute(rule,"access")
if level == access:
raise CommandExitException()
else:
rule = self.xml.create_element("rule")
rule.setAttributeNS(None,"key",attr)
#group.appendChild(rule)
Xml.append_child(group, rule)
#self.root.appendChild(group)
Xml.append_child(self.root, group)
# set the access level
rule.setAttributeNS(None,"type","attr")
rule.setAttributeNS(None,"access",level)
示例9: execute
def execute(my):
database = "sthpw"
sql = DbContainer.get(database)
value_array = sql.do_query("select code, cc from (select code, count(code) as cc from file group by code order by cc desc) as X where cc > 1;")
#value_array = sql.do_query("select code, cc from (select code, count(code) as cc from file group by code order by cc desc) as X;")
print "found [%s] pairs" % len(value_array)
for count, value_list in enumerate(value_array):
if count >= BATCH:
break
# get the file object
file_code = value_list[0]
search = Search("sthpw/file")
search.add_filter("code", file_code)
files = search.get_sobjects()
#if len(files) == 1:
# continue
for file in files:
project_code = file.get_value("project_code")
if not project_code:
print "WARNING: file [%s] has no project_code" % file_code
continue
project = Project.get_by_code(project_code)
initials = project.get_initials()
id = file.get_id()
new_file_code = "%s%s" % (id, initials)
if file_code == new_file_code:
continue
print "-"*20
print "switching: ", file_code, "to", new_file_code
snapshot_code = file.get_value("snapshot_code")
snapshot = Snapshot.get_by_code(snapshot_code)
assert snapshot
snapshot_xml = snapshot.get_xml_value("snapshot")
print snapshot_xml.to_string()
node = snapshot_xml.get_node("snapshot/file[@file_code='%s']" % file_code)
Xml.set_attribute(node, "file_code", new_file_code)
print snapshot_xml.to_string()
assert node
# set the file_code
file.set_value("code", new_file_code)
file.commit()
# set the snapshot
snapshot.set_value("snapshot", snapshot_xml.to_string() )
snapshot.commit()
示例10: get_config
def get_config(my):
# TEST
config_xml = '''
<config>
<custom_filter>
<element name='asset_library'>
<display class='SelectWdg'>
<query>prod/asset_library|code|code</query>
<empty>true</empty>
</display>
</element>
<element name='pipeline_code'>
<display class='SelectWdg'>
<query>sthpw/pipeline|code|code</query>
<empty>true</empty>
</display>
</element>
</custom_filter>
</config>
'''
my.view = my.kwargs.get("search_view")
if not my.view:
my.view = 'custom_filter'
#view = "custom_filter"
project_code = Project.extract_project_code(my.search_type)
search = Search("config/widget_config", project_code=project_code )
search.add_filter("view", my.view)
search.add_filter("search_type", my.base_search_type)
config_sobj = search.get_sobject()
if config_sobj:
config_xml = config_sobj.get_value("config")
else:
config_xml = '''
<config>
<custom_filter>
</custom_filter>
</config>
'''
# use the one defined in the default config file
file_configs = WidgetConfigView.get_configs_from_file(my.base_search_type, my.view)
if file_configs:
config = file_configs[0]
xml_node = config.get_view_node()
if xml_node is not None:
xml = Xml(config.get_xml().to_string())
config_xml = '<config>%s</config>' %xml.to_string(node=xml_node)
from pyasm.widget import WidgetConfig
config = WidgetConfig.get(view=my.view, xml=config_xml)
return config
示例11: get_plugin_data
def get_plugin_data(my, reldir):
manifest_path = "%s/%s/manifest.xml" % (my.base_dir, reldir)
xml = Xml()
xml.read_file(manifest_path)
node = xml.get_node("manifest/data")
data = xml.get_node_values_of_children(node)
return data
示例12: handle_config
def handle_config(my):
web = WebContainer.get_web()
search_type = my.kwargs.get("search_type")
view = my.view
config_search_type = "config/widget_config"
search = Search(config_search_type)
search.add_filter("search_type", search_type)
search.add_filter("view", view)
search.add_filter("login", my.login)
config = search.get_sobject()
if not config:
config = SearchType.create(config_search_type)
config.set_value("search_type", search_type )
config.set_value("view", view )
if my.login:
config.set_value("login", my.login )
xml = config.get_xml_value("config", "config")
root = xml.get_root_node()
# reinitialize
config._init()
# build a new config
view_node = xml.create_element(view)
root.appendChild(view_node)
config_mode = web.get_form_value("config_mode")
if config_mode == "advanced":
config_string = web.get_form_value("config_xml")
else:
config_title = web.get_form_value("config_title")
config_icon = web.get_form_value("config_icon")
config_icon2 = web.get_form_value("config_icon2")
if config_icon2:
config_icon = config_icon2
# TAKEN FROM API: should be centralized or something
from tactic.ui.panel import SideBarBookmarkMenuWdg
config_view = SideBarBookmarkMenuWdg.get_config(search_type, view)
node = config_view.get_element_node(my.element_name)
if node:
config_xml = config_view.get_xml()
node = config_view.get_element_node(my.element_name)
Xml.set_attribute(node, "title", config_title)
Xml.set_attribute(node, "icon", config_icon)
config_string = config_xml.to_string(node)
else:
config_string = '''
<element name="%s" title="%s" icon="%s"/>
''' %(my.element_name, config_title, config_icon)
config.append_xml_element(my.element_name, config_string)
config.commit_config()
示例13: _read_ref_file
def _read_ref_file(my):
'''read the reference file containing extra node information'''
dir = my.get_upload_dir()
xml = Xml()
key = my.sobject.get_code()
# make this filename good for the file system
filename = File.get_filesystem_name(key)
xml.read_file( "%s/%s-ref.xml" % (dir,filename) )
return xml
示例14: get_config
def get_config(self):
self.view = self.kwargs.get("search_view")
config = self.kwargs.get("search_config")
if not self.view:
self.view = 'custom_filter'
#view = "custom_filter"
project_code = Project.extract_project_code(self.search_type)
search = Search("config/widget_config", project_code=project_code )
search.add_filter("view", self.view)
search.add_filter("search_type", self.base_search_type)
config_sobjs = search.get_sobjects()
from pyasm.search import WidgetDbConfig
config_sobj = WidgetDbConfig.merge_configs(config_sobjs)
if config_sobj:
#config_xml = config_sobj.get("config")
config_xml = config_sobj.get_xml().to_string()
config_xml = config_xml.replace("<", "<")
config_xml = config_xml.replace(">", ">")
config_xml = Common.run_mako(config_xml)
elif config:
config_xml = '''
<config>
<custom_filter>%s
</custom_filter>
</config>
''' % config
else:
config_xml = '''
<config>
<custom_filter>
</custom_filter>
</config>
'''
# use the one defined in the default config file
file_configs = WidgetConfigView.get_configs_from_file(self.base_search_type, self.view)
if file_configs:
config = file_configs[0]
xml_node = config.get_view_node()
if xml_node is not None:
xml = Xml(config.get_xml().to_string())
config_xml = '<config>%s</config>' %xml.to_string(node=xml_node)
from pyasm.widget import WidgetConfig
config = WidgetConfig.get(view=self.view, xml=config_xml)
return config
示例15: _test_guest_allow
def _test_guest_allow(self):
'''test Config tag allow_guest in security tag.
Note: Since it is hard to emulate AppServer class,
this is based on logic which handles in _get_display
of BaseAppServer.
1. If allow_guest is false, then it is necessary that
Sudo is instantiated.
2. If allow_guest is true, then it is necessary that
guest login rules are added and login_as_guest is
executed.
'''
security = Security()
Environment.set_security(security)
#1. allow_guest is false
fail = False
try:
sudo = Sudo()
except Exception as e:
fail = True
self.assertEquals( False, fail )
sudo.exit()
key = [{'code': "*"}]
project_access = security.check_access("project", key, "allow")
self.assertEquals(project_access, False)
#2. allow_guest is true
Site.set_site("default")
try:
security.login_as_guest()
ticket_key = security.get_ticket_key()
access_manager = security.get_access_manager()
xml = Xml()
xml.read_string('''
<rules>
<rule column="login" value="{$LOGIN}" search_type="sthpw/login" access="deny" op="!=" group="search_filter"/>
<rule group="project" code="default" access="allow"/>
</rules>
''')
access_manager.add_xml_rules(xml)
finally:
Site.pop_site()
default_key = [{'code': "default"}]
project_access = security.check_access("project", default_key, "allow")
self.assertEquals(project_access, True)
unittest_key = [{'code', "sample3d"}]
project_access = security.check_access("project", unittest_key, "allow")
self.assertEquals(project_access, False)