mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
32 lines
826 B
Python
32 lines
826 B
Python
import os
|
|
|
|
|
|
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 slurp(filespec):
|
|
with open(filespec) as x: f = x.read()
|
|
return f
|
|
|
|
|
|
def unslurp(filespec, msg):
|
|
with open(filespec, 'w') as x:
|
|
x.write(msg)
|