Created
July 22, 2015 06:27
-
-
Save mattgathu/9e5523b9f739a675afd1 to your computer and use it in GitHub Desktop.
Python logs file names and contents generators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gen_log_files(): | |
"""Generate log files names""" | |
for root, _, files in os.walk(DEFAULT_LOG_DIR): | |
for name in files: | |
if is_pref_file(name): | |
yield os.path.join(root, name) | |
def gen_contents(fnames): | |
"""Generate file contents | |
""" | |
for name in fnames: | |
try: | |
yield name, open(name, 'r').read() | |
except UnicodeDecodeError: | |
continue | |
except IOError as err: | |
if err.errno == EACCES: | |
continue | |
else: | |
raise err |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment