[mod] more explicit error message

This commit is contained in:
Laurent Peuch 2015-12-08 08:06:47 +01:00
parent 83915ebfa3
commit 218e970602

View File

@ -16,11 +16,12 @@ def error(test, error_message):
if not test: if not test:
sys.stderr.write(error_message) sys.stderr.write(error_message)
sys.stderr.write("\n") sys.stderr.write("\n")
sys.stderr.write("Abort.\n")
sys.exit(1) sys.exit(1)
def main(): def main():
error(os.path.exists(os.path.join(os.getcwd(), "settings.yaml")), "I can't find a settings.yaml in the current working directory, abort") error(os.path.exists(os.path.join(os.getcwd(), "settings.yaml")), "I can't find a settings.yaml in the current working directory")
settings = yaml.safe_load(open("settings.yaml", "r")) settings = yaml.safe_load(open("settings.yaml", "r"))
@ -33,12 +34,12 @@ def main():
dirs = filter(lambda x: x not in (".", "..") and os.path.isdir(x) and os.path.exists(os.path.join(os.getcwd(), x, "settings.yaml")), os.listdir(os.getcwd())) dirs = filter(lambda x: x not in (".", "..") and os.path.isdir(x) and os.path.exists(os.path.join(os.getcwd(), x, "settings.yaml")), os.listdir(os.getcwd()))
error(dirs, "I can't find at least one directory with a settings.yaml in the current working directory, you don't have any gallery?\nAbort") error(dirs, "I can't find at least one directory with a settings.yaml in the current working directory, you don't have any gallery?")
for gallery in dirs: for gallery in dirs:
gallery_settings = yaml.safe_load(open(os.path.join(os.getcwd(), gallery, "settings.yaml")), "r") gallery_settings = yaml.safe_load(open(os.path.join(os.getcwd(), gallery, "settings.yaml"), "r"))
error(isinstance(gallery_settings, dict), "Your settings.yaml should be a dict") error(isinstance(gallery_settings, dict), "Your %s should be a dict" % (os.path.join(gallery, "settings.yaml")))
error(gallery_settings.get("title"), "You should specify a title in %s" % (os.path.join(gallery, "settings.yaml"))) error(gallery_settings.get("title"), "You should specify a title in %s" % (os.path.join(gallery, "settings.yaml")))
error(gallery_settings.get("cover"), "You should specify a path to a cover picture in %s" % (os.path.join(gallery, "settings.yaml"))) error(gallery_settings.get("cover"), "You should specify a path to a cover picture in %s" % (os.path.join(gallery, "settings.yaml")))