pvl.hosts: --hosts-include path support
authorTero Marttila <terom@paivola.fi>
Sun, 22 Dec 2013 18:15:59 +0200
changeset 334 19da67d71506
parent 333 7d2601368142
child 335 77fb4019d4e0
pvl.hosts: --hosts-include path support
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) :