summaryrefslogtreecommitdiff
path: root/util.py
diff options
context:
space:
mode:
authorJames Vasile <james@hackervisions.org>2011-12-16 23:42:29 -0500
committerJames Vasile <james@jamesvasile.com>2012-02-19 15:07:14 -0500
commit02baab57a0db113fecc32d05a4390e9fa7ff5810 (patch)
tree3b6802e67aca50c6d0fd9e2762993df667716abe /util.py
parentbc8887e8b645bb46ab50ac342acfd494a9236531 (diff)
mkdir
Diffstat (limited to 'util.py')
-rw-r--r--util.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/util.py b/util.py
index 11bb647..e43af83 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):