From 4a91a43d6e90299cf8daf326bc8e8beab751570c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= Date: Wed, 27 Apr 2016 11:01:26 +0200 Subject: [PATCH] Add 'title' command. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds a 'title' command to make it easier to add titles to images. It basically takes an image filename and a title, and will write a corresponding .md file with the Title attribute. Signed-off-by: Toke Høiland-Jørgensen --- sigal/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sigal/__init__.py b/sigal/__init__.py index 91ec6e6..5b67295 100644 --- a/sigal/__init__.py +++ b/sigal/__init__.py @@ -223,3 +223,23 @@ def serve(destination, port, config): httpd.serve_forever() except KeyboardInterrupt: print('\nAll done!') + +@main.command() +@argument('image') +@argument('title') +@option('-f', '--force', default=False, is_flag=True, + help='Overwrite existing .md file') +def title(image, title, force=False): + "Write image title to corresponding .md file" + + if not os.path.exists(image): + sys.stderr.write("The image {} does not exist.\n".format(image)) + sys.exit(1) + descfile = os.path.splitext(image)[0] + '.md' + if os.path.exists(descfile) and not force: + sys.stderr.write("Description file for {} already exists. " + "Use --force to overwrite it.\n".format(image)) + sys.exit(2) + + with open(descfile, "w") as fp: + fp.write("Title: {}\n".format(title))