95 parser.add_argument('--rebuild', |
95 parser.add_argument('--rebuild', |
96 action = 'store_true', |
96 action = 'store_true', |
97 help = 'parses the part file and prints it back out, used for ' |
97 help = 'parses the part file and prints it back out, used for ' |
98 'testing whether the program interprets part files correctly', |
98 'testing whether the program interprets part files correctly', |
99 ) |
99 ) |
100 parser.add_argument('--flatness', |
100 parser.add_argument('--subfile', |
101 action = 'store_true', |
101 action = 'store_true', |
102 help = 'finds a primitive by name and prints out in which ' |
102 help = 'finds a subfile by name and prints out information about it' |
103 'dimensions it is flat in', |
|
104 ) |
|
105 parser.add_argument('--description', |
|
106 action = 'store_true', |
|
107 help = 'finds a primitive by name and prints out its description', |
|
108 ) |
103 ) |
109 args = parser.parse_args() |
104 args = parser.parse_args() |
110 config = load_config('ldcheck.cfg') |
105 config = load_config('ldcheck.cfg') |
111 for ldconfig_ldr_path in find_ldconfig_ldr_paths(config): |
106 for ldconfig_ldr_path in find_ldconfig_ldr_paths(config): |
112 with ldconfig_ldr_path.open() as ldconfig_ldr: |
107 with ldconfig_ldr_path.open() as ldconfig_ldr: |
113 load_colours(ldconfig_ldr) |
108 load_colours(ldconfig_ldr) |
114 if args.flatness or args.description: |
109 if args.subfile: |
115 import filecache |
110 import filecache |
116 cache = filecache.SubfileCache( |
111 cache = filecache.SubfileCache( |
117 ldraw_directories = config['libraries'], |
112 ldraw_directories = config['libraries'], |
118 ) |
113 ) |
119 subfile = cache.prepare_file(args.filename) |
114 subfile = cache.prepare_file(args.filename) |
120 if not subfile.valid: |
115 if not subfile.valid: |
121 print(subfile.problem) |
116 print(subfile.problem) |
122 elif args.flatness: |
117 else: |
123 if subfile.flatness: |
118 print('Flat dimensions:', repr(subfile.flatness)) |
124 print(str.format( |
|
125 'Flatness: {}', |
|
126 ', '.join(subfile.flatness), |
|
127 )) |
|
128 else: |
|
129 print('File is not flat in any dimensions') |
|
130 elif args.description: |
|
131 print('Description:', repr(subfile.description)) |
119 print('Description:', repr(subfile.description)) |
|
120 print('Contains studs:', repr(subfile.has_studs)) |
132 else: |
121 else: |
133 with open(args.filename) as file: |
122 with open(args.filename) as file: |
134 from os.path import basename |
123 from os.path import basename |
135 model = parse.read_ldraw( |
124 model = parse.read_ldraw( |
136 file, |
125 file, |