Skip to content
Snippets Groups Projects
Commit 8aac706b authored by hdd29's avatar hdd29
Browse files

Works fine with directories and regular files, need more testing with sockets and named pipes

parent 7635929f
Branches
No related tags found
No related merge requests found
assn2/dropXml.py 100644 → 100755
......@@ -2,29 +2,94 @@
import sys
import os
import stat
top = sys.argv[1]
IND = ' '
os.chdir(top)
rootPath = os.getcwd()
def checkType(foo):
tests = {
stat.S_ISREG : 'file' ,
stat.S_ISDIR : 'dir' ,
# stat.S_ISLNK : 'Soft Link' , # TODO Not working
stat.S_ISFIFO : 'fifo' ,
stat.S_ISSOCK : 'sock'
}
mode = os.stat(foo)[stat.ST_MODE]
for t, n in tests.items():
if t(mode):
dirXML.write(f'\t\t<{n}>{foo}</{n}>\n')
break
for root, dirs, files in os.walk(top):
os.chdir(root)
currentDir = os.getcwd()
exists = os.path.isfile(str(currentDir)+ '/README')
dirXML=open('dir.xml', 'w')
dirXML.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n<direntry>\n')
if exists:
print('Found it!')
else:
print('Uh uh, no REDME for you!')
os.chdir(rootPath)
print('Found README! \n Parsing README ...')
#if exist README in that folder
RM = open('README', 'r')
line_list = RM.readlines()
RM.close()
def createDirXML():
dirXML=open('dir.xml', 'w+')
dirXML.close()
with open('dir.xml', 'a') as dirXML:
dirXML.write('<?xml version="1.0" encoding="ISO-8859-1"?> \n <direntry>')
#if exist README in that folder
for l in line_list:
w = l.split(':')
if str(w[0]) == 'index':
last=w[-1].strip('\n')
index=w[1:(len(w)-1)]
index.append(last)
elif str(w[0]) == 'required':
w[-1].strip('\n')
last=w[-1].strip('\n')
required=w[1:(len(w)-1)]
required.append(last)
dirXML.write('\t<index>\n')
for i in index:
dirXML.write(f'\t\t<file>{i}</file>\n')
dirXML.write('\t</index>\n')
dirXML.write('\t<required>\n')
for r in required:
checkType(r)
dirXML.write('\t</required>\n')
dirXML.write('\t<other>\n')
for f in files:
checkType(f)
for d in dirs:
checkType(d)
dirXML.write('\t</other>\n')
else:
print('Uh uh, no README for you! All files will go to section "others"')
dirXML.write('\t<other>\n')
for root, dirs, files in os.walk(currentDir):
for f in files:
checkType(f)
dirXML.write('\t</other>\n')
dirXML.write('</direntry>\n')
dirXML.close()
os.chdir(rootPath)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment