diff options
author | James Vasile <james@hackervisions.org> | 2011-12-16 23:42:29 -0500 |
---|---|---|
committer | James Vasile <james@jamesvasile.com> | 2012-02-19 15:07:14 -0500 |
commit | 02baab57a0db113fecc32d05a4390e9fa7ff5810 (patch) | |
tree | 3b6802e67aca50c6d0fd9e2762993df667716abe /util.py | |
parent | bc8887e8b645bb46ab50ac342acfd494a9236531 (diff) |
mkdir
Diffstat (limited to 'util.py')
-rw-r--r-- | util.py | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -1,9 +1,27 @@ -import sys +import os, sys import cherrypy import cfg import sqlite3 from filedict import FileDict +def mkdir(newdir): + """works the way a good mkdir should :) + - already exists, silently complete + - regular file in the way, raise an exception + - parent directory(ies) does not exist, make them as well + """ + if os.path.isdir(newdir): + pass + elif os.path.isfile(newdir): + raise OSError("a file with the same name as the desired " \ + "dir, '%s', already exists." % newdir) + else: + head, tail = os.path.split(newdir) + if head and not os.path.isdir(head): + mkdir(head) + #print "mkdir %s" % repr(newdir) + if tail: + os.mkdir(newdir) def is_string(obj): isinstance(obj, basestring) def is_ascii(s): |