Convert '.' and '..' to the less magical os.curdir and os.pardir

While I'm cleaning up path manipulation, I might as well make things
more semantic.
This commit is contained in:
W. Trevor King 2013-03-11 08:25:47 -04:00
commit b59da89e80
10 changed files with 19 additions and 16 deletions

View file

@ -306,9 +306,9 @@ def get_relative_path(path):
"""Return the relative path from the given path to the root path."""
nslashes = path.count('/')
if nslashes == 0:
return '.'
return os.curdir
else:
return '/'.join(['..'] * nslashes)
return '/'.join([os.pardir] * nslashes)
def truncate_html_words(s, num, end_text='...'):
@ -429,7 +429,7 @@ def files_changed(path, extensions, ignores=[]):
def file_times(path):
"""Return the last time files have been modified"""
for root, dirs, files in os.walk(path):
dirs[:] = [x for x in dirs if x[0] != '.']
dirs[:] = [x for x in dirs if x[0] != os.curdir]
for f in files:
if any(f.endswith(ext) for ext in extensions) \
and not any(fnmatch.fnmatch(f, ignore)