37 lines
785 B
Python
37 lines
785 B
Python
import os
|
|
|
|
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
|
|
sshwot_dir_path = os.path.join(homedir, '.sshwot')
|
|
try:
|
|
sshwot_dir = os.listdir(sshwot_dir_path)
|
|
except FileNotFoundError:
|
|
return []
|
|
|
|
# Read all the .sshwot files from /.sshwot by default
|
|
paths = []
|
|
for dir_entry in sshwot_dir:
|
|
if dir_entry.split('.')[-1] == 'sshwot':
|
|
path = os.path.join(sshwot_dir_path, dir_entry)
|
|
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
|