This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author zooko
Recipients draghuram, ggenellina, gvanrossum, ijmorlan, zooko
Date 2008-11-11.22:59:34
SpamBayes Score 0.00010988393
Marked as misclassified No
Message-id <1226444376.44.0.64147057752.issue1675@psf.upfronthosting.co.za>
In-reply-to
Content
Here's the version of this that I've been using for almost a decade now:

http://allmydata.org/trac/pyutil/browser/pyutil/pyutil/fileutil.py?rev=127#L241

Actually I used to have a bigger version that could optionally require
certain things of the mode of the directory, but it turned out that I
wasn't going to need it.

def make_dirs(dirname, mode=0777):
    """
    An idempotent version of os.makedirs().  If the dir already exists, do
    nothing and return without raising an exception.  If this call
creates the
    dir, return without raising an exception.  If there is an error that
    prevents creation or if the directory gets deleted after make_dirs()
creates
    it and before make_dirs() checks that it exists, raise an exception.
    """
    tx = None
    try:
        os.makedirs(dirname, mode)
    except OSError, x:
        tx = x

    if not os.path.isdir(dirname):
        if tx:
            raise tx
        raise exceptions.IOError, "unknown error prevented creation of
directory, or deleted the directory immediately after creation: %s" %
dirname # careful not to construct an IOError with a 2-tuple, as that
has a special meaning...
History
Date User Action Args
2008-11-11 22:59:36zookosetrecipients: + zooko, gvanrossum, ggenellina, draghuram, ijmorlan
2008-11-11 22:59:36zookosetmessageid: <1226444376.44.0.64147057752.issue1675@psf.upfronthosting.co.za>
2008-11-11 22:59:35zookolinkissue1675 messages
2008-11-11 22:59:34zookocreate