19 read_config = deepcopy(config) |
19 read_config = deepcopy(config) |
20 if 'libraries' not in config: |
20 if 'libraries' not in config: |
21 config['libraries'] = ['/path/to/ldraw'] |
21 config['libraries'] = ['/path/to/ldraw'] |
22 if config != read_config: |
22 if config != read_config: |
23 config.write() |
23 config.write() |
|
24 check_library_paths(config) |
24 return config |
25 return config |
25 |
26 |
26 def read_ldraw(file, *, name = '', config): |
27 def read_ldraw(file, *, name = '', config): |
27 model_body = [ |
28 model_body = [ |
28 parse_ldraw_code(line) |
29 parse_ldraw_code(line) |
33 return model |
34 return model |
34 |
35 |
35 def library_paths(config): |
36 def library_paths(config): |
36 for library_path_string in config['libraries']: |
37 for library_path_string in config['libraries']: |
37 yield Path(library_path_string).expanduser() |
38 yield Path(library_path_string).expanduser() |
|
39 |
|
40 def check_library_paths(config): |
|
41 from sys import exit |
|
42 problems = False |
|
43 for library_path in library_paths(config): |
|
44 if not library_path.exists(): |
|
45 problems = True |
|
46 print(str.format( |
|
47 'Library path {} does not exist', |
|
48 library_path, |
|
49 )) |
|
50 elif not library_path.exists(): |
|
51 problems = True |
|
52 print(str.format( |
|
53 'Library path {} is not a directory', |
|
54 library_path, |
|
55 )) |
|
56 if problems: |
|
57 print('Please fix ldcheck.cfg') |
|
58 exit(1) |
38 |
59 |
39 def find_ldconfig_ldr_paths(config): |
60 def find_ldconfig_ldr_paths(config): |
40 for library_path in library_paths(config): |
61 for library_path in library_paths(config): |
41 yield from [ |
62 yield from [ |
42 library_path / path |
63 library_path / path |