sshwot/src/default_files.py

37 lines
785 B
Python
Raw Permalink Normal View History

import os
2018-09-01 19:33:41 +00:00
def list_all():
"""list_all() → [str]
List 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
2018-09-01 19:03:31 +00:00
sshwot_dir_path = os.path.join(homedir, '.sshwot')
try:
2018-09-01 19:03:31 +00:00
sshwot_dir = os.listdir(sshwot_dir_path)
except FileNotFoundError:
return []
# Read all the .sshwot files from /.sshwot by default
2018-09-01 19:33:41 +00:00
paths = []
for dir_entry in sshwot_dir:
if dir_entry.split('.')[-1] == 'sshwot':
2018-09-01 19:03:31 +00:00
path = os.path.join(sshwot_dir_path, dir_entry)
2018-09-01 19:33:41 +00:00
paths.append(path)
return paths
def open_all():
"""open_all() → [file(rb)]
Open the default sshwot files"""
files = []
for path in list_all():
files.append(open(path, 'rb'))
return files