diff options
author | Paul Sherwood <paul.sherwood@codethink.co.uk> | 2016-09-01 14:03:59 +0100 |
---|---|---|
committer | Paul Sherwood <paul.sherwood@codethink.co.uk> | 2016-09-01 16:17:26 +0100 |
commit | f072299d04079009e1594630044a0a80a586e2ba (patch) | |
tree | 0f8b670e1827158509e1d2016090d582ad7d10ad | |
parent | 969df3637ed33dd3ad29b54d921741f9f7666541 (diff) | |
download | ybd-f072299d04079009e1594630044a0a80a586e2ba.tar.gz |
Simplify logic for walk and parse definitions
-rw-r--r-- | ybd/morphs.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/ybd/morphs.py b/ybd/morphs.py index 1a41d65..5796d15 100644 --- a/ybd/morphs.py +++ b/ybd/morphs.py @@ -15,6 +15,7 @@ # =*= License: GPL-2 =*= import yaml +import glob import os from app import chdir, config, log from defaults import Defaults @@ -28,23 +29,17 @@ class Morphs(object): self.defaults = Defaults() self.fields = self.defaults.build_steps + self.defaults.fields config['cpu'] = self.defaults.cpus.get(config['arch'], config['arch']) - self.parse_files(directory) - - def parse_files(self, directory): - with chdir(directory): - for dirname, dirnames, filenames in os.walk('.'): - filenames.sort() - dirnames.sort() - if '.git' in dirnames: - dirnames.remove('.git') - for filename in filenames: - if filename.endswith(('.def', '.morph')): - path = os.path.join(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) + + 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: + 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] for field in dn: |