Commit 96182d7b authored by Greg Ward's avatar Greg Ward

Fixed 'mkpath()' to accept empty string silently (it's just the current dir).

Fixed all DistutilsFileError messages to wrap file/dir names in quotes.
parent 63c2b250
...@@ -39,7 +39,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0): ...@@ -39,7 +39,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
name = os.path.normpath (name) name = os.path.normpath (name)
if os.path.isdir (name): if os.path.isdir (name) or name == '':
return return
if PATH_CREATED.get (name): if PATH_CREATED.get (name):
return return
...@@ -71,7 +71,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0): ...@@ -71,7 +71,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
try: try:
os.mkdir (head) os.mkdir (head)
except os.error, (errno, errstr): except os.error, (errno, errstr):
raise DistutilsFileError, "%s: %s" % (head, errstr) raise DistutilsFileError, "'%s': %s" % (head, errstr)
PATH_CREATED[head] = 1 PATH_CREATED[head] = 1
...@@ -197,19 +197,21 @@ def _copy_file_contents (src, dst, buffer_size=16*1024): ...@@ -197,19 +197,21 @@ def _copy_file_contents (src, dst, buffer_size=16*1024):
try: try:
fsrc = open(src, 'rb') fsrc = open(src, 'rb')
except os.error, (errno, errstr): except os.error, (errno, errstr):
raise DistutilsFileError, "could not open %s: %s" % (src, errstr) raise DistutilsFileError, \
"could not open '%s': %s" % (src, errstr)
try: try:
fdst = open(dst, 'wb') fdst = open(dst, 'wb')
except os.error, (errno, errstr): except os.error, (errno, errstr):
raise DistutilsFileError, "could not create %s: %s" % (dst, errstr) raise DistutilsFileError, \
"could not create '%s': %s" % (dst, errstr)
while 1: while 1:
try: try:
buf = fsrc.read (buffer_size) buf = fsrc.read (buffer_size)
except os.error, (errno, errstr): except os.error, (errno, errstr):
raise DistutilsFileError, \ raise DistutilsFileError, \
"could not read from %s: %s" % (src, errstr) "could not read from '%s': %s" % (src, errstr)
if not buf: if not buf:
break break
...@@ -218,7 +220,7 @@ def _copy_file_contents (src, dst, buffer_size=16*1024): ...@@ -218,7 +220,7 @@ def _copy_file_contents (src, dst, buffer_size=16*1024):
fdst.write(buf) fdst.write(buf)
except os.error, (errno, errstr): except os.error, (errno, errstr):
raise DistutilsFileError, \ raise DistutilsFileError, \
"could not write to %s: %s" % (dst, errstr) "could not write to '%s': %s" % (dst, errstr)
finally: finally:
if fdst: if fdst:
...@@ -258,7 +260,7 @@ def copy_file (src, dst, ...@@ -258,7 +260,7 @@ def copy_file (src, dst,
if not os.path.isfile (src): if not os.path.isfile (src):
raise DistutilsFileError, \ raise DistutilsFileError, \
"can't copy %s: not a regular file" % src "can't copy '%s': not a regular file" % src
if os.path.isdir (dst): if os.path.isdir (dst):
dir = dst dir = dst
...@@ -321,7 +323,7 @@ def copy_tree (src, dst, ...@@ -321,7 +323,7 @@ def copy_tree (src, dst,
if not dry_run and not os.path.isdir (src): if not dry_run and not os.path.isdir (src):
raise DistutilsFileError, \ raise DistutilsFileError, \
"cannot copy tree %s: not a directory" % src "cannot copy tree '%s': not a directory" % src
try: try:
names = os.listdir (src) names = os.listdir (src)
except os.error, (errno, errstr): except os.error, (errno, errstr):
...@@ -329,7 +331,7 @@ def copy_tree (src, dst, ...@@ -329,7 +331,7 @@ def copy_tree (src, dst,
names = [] names = []
else: else:
raise DistutilsFileError, \ raise DistutilsFileError, \
"error listing files in %s: %s" % (src, errstr) "error listing files in '%s': %s" % (src, errstr)
if not dry_run: if not dry_run:
mkpath (dst, verbose=verbose) mkpath (dst, verbose=verbose)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment