diff --git a/util.py b/util.py index 11bb647e0..e43af8371 100644 --- a/util.py +++ b/util.py @@ -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):