ldcheck.py

changeset 17
327da5d00360
parent 13
12d4ddc4bfd8
child 18
672ebc45685a
equal deleted inserted replaced
16:09cc89622262 17:327da5d00360
33 for library_path_string in config['libraries']: 33 for library_path_string in config['libraries']:
34 yield Path(library_path_string).expanduser() 34 yield Path(library_path_string).expanduser()
35 35
36 def find_ldconfig_ldr_paths(config): 36 def find_ldconfig_ldr_paths(config):
37 for library_path in library_paths(config): 37 for library_path in library_paths(config):
38 ldconfig_paths = [ 38 yield from [
39 library_path / 'LDConfig.ldr', 39 library_path / path
40 library_path / 'ldconfig.ldr', 40 for path in ['LDConfig.ldr', 'ldconfig.ldr']
41 if (library_path / path).is_file()
41 ] 42 ]
42 for path in ldconfig_paths:
43 print(path)
44 if path.is_file():
45 yield path
46 43
47 def hairline_score(smallest_angle): 44 def hairline_score(smallest_angle):
48 from math import log10 45 from math import log10
49 return max(0, -log10(smallest_angle)) 46 return max(0, -log10(smallest_angle))
50 47
51 class Model: 48 class Model:
52 def __init__(self, body): 49 def __init__(self, body):
53 self.body = body 50 self.body = body
54 @property 51 self.body_offset = 0
55 def quadrilaterals(self): 52 @property
56 yield from filter( 53 def quadrilaterals(self):
57 lambda element: isinstance(element, linetypes.Quadrilateral), 54 yield from [
58 self.body) 55 element
56 for element in self.body
57 if isinstance(element, linetypes.Quadrilateral)
58 ]
59 59
60 if __name__ == '__main__': 60 if __name__ == '__main__':
61 from sys import argv 61 from sys import argv
62 config = load_config('ldcheck.cfg') 62 config = load_config('ldcheck.cfg')
63 for ldconfig_ldr_path in find_ldconfig_ldr_paths(config): 63 for ldconfig_ldr_path in find_ldconfig_ldr_paths(config):
64 with ldconfig_ldr_path.open() as ldconfig_ldr: 64 with ldconfig_ldr_path.open() as ldconfig_ldr:
65 load_colours(ldconfig_ldr) 65 load_colours(ldconfig_ldr)
66 with open(argv[1], 'r') as file: 66 with open(argv[1], 'r') as file:
67 model_body = read_ldraw(file, config = config) 67 model_body = read_ldraw(file, config = config)
68 model = Model(body = model_body) 68 model = Model(body = model_body)
69 for line_number, entry in enumerate(model_body, 1): 69 from testsuite import load_tests, check_model, format_report
70 if hasattr(entry, 'colour'): 70 test_suite = load_tests()
71 print(repr(entry.colour)) 71 report = check_model(model, test_suite)
72 if hasattr(entry, 'geometry') and len(entry.geometry) >= 3: 72 print(format_report(report, model, test_suite))
73 if hairline_score(entry.geometry.smallest_angle) >= 2.0:
74 print(str.format(
75 'Hairline {type} at line {line_number}',
76 type = entry.typename(),
77 line_number = line_number,
78 ))
79 print(entry.textual_representation())
80 print('-' * 25)

mercurial