sshwot/src/open_default_files.py

25 lines
554 B
Python

import os
def open_all():
"""open_all() → [file(rb)]
Open the default sshwot files"""
try:
homedir = os.environ['HOME']
except KeyError as err:
raise KeyError('$HOME is not set') from err
# If the directory doesn't exist, just return empty
try:
sshwot_dir = os.listdir(os.path.join(homedir, '.sshwot'))
except FileNotFoundError:
return []
# Read all the .sshwot files from /.sshwot by default
files = []
for dir_entry in sshwot_dir:
if dir_entry.split('.')[-1] == 'sshwot':
files.append(open(dir_entry, 'rb'))
return files