diff --git a/saucebrush/utils.py b/saucebrush/utils.py index d75b624..2085e7e 100644 --- a/saucebrush/utils.py +++ b/saucebrush/utils.py @@ -159,4 +159,31 @@ def dotted_key_set(dict_or_list, dotted_key, value, separator='.'): elif isinstance(dict_or_list, (tuple, list)): newkey = separator.join(keys[i:]) for item in dict_or_list: - dotted_key_set(item, newkey, value, separator) \ No newline at end of file + dotted_key_set(item, newkey, value, separator) + +# +# utility classes +# + +class Files(object): + + def __init__(self, file_open_callback=None, *args): + self.paths = [] + for arg in args: + self.add(arg) + self.file_open_callback = file_open_callback + + def add(self, path): + self.paths.append(path) + + def __iter__(self): + return self.linereader() + + def linereader(self): + for path in iter(self.paths): + if os.path.exists(path): + self.file_open_callback(path) + f = open(path) + for line in f: + yield line + f.close() \ No newline at end of file