<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 01/10/13 15:18, Chris Larson wrote:
<blockquote
cite="mid:CABcZANnD8C4gZXEcRWfR8f_ftZjndOT9UJ5796SEigRqw6tohA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Jan 10, 2013 at 7:11 AM,
Chris Larson <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:clarson@kergoth.com" target="_blank">clarson@kergoth.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="adM">
<div class="h5"><br>
<div class="gmail_quote">On Thu, Jan 10, 2013 at 7:10
AM, Chris Larson <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:clarson@kergoth.com"
target="_blank">clarson@kergoth.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div class="gmail_quote">On Thu, Jan 10, 2013 at
1:46 AM, Martin Ertsaas <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:martiert@gmail.com"
target="_blank">martiert@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote"
style="margin:0 0 0 .8ex;border-left:1px
#ccc solid;padding-left:1ex">
<div>On mac, os.unlink does not remove
directories, and we therefor have<br>
to explicitly use shutil.rmtree if the
path is a directory.<br>
---<br>
lib/bb/utils.py | 5 ++++-<br>
1 file changed, 4 insertions(+), 1
deletion(-)<br>
<br>
diff --git a/lib/bb/utils.py
b/lib/bb/utils.py<br>
index cef0fdd..8b6d3f5 100644<br>
--- a/lib/bb/utils.py<br>
+++ b/lib/bb/utils.py<br>
@@ -561,7 +561,10 @@ def remove(path,
recurse=False):<br>
import os, errno, shutil, glob<br>
for name in glob.glob(path):<br>
try:<br>
- os.unlink(name)<br>
+ if os.path.isdir(name):<br>
+ shutil.rmtree(name)<br>
+ else:<br>
+ os.unlink(name)<br>
except OSError as exc:<br>
if recurse and exc.errno ==
errno.EISDIR:<br>
shutil.rmtree(name)</div>
</blockquote>
</div>
<br>
<br>
</div>
Look 2 lines down, where it checks to see if the
os.unlink failed due to it being a directory and
runs shutil.rmtree if that's the case.</blockquote>
</div>
<br>
</div>
</div>
I'm guessing you're trying to use it without passing
recurse=True.</blockquote>
</div>
<br>
Having through about it further, I think it might be best to
be alter the code to also handle the case where recurse==False
and the path is a directory by calling os.rmdir(). Perhaps
this would reduce confusion.<br>
-- <br>
Christopher Larson</div>
</div>
</blockquote>
You think to recursively call remove on the children of the
directory? Wouldn't something like:<br>
<br>
for name in glob.glob(path):<br>
if os.path.isdir(name) and recurse:<br>
shutil.rmtree(name)<br>
elif os.path.isdir(name):<br>
os.rmdir(name)<br>
else:<br>
os.unlink(name)<br>
<br>
Then we will possibly get an exception from os.rmdir, which we can
catch. But this also avoids the need to use the exception as a
control flow structure as it is used today.<br>
<br>
At least in my mind, that is a lot easier to grasp than the if
statement in the exception handling, which I totally overlooked as
it is an exception.<br>
<br>
- Martin<br>
</body>
</html>