Moving away from string exceptions
authorStephen Gran <steve@lobefin.net>
Sat, 9 May 2009 11:23:19 +0000 (12:23 +0100)
committerStephen Gran <steve@lobefin.net>
Sat, 9 May 2009 11:23:19 +0000 (12:23 +0100)
ud-generate
userdir_exceptions.py

index 953be7f..8001012 100755 (executable)
@@ -28,6 +28,7 @@
 
 import string, re, time, ldap, getopt, sys, os, pwd, posix, socket, base64, sha, shutil, errno, tarfile, grp
 from userdir_ldap import *;
+from userdir_exceptions import *
 
 global Allowed;
 global CurrentHost;
@@ -809,7 +810,7 @@ def GenSSHFP(l,File,HomePrefix):
    # Fetch all the hosts
    global HostAttrs
    if HostAttrs == None:
-      raise "No Hosts"
+      raise UDEmptyList, "No Hosts"
 
    for x in HostAttrs:
       if x[1].has_key("hostname") == 0 or \
@@ -905,7 +906,7 @@ def GenSSHKnown(l,File,mode=None):
 
    global HostAttrs
    if HostAttrs == None:
-      raise "No Hosts";
+      raise UDEmptyList, "No Hosts"
 
    for x in HostAttrs:
       if x[1].has_key("hostname") == 0 or \
@@ -962,7 +963,7 @@ def GenHosts(l,File):
                            ["hostname"])
 
     if hostnames == None:
-       raise "No Hosts"
+       raise UDEmptyList, "No Hosts"
 
     seen = set()
     for x in hostnames:
@@ -1027,7 +1028,7 @@ PasswdAttrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\
                  "mailWhitelist", "sudoPassword", "objectClass", "accountStatus"])
 
 if PasswdAttrs is None:
-   raise "No Users"
+   raise UDEmptyList, "No Users"
 
 # Fetch all the hosts
 HostAttrs    = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"sshRSAHostKey=*",\
index a1d775e..4e32307 100644 (file)
@@ -25,6 +25,7 @@ UDERRORS = {
     "UDFormatError": """Exception raised for data format errors.""",
     "UDExecuteError": """Exception raised for subprocess execution errors.""",
     "UDNotAllowedError": """Exception raised for attempts to modify off-limits or disabled entries.""",
+    "UDEmptyList": """Exception raised for empty list objects.""",
 }
 
 def construct_udld_exception(name, description):