From: Zac Medico <zmedico@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Subject: Re: [gentoo-portage-dev] [PATCH] unprivileged mode: generate PORTAGE_DEPCACHEDIR
Date: Mon, 10 Nov 2014 10:21:11 -0800 [thread overview]
Message-ID: <54610217.3080707@gentoo.org> (raw)
In-Reply-To: <54609D06.5020101@gentoo.org>
On 11/10/2014 03:09 AM, Alexander Berntsen wrote:
> On 10/11/14 00:24, Zac Medico wrote:
>> ir
>> + while current_dir != os.sep:
>> + try:
>> + st = os.stat(current_dir)
>> + except OSError as e:
>> + if errno == errno.ENOENT:
>> + current_dir = \
>> + os.path.dirname(current_dir)
>> + continue
>> + break
> Can you think of a less terrible way of doing this in Python?
Well, you'll have to clarify what's so "terrible" about it. Note that I didn't
use os.path.isdir or similar because those functions hide all kinds of relevant
exceptions, such as EACCES.
If it's the continue and break that upset you, we can do it like this:
found_dir = False
while current_dir != os.sep and not found_dir:
try:
os.stat(current_dir)
found_dir = True
except OSError:
if errno == errno.ENOENT:
current_dir = \
os.path.dirname(current_dir)
else:
found_dir = True
--
Thanks,
Zac
next prev parent reply other threads:[~2014-11-10 18:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-09 23:24 [gentoo-portage-dev] [PATCH] unprivileged mode: generate PORTAGE_DEPCACHEDIR Zac Medico
2014-11-10 4:58 ` [gentoo-portage-dev] " Duncan
2014-11-10 5:28 ` Zac Medico
2014-11-10 6:06 ` Duncan
2014-11-10 11:09 ` [gentoo-portage-dev] " Alexander Berntsen
2014-11-10 18:21 ` Zac Medico [this message]
2014-11-10 20:32 ` Alexander Berntsen
2014-11-11 0:17 ` Zac Medico
2014-11-11 9:14 ` Alexander Berntsen
2014-11-15 5:19 ` Zac Medico
2014-11-15 7:21 ` [gentoo-portage-dev] [PATCH] unprivileged mode: use first_existing helper func Zac Medico
2014-11-17 8:12 ` Alexander Berntsen
2014-11-10 20:48 ` [gentoo-portage-dev] [PATCH v2] unprivileged mode: generate PORTAGE_DEPCACHEDIR Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54610217.3080707@gentoo.org \
--to=zmedico@gentoo.org \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox