diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2017-10-24 11:48:11 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2017-10-24 11:48:11 +0000 |
commit | 157986cb2f7c0b95e0e4e0bf3a39547f548a298d (patch) | |
tree | bedc73d882683022e791be3119ac2367117c475f | |
parent | 4cc518bc6e4441df7d494b22f805c72d6b49fb7c (diff) | |
parent | 6676c4ac025954a7c5c6a38c88350838c45be8b6 (diff) | |
download | ybd-157986cb2f7c0b95e0e4e0bf3a39547f548a298d.tar.gz |
Merge branch 'sam/ignore-hidden-dirs' into 'master'
Efficiently ignore hidden directories when looking for definitions
See merge request baserock/ybd!396
-rw-r--r-- | ybd/morphs.py | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/ybd/morphs.py b/ybd/morphs.py index 6ded04d..d910a27 100644 --- a/ybd/morphs.py +++ b/ybd/morphs.py @@ -15,12 +15,15 @@ # =*= License: GPL-2 =*= import yaml -import glob import os from app import chdir, config, log from defaults import Defaults +def is_not_hidden_dir(d): + return not d.startswith('.') + + class Morphs(object): def __init__(self, directory='.'): @@ -29,18 +32,19 @@ class Morphs(object): self.defaults = Defaults() self.fields = self.defaults.build_steps + self.defaults.fields - directories = [d[0] for d in os.walk(directory) if '/.' not in d[0]] - for d in sorted(directories): - files = glob.glob(os.path.join(d, '*.morph')) - for path in sorted(files): - data = self._load(path) - if data is not None: - path = self._demorph(path) - if path.startswith('./'): - path = path[2:] - data['path'] = path - self._fix_keys(data) - self._tidy_and_insert_recursively(data) + with chdir(directory): + for outer_dirname, dirnames, filenames in os.walk('.'): + dirnames[:] = filter(is_not_hidden_dir, dirnames) + filenames.sort() + dirnames.sort() + for filename in filenames: + if filename.endswith('.morph'): + path = os.path.join(outer_dirname, filename) + data = self._load(path) + if data is not None: + data['path'] = self._demorph(path[2:]) + self._fix_keys(data) + self._tidy_and_insert_recursively(data) for x in self._data: dn = self._data[x] |