Thu, 26 Aug 2021 19:36:44 +0300
Merge commit
3
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
1 | #!/usr/bin/env python3 |
147 | 2 | <<<<<<< /home/teemu/dev/ldcheck/ldcheck.py |
146 | 3 | import sys |
4 | if sys.version_info < (3, 4): | |
147 | 5 | ======= |
145
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
6 | import argparse |
8 | 7 | from sys import version_info |
8 | if version_info < (3, 4): | |
147 | 9 | >>>>>>> /tmp/ldcheck~other.ou_xbg_k.py |
8 | 10 | raise RuntimeError('Python 3.4 or newer required') |
147 | 11 | <<<<<<< /home/teemu/dev/ldcheck/ldcheck.py |
8 | 12 | from colours import load_colours |
147 | 13 | ======= |
8 | 14 | |
100
62759e5c4554
add some basic versioning
Teemu Piippo <teemu@hecknology.net>
parents:
98
diff
changeset
|
15 | appname = 'ldcheck' |
114
9ea2549e6171
changed version to 1.0.9999
Teemu Piippo <teemu@hecknology.net>
parents:
113
diff
changeset
|
16 | version = (1, 0, 9999) |
100
62759e5c4554
add some basic versioning
Teemu Piippo <teemu@hecknology.net>
parents:
98
diff
changeset
|
17 | version_string = str.join('.', map(str, version)) |
62759e5c4554
add some basic versioning
Teemu Piippo <teemu@hecknology.net>
parents:
98
diff
changeset
|
18 | |
147 | 19 | >>>>>>> /tmp/ldcheck~other.ou_xbg_k.py |
7 | 20 | from geometry import * |
8 | 21 | from pathlib import Path |
13 | 22 | import linetypes |
47
4da025d0b283
added work on header check
Teemu Piippo <teemu@hecknology.net>
parents:
38
diff
changeset
|
23 | import header |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
24 | import parse |
3
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
25 | |
147 | 26 | <<<<<<< /home/teemu/dev/ldcheck/ldcheck.py |
146 | 27 | def check_library_paths(library_paths): |
28 | for library_path in library_paths: | |
34
7ed2e831acd4
the program now checks that all ldraw paths are reachable
Teemu Piippo <teemu@hecknology.net>
parents:
32
diff
changeset
|
29 | if not library_path.exists(): |
146 | 30 | raise RuntimeError(str.format( |
31 | 'error: library path {} does not exist', | |
34
7ed2e831acd4
the program now checks that all ldraw paths are reachable
Teemu Piippo <teemu@hecknology.net>
parents:
32
diff
changeset
|
32 | library_path, |
7ed2e831acd4
the program now checks that all ldraw paths are reachable
Teemu Piippo <teemu@hecknology.net>
parents:
32
diff
changeset
|
33 | )) |
7ed2e831acd4
the program now checks that all ldraw paths are reachable
Teemu Piippo <teemu@hecknology.net>
parents:
32
diff
changeset
|
34 | elif not library_path.exists(): |
146 | 35 | raise RuntimeError(str.format( |
36 | 'error: library path {} is not a directory', | |
34
7ed2e831acd4
the program now checks that all ldraw paths are reachable
Teemu Piippo <teemu@hecknology.net>
parents:
32
diff
changeset
|
37 | library_path, |
7ed2e831acd4
the program now checks that all ldraw paths are reachable
Teemu Piippo <teemu@hecknology.net>
parents:
32
diff
changeset
|
38 | )) |
7ed2e831acd4
the program now checks that all ldraw paths are reachable
Teemu Piippo <teemu@hecknology.net>
parents:
32
diff
changeset
|
39 | |
146 | 40 | def find_ldconfig_ldr_paths(libraries): |
41 | for library_path in libraries: | |
17 | 42 | yield from [ |
43 | library_path / path | |
44 | for path in ['LDConfig.ldr', 'ldconfig.ldr'] | |
45 | if (library_path / path).is_file() | |
8 | 46 | ] |
47 | ||
146 | 48 | def load_ldconfig(libraries): |
49 | ldconfig_ldr_paths = list(find_ldconfig_ldr_paths(libraries)) | |
50 | if not ldconfig_ldr_paths: | |
51 | raise RuntimeError('could not find any LDConfig.ldr') | |
52 | for ldconfig_ldr_path in ldconfig_ldr_paths: | |
53 | with ldconfig_ldr_path.open() as ldconfig_ldr: | |
54 | load_colours(ldconfig_ldr) | |
147 | 55 | ======= |
9
fea8e9ae6f29
Added matrix code, moved library paths to ldcheck.cfg.
Santeri Piippo
parents:
8
diff
changeset
|
56 | from os.path import realpath |
fea8e9ae6f29
Added matrix code, moved library paths to ldcheck.cfg.
Santeri Piippo
parents:
8
diff
changeset
|
57 | script_directory = Path(realpath(__file__)).parent |
fea8e9ae6f29
Added matrix code, moved library paths to ldcheck.cfg.
Santeri Piippo
parents:
8
diff
changeset
|
58 | |
145
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
59 | def config_dirs(): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
60 | import appdirs |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
61 | appauthor = 'Teemu Piippo' |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
62 | dirs = appdirs.AppDirs(appname, appauthor) |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
63 | return { |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
64 | 'user': Path(dirs.user_config_dir), |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
65 | 'system': Path(dirs.site_config_dir), |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
66 | } |
9
fea8e9ae6f29
Added matrix code, moved library paths to ldcheck.cfg.
Santeri Piippo
parents:
8
diff
changeset
|
67 | |
145
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
68 | def ldraw_dirs_from_config(): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
69 | libraries = [] |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
70 | dirs = config_dirs() |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
71 | for dirpath in [dirs['system'], dirs['user']]: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
72 | filename = dirpath / 'ldcheck.cfg' |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
73 | from configobj import ConfigObj |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
74 | config = ConfigObj(str(filename), encoding = 'UTF8') |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
75 | if 'libraries' in config: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
76 | libraries = expand_paths(config['libraries']) |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
77 | return libraries |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
78 | |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
79 | def expand_paths(paths): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
80 | return [ |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
81 | Path(library).expanduser() |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
82 | for library in paths |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
83 | ] |
9
fea8e9ae6f29
Added matrix code, moved library paths to ldcheck.cfg.
Santeri Piippo
parents:
8
diff
changeset
|
84 | |
145
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
85 | class LDrawContext: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
86 | ''' |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
87 | Contains context-dependant LDraw information, like library directory |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
88 | paths and the colour table. |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
89 | ''' |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
90 | def __init__(self, libraries = None): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
91 | self._libraries = libraries |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
92 | if not self._libraries: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
93 | self._libraries = ldraw_dirs_from_config() |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
94 | self.ldconfig_colour_data = self.load_ldconfig_ldr() |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
95 | self.check_library_paths() |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
96 | @property |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
97 | def libraries(self): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
98 | return self._libraries |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
99 | @property |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
100 | def colours(self): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
101 | return self.ldconfig_colour_data |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
102 | def ldconfig_ldr_discovery(self): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
103 | for library_path in self.libraries: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
104 | yield from [ |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
105 | library_path / path |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
106 | for path in ['LDConfig.ldr', 'ldconfig.ldr'] |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
107 | if (library_path / path).is_file() |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
108 | ] |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
109 | def load_ldconfig_ldr(self): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
110 | from colours import load_colours |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
111 | for ldconfig_ldr_path in self.ldconfig_ldr_discovery(): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
112 | with open(ldconfig_ldr_path) as ldconfig_ldr: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
113 | return load_colours(ldconfig_ldr) |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
114 | def check_library_paths(self): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
115 | from sys import stderr |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
116 | problems = False |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
117 | have_paths = False |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
118 | for library_path in self.libraries: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
119 | have_paths = True |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
120 | if not library_path.exists(): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
121 | problems = True |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
122 | print(str.format( |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
123 | 'Library path {} does not exist', |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
124 | library_path, |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
125 | ), file = stderr) |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
126 | elif not library_path.exists(): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
127 | problems = True |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
128 | print(str.format( |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
129 | 'Library path {} is not a directory', |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
130 | library_path, |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
131 | ), file = stderr) |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
132 | if not have_paths: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
133 | raise RuntimeError('no LDraw library paths specified') |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
134 | def is_ldconfig_colour(self, colour): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
135 | return colour.index in self.colours |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
136 | def colour_name(self, colour): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
137 | if self.is_ldconfig_colour(colour): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
138 | return self.colours[self.index]['name'] |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
139 | else: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
140 | return str(colour) |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
141 | def colour_face(self, colour): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
142 | if self.is_ldconfig_colour(colour): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
143 | return self.colours[self.index]['value'] |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
144 | elif colour.is_direct_colour: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
145 | return '#%06X' % (self.index & 0xffffff) |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
146 | else: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
147 | return '#000000' |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
148 | def is_valid_colour(self, colour): |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
149 | return self.is_ldconfig_colour(colour) or colour.is_direct_colour |
147 | 150 | >>>>>>> /tmp/ldcheck~other.ou_xbg_k.py |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
151 | |
147 | 152 | <<<<<<< /home/teemu/dev/ldcheck/ldcheck.py |
146 | 153 | def parse_commandline_arguments(): |
154 | import os | |
155 | rcpath = Path(os.path.expanduser('~/.config/ldcheckrc')) | |
156 | if rcpath.exists(): | |
157 | with rcpath.open() as file: | |
158 | rcargs = ['--' + line.strip() for line in file] | |
159 | else: | |
160 | rcargs = [] | |
161 | import argparse | |
162 | class ListProblemTypesAction(argparse.Action): | |
163 | def __init__(self, option_strings, dest, nargs = None, **kwargs): | |
164 | super().__init__(option_strings, dest, nargs = 0, **kwargs) | |
165 | def __call__(self, *args, **kwargs): | |
166 | import testsuite | |
167 | test_suite = testsuite.load_tests() | |
168 | for warning_type in testsuite.all_problem_types(test_suite): | |
169 | print(str.format('{name}: {severity}: "{message}"', | |
170 | name = warning_type.name, | |
171 | severity = warning_type.severity, | |
172 | message = warning_type.placeholder_message(), | |
173 | )) | |
174 | sys.exit(0) | |
147 | 175 | ======= |
81
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
176 | class ListProblemsAction(argparse.Action): |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
177 | def __init__(self, option_strings, dest, nargs = None, **kwargs): |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
178 | super().__init__(option_strings, dest, nargs = 0, **kwargs) |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
179 | def __call__(self, *args, **kwargs): |
63
8949af6a4279
added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
180 | import testsuite |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
181 | from sys import exit |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
182 | from re import sub |
63
8949af6a4279
added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
183 | test_suite = testsuite.load_tests() |
8949af6a4279
added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
184 | for warning_type in testsuite.all_problem_types(test_suite): |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
185 | print(str.format('{name}: {severity}: "{message}"', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
186 | name = warning_type.name, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
187 | severity = warning_type.severity, |
63
8949af6a4279
added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
188 | message = warning_type.placeholder_message(), |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
189 | )) |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
190 | exit(0) |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
191 | |
98 | 192 | def format_report(report, model, test_suite, *, use_colors = True): |
193 | from testsuite import problem_text | |
194 | messages = [] | |
195 | for problem in report['problems']: | |
196 | text_colour = '' | |
197 | if use_colors: | |
198 | if problem.severity == 'hold': | |
199 | text_colour = colorama.Fore.LIGHTRED_EX | |
200 | elif problem.severity == 'warning': | |
201 | text_colour = colorama.Fore.LIGHTBLUE_EX | |
202 | ldraw_code = model.body[problem.body_index].textual_representation() | |
203 | message = str.format( | |
204 | '{text_colour}{model_name}:{line_number}: {problem_type}: {message}' | |
205 | '{colour_reset}\n\t{ldraw_code}', | |
206 | text_colour = text_colour, | |
207 | model_name = model.name, | |
208 | line_number = problem.line_number, | |
209 | problem_type = problem.severity, | |
210 | message = problem_text(problem, test_suite), | |
211 | colour_reset = use_colors and colorama.Fore.RESET or '', | |
212 | ldraw_code = ldraw_code, | |
213 | ) | |
214 | messages.append(message) | |
215 | return '\n'.join(messages) | |
216 | ||
3
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
217 | if __name__ == '__main__': |
109
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
218 | from sys import argv, stderr, exit |
147 | 219 | >>>>>>> /tmp/ldcheck~other.ou_xbg_k.py |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
220 | parser = argparse.ArgumentParser() |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
221 | parser.add_argument('filename') |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
222 | parser.add_argument('--list', |
146 | 223 | action = ListProblemTypesAction, |
81
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
224 | help = 'lists all possible problem types and exit', |
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
225 | ) |
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
226 | parser.add_argument('--dump', |
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
227 | action = 'store_true', |
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
228 | help = 'dumps the internal parsed structure of the part file', |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
229 | ) |
81
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
230 | parser.add_argument('--rebuild', |
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
231 | action = 'store_true', |
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
232 | help = 'parses the part file and prints it back out, used for ' |
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
233 | 'testing whether the program interprets part files correctly', |
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
234 | ) |
92
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
85
diff
changeset
|
235 | parser.add_argument('--subfile', |
81
e65d82501a38
added better help entries to command line parameters
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
236 | action = 'store_true', |
92
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
85
diff
changeset
|
237 | help = 'finds a subfile by name and prints out information about it' |
85
4438502fd3e0
fixed the use of moved-to-files check not working if there were non-alphanumerics in the filename
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
238 | ) |
147 | 239 | <<<<<<< /home/teemu/dev/ldcheck/ldcheck.py |
146 | 240 | parser.add_argument('-l', '--library', action = 'append') |
241 | arglist = rcargs + sys.argv[1:] | |
242 | return parser.parse_args(arglist) | |
243 | ||
244 | def main(): | |
245 | args = parse_commandline_arguments() | |
246 | # Make sure that we have at least one library path specified. | |
247 | if not args.library: | |
248 | raise RuntimeError( | |
249 | 'Please specify libraries using the -l / --library switch.\n' | |
250 | 'For example: -l ~/ldraw or --library=~/ldraw\n' | |
251 | 'Multiple --library switches may be used.') | |
252 | # Prepare the list of libraries. This also expands the ~ for the home | |
253 | # directory | |
254 | import os | |
255 | libraries = [Path(os.path.expanduser(library)) for library in args.library] | |
256 | check_library_paths(libraries) | |
257 | load_ldconfig(libraries) | |
147 | 258 | ======= |
98 | 259 | parser.add_argument('--color', |
260 | action = 'store_true', | |
261 | help = 'use colors' | |
262 | ) | |
145
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
263 | parser.add_argument('-d', '--ldraw-dir', |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
264 | nargs = '+', |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
265 | help = 'specify LDraw directory path(s)', |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
266 | ) |
100
62759e5c4554
add some basic versioning
Teemu Piippo <teemu@hecknology.net>
parents:
98
diff
changeset
|
267 | parser.add_argument('-v', '--version', |
62759e5c4554
add some basic versioning
Teemu Piippo <teemu@hecknology.net>
parents:
98
diff
changeset
|
268 | action = 'version', |
62759e5c4554
add some basic versioning
Teemu Piippo <teemu@hecknology.net>
parents:
98
diff
changeset
|
269 | version = str.format('{appname} {version}', |
62759e5c4554
add some basic versioning
Teemu Piippo <teemu@hecknology.net>
parents:
98
diff
changeset
|
270 | appname = appname, |
62759e5c4554
add some basic versioning
Teemu Piippo <teemu@hecknology.net>
parents:
98
diff
changeset
|
271 | version = version_string, |
62759e5c4554
add some basic versioning
Teemu Piippo <teemu@hecknology.net>
parents:
98
diff
changeset
|
272 | ), |
62759e5c4554
add some basic versioning
Teemu Piippo <teemu@hecknology.net>
parents:
98
diff
changeset
|
273 | ) |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
21
diff
changeset
|
274 | args = parser.parse_args() |
145
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
275 | libraries = ldraw_dirs_from_config() |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
276 | if args.ldraw_dir: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
277 | libraries = expand_paths(args.ldraw_dir) |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
278 | try: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
279 | context = LDrawContext(libraries) |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
280 | except RuntimeError as error: |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
281 | print('error:', str(error), file = stderr) |
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
282 | exit(1) |
98 | 283 | if args.color: |
284 | try: | |
285 | import colorama | |
286 | colorama.init() | |
287 | except ImportError: | |
288 | print('Use of --color requires the colorama module, disabling colours', file = stderr) | |
289 | args.color = False | |
147 | 290 | >>>>>>> /tmp/ldcheck~other.ou_xbg_k.py |
92
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
85
diff
changeset
|
291 | if args.subfile: |
146 | 292 | # Subfile debug mode: searches for the specified subfile from the LDraw |
293 | # libraries, opens it as if it was referenced by something and prints | |
294 | # out all information that is calculated from this subfile. | |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
295 | import filecache |
147 | 296 | <<<<<<< /home/teemu/dev/ldcheck/ldcheck.py |
146 | 297 | cache = filecache.SubfileCache(ldraw_directories = libraries) |
147 | 298 | ======= |
145
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
299 | cache = filecache.SubfileCache(context = context) |
147 | 300 | >>>>>>> /tmp/ldcheck~other.ou_xbg_k.py |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
301 | subfile = cache.prepare_file(args.filename) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
302 | if not subfile.valid: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
303 | print(subfile.problem) |
92
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
85
diff
changeset
|
304 | else: |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
85
diff
changeset
|
305 | print('Flat dimensions:', repr(subfile.flatness)) |
85
4438502fd3e0
fixed the use of moved-to-files check not working if there were non-alphanumerics in the filename
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
306 | print('Description:', repr(subfile.description)) |
92
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
85
diff
changeset
|
307 | print('Contains studs:', repr(subfile.has_studs)) |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
308 | else: |
147 | 309 | <<<<<<< /home/teemu/dev/ldcheck/ldcheck.py |
94
109fb7cf658f
added a check for non-DOS line endings
Teemu Piippo <teemu@hecknology.net>
parents:
92
diff
changeset
|
310 | with open(args.filename, 'rb') as file: |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
311 | from os.path import basename |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
312 | model = parse.read_ldraw( |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
313 | file, |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
314 | name = basename(args.filename), |
146 | 315 | ldraw_directories = libraries) |
77
d98502ae1f33
improved header extent scanning
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
316 | if args.dump: |
146 | 317 | # Dump mode: prints out the structure of the processed LDraw file |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
318 | print('header: ' + type(model.header).__name__) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
319 | for key in sorted(dir(model.header)): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
320 | if not key.startswith('__'): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
321 | print('\t' + key + ': ' + repr(getattr(model.header, key))) |
77
d98502ae1f33
improved header extent scanning
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
322 | for i, entry in enumerate(model.body): |
d98502ae1f33
improved header extent scanning
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
323 | if model.header.valid and i == model.header_size: |
146 | 324 | # Mark where the header is considered to end |
77
d98502ae1f33
improved header extent scanning
Teemu Piippo <teemu@hecknology.net>
parents:
63
diff
changeset
|
325 | print('--------- End of header') |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
326 | print(entry) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
327 | elif args.rebuild: |
146 | 328 | # Debug rebuild mode: open the file, parse it and turn it back |
329 | # into LDraw code and write it into stdout. This is used to ensure | |
330 | # that LDCheck does not miss any information while parsing files. | |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
331 | for entry in model.body: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
332 | print(entry.textual_representation(), end = '\r\n') |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
333 | else: |
146 | 334 | # Regular mode |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
335 | from testsuite import load_tests, check_model, format_report |
146 | 336 | # load the test suite |
337 | # TODO: maybe add some command line argument to filter tests | |
338 | # in case the user wants to run some specific tests only or | |
339 | # possibly leave some test out | |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
340 | test_suite = load_tests() |
146 | 341 | # use the test suite to check the model |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
342 | report = check_model(model, test_suite) |
146 | 343 | # print out the report |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
344 | print(format_report(report, model, test_suite)) |
146 | 345 | |
346 | if __name__ == '__main__': | |
347 | try: | |
348 | main() | |
349 | except RuntimeError as e: | |
350 | import sys | |
351 | print('error:', str(e), file = sys.stderr) | |
352 | sys.exit(1) | |
147 | 353 | ======= |
109
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
354 | try: |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
355 | with open(args.filename, 'rb') as file: |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
356 | from os.path import basename |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
357 | model = parse.read_ldraw( |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
358 | file, |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
359 | name = basename(args.filename), |
145
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
122
diff
changeset
|
360 | context = context) |
109
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
361 | if args.dump: |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
362 | print('header: ' + type(model.header).__name__) |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
363 | for key in sorted(dir(model.header)): |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
364 | if not key.startswith('__'): |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
365 | print('\t' + key + ': ' + repr(getattr(model.header, key))) |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
366 | for i, entry in enumerate(model.body): |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
367 | if model.header.valid and i == model.header_size: |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
368 | print('--------- End of header') |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
369 | print(entry) |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
370 | elif args.rebuild: |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
371 | for entry in model.body: |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
372 | print(entry.textual_representation(), end = '\r\n') |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
373 | else: |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
374 | from testsuite import load_tests, check_model |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
375 | test_suite = load_tests() |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
376 | report = check_model(model, test_suite) |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
377 | print(format_report( |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
378 | report, |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
379 | model, |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
380 | test_suite, |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
381 | use_colors = args.color |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
382 | )) |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
383 | except FileNotFoundError: |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
384 | print(str.format( |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
385 | 'no such file: {filename!r}', |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
386 | filename = args.filename |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
387 | ), file = stderr) |
b627f8963a84
handle file not found more cleanly
Teemu Piippo <teemu@hecknology.net>
parents:
100
diff
changeset
|
388 | exit(1) |
147 | 389 | >>>>>>> /tmp/ldcheck~other.ou_xbg_k.py |