- 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

@ -754,6 +754,7 @@ class Main:
else: else:
method = None method = None
method_display_name = "<y>%s<.>" %(method_name) method_display_name = "<y>%s<.>" %(method_name)
if method_name == "<module>": if method_name == "<module>":
method_type = "module" method_type = "module"
else: else:

View file

@ -3,6 +3,10 @@
# -------------------------------------------------- # --------------------------------------------------
import os
# --------------------------------------------------
def boolean(arg): def boolean(arg):
""" """
Converts Converts
@ -48,3 +52,29 @@ def strings(*args):
out.append(str(arg)) out.append(str(arg))
return out 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

View file

@ -4,7 +4,6 @@
# -------------------------------------------------- # --------------------------------------------------
# Library imports # Library imports
import over import over
prefix = over.text.prefix
# -------------------------------------------------- # --------------------------------------------------
# Local imports # Local imports
@ -25,10 +24,9 @@ class ConfigurationError(Exception):
# -------------------------------------------------- # --------------------------------------------------
if __name__ == "__main__": if __name__ == "__main__":
main = over.app.Main("short-name", "Human Readable Name", version.str, "LICENSE", use_cfg_file=False) main = over.app.Main("app-name", version.str, "LICENSE", features={"config_file": False})
main.add_option("option", "type", "default", "Description.", short_name="s") main.add_option("option", "What the option does.", str, ["default"], count=1, abbr="o")
main.add_help("Description", ["What it does.", "Another paragraph."]) main.add_doc("Description", ["What it does.", "Another paragraph."])
main.enable_help("h") main.setup()
main.parse()
... ...