# HG changeset patch # User Tero Marttila # Date 1387728959 -7200 # Node ID 19da67d715063e754246b81382851e0da33ffc83 # Parent 7d2601368142a936199cfd58c81713fe92034347 pvl.hosts: --hosts-include path support diff -r 7d2601368142 -r 19da67d71506 pvl/hosts.py --- a/pvl/hosts.py Sun Dec 22 18:09:08 2013 +0200 +++ b/pvl/hosts.py Sun Dec 22 18:15:59 2013 +0200 @@ -19,9 +19,18 @@ hosts.add_option('--hosts-domain', metavar='DOMAIN', help="Default domain for hosts") + + hosts.add_option('--hosts-include', metavar='PATH', + help="Optional path for hosts includes, beyond host config dir") return hosts +class HostError (Exception) : + pass + +class HostConfigError (HostError) : + pass + class Host (object) : # the label used for alias4/6 hosts ALIAS4_FMT = '{host}-ipv4' @@ -203,11 +212,19 @@ """ Yield files from a given config's include=... value """ - - include_path = os.path.dirname(config_path) + + if options.hosts_include : + include_paths = (os.path.dirname(config_path), options.hosts_include) + else : + include_paths = (os.path.dirname(config_path), ) for include in include.split() : - path = os.path.join(include_path, include) + for include_path in include_paths : + path = os.path.join(include_path, include) + if os.path.exists(path) : + break + else : + raise HostConfigError(config_path, "Unable to find include %s in include path: %s" % (include, ' '.join(include_paths))) if include.endswith('/') : for name in os.listdir(path) :