equal
deleted
inserted
replaced
17 hosts.add_option('--hosts-charset', metavar='CHARSET', default='utf-8', |
17 hosts.add_option('--hosts-charset', metavar='CHARSET', default='utf-8', |
18 help="Encoding used for host files") |
18 help="Encoding used for host files") |
19 |
19 |
20 hosts.add_option('--hosts-domain', metavar='DOMAIN', |
20 hosts.add_option('--hosts-domain', metavar='DOMAIN', |
21 help="Default domain for hosts") |
21 help="Default domain for hosts") |
|
22 |
|
23 hosts.add_option('--hosts-include', metavar='PATH', |
|
24 help="Optional path for hosts includes, beyond host config dir") |
22 |
25 |
23 return hosts |
26 return hosts |
|
27 |
|
28 class HostError (Exception) : |
|
29 pass |
|
30 |
|
31 class HostConfigError (HostError) : |
|
32 pass |
24 |
33 |
25 class Host (object) : |
34 class Host (object) : |
26 # the label used for alias4/6 hosts |
35 # the label used for alias4/6 hosts |
27 ALIAS4_FMT = '{host}-ipv4' |
36 ALIAS4_FMT = '{host}-ipv4' |
28 ALIAS6_FMT = '{host}-ipv6' |
37 ALIAS6_FMT = '{host}-ipv6' |
201 |
210 |
202 def apply_host_includes (options, config_path, include) : |
211 def apply_host_includes (options, config_path, include) : |
203 """ |
212 """ |
204 Yield files from a given config's include=... value |
213 Yield files from a given config's include=... value |
205 """ |
214 """ |
206 |
215 |
207 include_path = os.path.dirname(config_path) |
216 if options.hosts_include : |
|
217 include_paths = (os.path.dirname(config_path), options.hosts_include) |
|
218 else : |
|
219 include_paths = (os.path.dirname(config_path), ) |
208 |
220 |
209 for include in include.split() : |
221 for include in include.split() : |
210 path = os.path.join(include_path, include) |
222 for include_path in include_paths : |
|
223 path = os.path.join(include_path, include) |
|
224 if os.path.exists(path) : |
|
225 break |
|
226 else : |
|
227 raise HostConfigError(config_path, "Unable to find include %s in include path: %s" % (include, ' '.join(include_paths))) |
211 |
228 |
212 if include.endswith('/') : |
229 if include.endswith('/') : |
213 for name in os.listdir(path) : |
230 for name in os.listdir(path) : |
214 file_path = os.path.join(path, name) |
231 file_path = os.path.join(path, name) |
215 |
232 |