for creole's zephir2 branch
This commit is contained in:
55
tests/tools/add_to_dico.py
Normal file
55
tests/tools/add_to_dico.py
Normal file
@ -0,0 +1,55 @@
|
||||
from lxml import etree
|
||||
from os import listdir
|
||||
from os.path import join, isdir
|
||||
|
||||
|
||||
|
||||
|
||||
root_dir = '../flattener_dicos'
|
||||
|
||||
def xml_parse_document(document):
|
||||
families = document.xpath('variables/family')
|
||||
for family in families:
|
||||
if family.attrib['path'] == 'creole.containers':
|
||||
return
|
||||
family = etree.Element('family', hidden="True", icon="puzzle-piece", mode="expert", name="Containers", path="creole.containers")
|
||||
variable = etree.SubElement(family, 'variable', auto_freeze="False", auto_save="False", description="Bridge IP address", disabled="False", hidden="True", mandatory="False", mode="expert", multi="False", name="adresse_ip_br0", path="creole.containers.adresse_ip_br0", type="string")
|
||||
value = etree.SubElement(variable, 'value')
|
||||
value.text = '127.0.0.1'
|
||||
variable = etree.SubElement(family, 'variable', auto_freeze="False", auto_save="False", description="Bridge IP subnet mask", disabled="False", hidden="True", mandatory="False", mode="expert", multi="False", name="adresse_netmask_br0", path="creole.containers.adresse_netmask_br0", type="string")
|
||||
value = etree.SubElement(variable, 'value')
|
||||
value.text = '255.0.0.0'
|
||||
variable = etree.SubElement(family, 'variable', auto_freeze="False", auto_save="False", description="Bridge IP network_br0 address", disabled="False", hidden="True", mandatory="False", mode="expert", multi="False", name="adresse_network_br0", path="creole.containers.adresse_network_br0", type="string")
|
||||
value = etree.SubElement(variable, 'value')
|
||||
value.text = '127.0.0.0'
|
||||
variable = etree.SubElement(family, 'variable', auto_freeze="False", auto_save="False", description="Bridge broadcast IP address", disabled="False", hidden="True", mandatory="False", mode="expert", multi="False", name="adresse_broadcast_br0", path="creole.containers.adresse_broadcast_br0", type="string")
|
||||
value = etree.SubElement(variable, 'value')
|
||||
value.text = '127.255.255.255'
|
||||
elt = document.xpath('variables')[0]
|
||||
elt.insert(0, family)
|
||||
|
||||
|
||||
def edit(xmlfile):
|
||||
print('process {}'.format(xmlfile))
|
||||
document = etree.parse(xmlfile).getroot()
|
||||
xml_parse_document(document)
|
||||
with file(xmlfile, 'w') as fh:
|
||||
fh.write(etree.tostring(document, pretty_print=True, encoding="UTF-8"))
|
||||
|
||||
|
||||
def main():
|
||||
for xmldir in listdir(root_dir):
|
||||
xmldir = join(root_dir, xmldir)
|
||||
resultdir = join(xmldir, 'result')
|
||||
#if isdir(xmldir):
|
||||
# for dico in listdir(xmldir):
|
||||
# if dico.endswith('.xml'):
|
||||
# edit(join(xmldir, dico))
|
||||
if isdir(resultdir):
|
||||
for dico in listdir(resultdir):
|
||||
if dico.endswith('.xml'):
|
||||
edit(join(resultdir, dico))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
83
tests/tools/update_dico_attr.py
Normal file
83
tests/tools/update_dico_attr.py
Normal file
@ -0,0 +1,83 @@
|
||||
# coding: utf-8
|
||||
from lxml import etree
|
||||
from os import listdir
|
||||
from os.path import join, isdir
|
||||
|
||||
#update_attrs = {'family': {'hidden': 'False', 'mode': 'normal'},
|
||||
# 'variable': {'auto_freeze': 'False',
|
||||
# 'auto_save': 'False',
|
||||
# 'disabled': 'False',
|
||||
# 'hidden': 'False',
|
||||
# 'mandatory': 'False',
|
||||
# 'mode': 'normal',
|
||||
# 'multi': 'False',
|
||||
# 'remove_check': 'False',
|
||||
# 'remove_condition': 'False'},
|
||||
# 'param': {'hidden': 'True'},
|
||||
# 'separator': {'never_hidden': 'False'}
|
||||
# }
|
||||
#remove_attrs = {'param': ['optional'],
|
||||
# 'variable': ['redefine', 'exists']}
|
||||
#update_attrs = {'check': {'level': 'error'}}
|
||||
#remove_attrs = {'variable': ['remove_condition']}
|
||||
update_attrs = {'param': ['pouet']}
|
||||
remove_attrs = {}
|
||||
remove_tags = ()
|
||||
|
||||
root_dir = '../flattener_dicos'
|
||||
|
||||
def xml_parse_document(document):
|
||||
for child in document:
|
||||
if not isinstance(child.tag, str):
|
||||
continue
|
||||
#if child.tag in remove_tags:
|
||||
# etree.SubElement(document, 'containers')
|
||||
# print list(child)
|
||||
# #document.remove(child)
|
||||
# continue
|
||||
if child.tag in update_attrs:
|
||||
if child.attrib.get('type') == None:
|
||||
child.attrib['type'] = 'string'
|
||||
#for key, value in update_attrs[child.tag].items():
|
||||
# if key not in child.attrib:
|
||||
# child.attrib[key] = value
|
||||
if child.tag in remove_attrs:
|
||||
for key in remove_attrs[child.tag]:
|
||||
if key in child.attrib:
|
||||
del(child.attrib[key])
|
||||
#print(child.tag)
|
||||
#print(child.attrib)
|
||||
#if child.text is None:
|
||||
# text = None
|
||||
#else:
|
||||
# text = child.text.strip()
|
||||
#if text:
|
||||
# print(text)
|
||||
if list(child) != []:
|
||||
ret = xml_parse_document(child)
|
||||
|
||||
|
||||
def edit(xmlfile):
|
||||
print('process {}'.format(xmlfile))
|
||||
document = etree.parse(xmlfile).getroot()
|
||||
xml_parse_document(document)
|
||||
with file(xmlfile, 'w') as fh:
|
||||
fh.write(etree.tostring(document, pretty_print=True, encoding="UTF-8"))
|
||||
|
||||
|
||||
def main():
|
||||
for xmldir in listdir(root_dir):
|
||||
xmldir = join(root_dir, xmldir)
|
||||
resultdir = join(xmldir, 'result')
|
||||
#if isdir(xmldir):
|
||||
# for dico in listdir(xmldir):
|
||||
# if dico.endswith('.xml'):
|
||||
# edit(join(xmldir, dico))
|
||||
if isdir(resultdir):
|
||||
for dico in listdir(resultdir):
|
||||
if dico.endswith('.xml'):
|
||||
edit(join(resultdir, dico))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user