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

Final commit

parent 3e8506b8
Branches
No related tags found
No related merge requests found
......@@ -18,12 +18,14 @@ def checkType(foo, dirXML):
stat.S_ISFIFO : 'fifo' ,
stat.S_ISSOCK : 'sock'
}
try:
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
except FileNotFoundError:
dirXML.write(f'\t\t<file>{foo}</file>\n')
......@@ -35,17 +37,20 @@ def drop(top):
for root, dirs, files in os.walk(top):
os.chdir(root)
currentDir = os.getcwd()
print(f'Currently walking through {currentDir}')
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 README! \n Parsing README ...')
print('Found README! \n Parsing README ...\n\n')
#if exist README in that folder
RM = open('README', 'r')
line_list = RM.readlines()
RM.close()
required = []
index = []
for l in line_list:
w = l.split(':')
......@@ -61,12 +66,14 @@ def drop(top):
required=w[1:(len(w)-1)]
required.append(last)
if len(index) > 0:
dirXML.write('\t<index>\n')
for i in index:
dirXML.write(f'\t\t<file>{i}</file>\n')
dirXML.write('\t</index>\n')
if len(required) > 0:
dirXML.write('\t<required>\n')
for r in required:
checkType(r, dirXML)
......@@ -74,9 +81,11 @@ def drop(top):
dirXML.write('\t<other>\n')
for f in files:
if (f not in required) and (f not in index) and (str(f) != 'dir.xml'):
checkType(f, dirXML)
for d in dirs:
if (f not in required) and (f not in index):
checkType(d, dirXML)
......@@ -84,11 +93,13 @@ def drop(top):
else:
print('Uh uh, no README for you! All files will go to section "others"')
print('Uh uh, no README for you! All files will go to section "others"\n\n')
dirXML.write('\t<other>\n')
for root, dirs, files in os.walk(currentDir):
for f in files:
if str(f) != 'dir.xml':
checkType(f, dirXML)
for d in dirs:
checkType(d, dirXML)
dirXML.write('\t</other>\n')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment