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

functional but not pretty (not tested with socket and pipe)

parent 8aac706b
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
#
# Created by Hanh Do Phung
#
# NOTE: This program iterates through a directory and leave a file "dir.xml" at each subdirectory
# The content of dir.xml is a listing of the files in that folder divided in groups: index, required, and others
# The file type of each is also specified
import sys
import os
import stat
top = sys.argv[1]
IND = ' '
os.chdir(top)
rootPath = os.getcwd()
def checkType(foo):
def checkType(foo, dirXML):
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'
}
......@@ -30,6 +27,11 @@ def checkType(foo):
def drop(top):
os.chdir(top)
rootPath= os.getcwd()
for root, dirs, files in os.walk(top):
os.chdir(root)
currentDir = os.getcwd()
......@@ -67,15 +69,15 @@ for root, dirs, files in os.walk(top):
dirXML.write('\t<required>\n')
for r in required:
checkType(r)
checkType(r, dirXML)
dirXML.write('\t</required>\n')
dirXML.write('\t<other>\n')
for f in files:
checkType(f)
checkType(f, dirXML)
for d in dirs:
checkType(d)
checkType(d, dirXML)
dirXML.write('\t</other>\n')
......@@ -86,10 +88,24 @@ for root, dirs, files in os.walk(top):
dirXML.write('\t<other>\n')
for root, dirs, files in os.walk(currentDir):
for f in files:
checkType(f)
checkType(f, dirXML)
dirXML.write('\t</other>\n')
dirXML.write('</direntry>\n')
dirXML.close()
os.chdir(rootPath)
if len(sys.argv) > 1:
os.chdir(sys.argv[1])
top = os.getcwd()
print('Taken in the provided directory. Processing . . .\n')
drop(top)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment