Commit d1e46146 authored by Łukasz Nowak's avatar Łukasz Nowak

recipe/readline: Add when-absent feature

Allows to use recipe for cases when file is not present yet so it can return
some default (marker-like) value.
parent b5cd5f6d
...@@ -43,13 +43,14 @@ class Recipe(object): ...@@ -43,13 +43,14 @@ class Recipe(object):
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
storage_path = options['storage-path'] storage_path = options['storage-path']
when_absent = options.get('when-absent', None)
try: try:
with open(storage_path) as f: with open(storage_path) as f:
readline = f.readline() readline = f.readline()
except IOError as e: except IOError as e:
if e.errno != errno.ENOENT: if e.errno != errno.ENOENT:
raise raise
readline = None readline = when_absent
self.readline = readline self.readline = readline
options['readline'] = readline options['readline'] = readline
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment