mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
mkdir
This commit is contained in:
parent
bc8887e8b6
commit
02baab57a0
20
util.py
20
util.py
@ -1,9 +1,27 @@
|
|||||||
import sys
|
import os, sys
|
||||||
import cherrypy
|
import cherrypy
|
||||||
import cfg
|
import cfg
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from filedict import FileDict
|
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):
|
def is_string(obj):
|
||||||
isinstance(obj, basestring)
|
isinstance(obj, basestring)
|
||||||
def is_ascii(s):
|
def is_ascii(s):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user