Mon, 22 Jan 2018 18:07:19 +0200
refactor
ldcheck.py | file | annotate | diff | comparison | revisions |
--- a/ldcheck.py Mon Jan 22 17:47:06 2018 +0200 +++ b/ldcheck.py Mon Jan 22 18:07:19 2018 +0200 @@ -23,11 +23,14 @@ config.write() return config -def read_ldraw(file, *, config): - result = list() - for line in file: - result.append(parse_ldraw_code(line)) - return result +def read_ldraw(file, *, name = '', config): + model_body = [ + parse_ldraw_code(line) + for line in file + ] + model = Model(body = model_body) + model.name = name + return model def library_paths(config): for library_path_string in config['libraries']: @@ -49,13 +52,24 @@ def __init__(self, body): self.body = body self.body_offset = 0 - @property - def quadrilaterals(self): + def filter_by_type(self, type): yield from [ element for element in self.body - if isinstance(element, linetypes.Quadrilateral) + if isinstance(element, type) ] + @property + def subfile_references(self): + yield from self.filter_by_type(linetypes.SubfileReference) + @property + def line_segments(self): + yield from self.filter_by_type(linetypes.LineSegment) + @property + def triangles(self): + yield from self.filter_by_type(linetypes.Triangle) + @property + def quadrilaterals(self): + yield from self.filter_by_type(linetypes.Quadrilateral) if __name__ == '__main__': from sys import argv @@ -64,10 +78,8 @@ with ldconfig_ldr_path.open() as ldconfig_ldr: load_colours(ldconfig_ldr) with open(argv[1], 'r') as file: - model_body = read_ldraw(file, config = config) - model = Model(body = model_body) from os.path import basename - model.name = basename(argv[1]) + model = read_ldraw(file, name = basename(argv[1]), config = config) from testsuite import load_tests, check_model, format_report test_suite = load_tests() report = check_model(model, test_suite)