Created
September 19, 2017 06:48
-
-
Save Finwood/fc84da9860fe340dab8750226621effd to your computer and use it in GitHub Desktop.
Python File List
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
import os.path | |
import yaml | |
def load(fname): | |
with open(fname) as f: | |
return yaml.load(f.read()) | |
def parse_dirs(data): | |
if isinstance(data, str): | |
yield data | |
elif isinstance(data, (list, tuple)): | |
yield from data | |
elif isinstance(data, dict): | |
for k, vs in data.items(): | |
for v in parse_dirs(vs): | |
yield os.path.expanduser(os.path.join(k, v)) | |
else: | |
raise TypeError("Expecting str, list or dict; got {}".format(type(data))) | |
def load_dirs(fname): | |
return list(parse_dirs(load(fname))) |
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
/etc: | |
- ssh | |
- foo | |
'~': | |
- projects | |
- bin | |
- Studium | |
- Downloads/res | |
- foo: | |
- bar | |
- baz/boo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment