initial cpmmit

This commit is contained in:
Super_JK
2022-03-05 21:48:39 +01:00
commit 26c2570680
24 changed files with 399 additions and 0 deletions

39
python/TP2.py Normal file
View File

@@ -0,0 +1,39 @@
from os import listdir
from os.path import isdir, isfile
from xml.dom import minidom
doc = minidom.parse('../xml/TP1.xml')
dico = doc.getElementsByTagName('dictionary')[0]
def printDico(dico, past):
for child in dico.childNodes:
if child.nodeType == child.ELEMENT_NODE:
val = child.getAttribute('value')
if len(child.childNodes) == 0:
print(past + val)
else:
printDico(child, past + val + "-")
# printDico(dico,'')
def dirToXml(path, doc, el):
for elem in listdir(path):
path_ = path + "/" + elem
if isfile(path_):
node = doc.createElement("file")
node.attributes["name"] = elem
el.appendChild(node)
elif isdir(path_):
node = doc.createElement("dir")
node.attributes["name"] = elem
el.appendChild(node)
dirToXml(path_, doc, node)
root = minidom.Document()
xml = root.createElement('root')
root.appendChild(xml)
dirToXml("/", root, root.getElementsByTagName("root")[0])
print(root.toprettyxml())