factor out the call to os.stat(); broken links

This commit is contained in:
Martin A. Brown 2016-02-17 11:31:08 -08:00
parent 9301a54ab2
commit 46edc205e0
1 changed files with 13 additions and 2 deletions

View File

@ -82,6 +82,17 @@ def makefh(thing):
return f
def statfile(name):
try:
st = os.stat(name)
except OSError as e:
if e.errno != errno.ENOENT:
raise e
if os.path.islink(name):
st = os.lstat(name)
return st
def statfiles(name, relative=None):
statinfo = dict()
if not os.path.isdir(name):
@ -89,7 +100,7 @@ def statfiles(name, relative=None):
relpath = os.path.relpath(name, start=relative)
else:
relpath = name
statinfo[relpath] = os.stat(name)
statinfo[relpath] = statfile(name)
else:
for root, dirs, files in os.walk(name):
for x in files:
@ -98,7 +109,7 @@ def statfiles(name, relative=None):
relpath = os.path.relpath(foundpath, start=relative)
else:
relpath = foundpath
statinfo[relpath] = os.stat(foundpath)
statinfo[relpath] = statfile(foundpath)
return statinfo