- added a directory callback

- updated the template (fixes #11)
This commit is contained in:
Martinez 2016-10-10 16:52:59 +02:00
parent 8996bb9d04
commit 16770b209c
3 changed files with 35 additions and 6 deletions

View file

@ -3,6 +3,10 @@
# --------------------------------------------------
import os
# --------------------------------------------------
def boolean(arg):
"""
Converts
@ -48,3 +52,29 @@ def strings(*args):
out.append(str(arg))
return out
def directory(exists=False, writable=False, gio=False):
"""
Returns a directory callback that raises hell if:
- the supplied directory doesn't exist and `exists` is True
- isn't writable and `writable` is True
- isn't a valid Gio path and `gio` is True
@while generating a callback
"""
if gio:
raise NotImplementedError("Gio support is not yet here")
def cb(arg):
path = os.path.abspath(os.path.expanduser(arg))
if not os.path.isdir(path) and exists:
raise FileNotFoundError("%s (%s) does not exist" %(arg, path))
if writable and not os.access(path, os.W_OK | os.X_OK):
raise PermissionError("%s exists but is not writable" %(arg))
return path
return cb