ia64/xen-unstable

changeset 11659:98ba161961b5

[XM] Fix stray quotes in usage message in getlabel.py

Fixed built-in function name conflict.
Raise correct exceptions for when option is invalid to be properly
reported by xm.

Signed-off-by: Alastair Tse <atse@xensource.com>
author atse@norwich.uk.xensource.com
date Thu Sep 28 12:23:21 2006 +0100 (2006-09-28)
parents 0de76117acb6
children 98c369711006
files tools/python/xen/xm/getlabel.py
line diff
     1.1 --- a/tools/python/xen/xm/getlabel.py	Thu Sep 28 12:16:11 2006 +0100
     1.2 +++ b/tools/python/xen/xm/getlabel.py	Thu Sep 28 12:23:21 2006 +0100
     1.3 @@ -25,8 +25,9 @@ from xen.xm.opts import OptionError
     1.4  
     1.5  def help():
     1.6      return """
     1.7 -    Usage: xm getlabel dom <configfile>"
     1.8 -           xm getlabel res <resource>\n"
     1.9 +    Usage: xm getlabel dom <configfile>
    1.10 +           xm getlabel res <resource>
    1.11 +           
    1.12      This program shows the label for a domain or resource."""
    1.13  
    1.14  def get_resource_label(resource):
    1.15 @@ -37,7 +38,7 @@ def get_resource_label(resource):
    1.16      try:
    1.17          access_control = dictio.dict_read("resources", file)
    1.18      except:
    1.19 -        security.err("Resource label file not found")
    1.20 +        raise OptionError("Resource label file not found")
    1.21  
    1.22      # get the entry and print label
    1.23      if access_control.has_key(resource):
    1.24 @@ -45,23 +46,22 @@ def get_resource_label(resource):
    1.25          label = access_control[resource][1]
    1.26          print "policy="+policy+",label="+label
    1.27      else:
    1.28 -        security.err("Resource not labeled")
    1.29 +        raise security.ACMError("Resource not labeled")
    1.30  
    1.31  
    1.32  def get_domain_label(configfile):
    1.33      # open the domain config file
    1.34      fd = None
    1.35 -    file = None
    1.36      if configfile[0] == '/':
    1.37          fd = open(configfile, "rb")
    1.38      else:
    1.39          for prefix in [".", "/etc/xen"]:
    1.40 -            file = prefix + "/" + configfile
    1.41 -            if os.path.isfile(file):
    1.42 -                fd = open(file, "rb")
    1.43 +            abs_file = prefix + "/" + configfile
    1.44 +            if os.path.isfile(abs_file):
    1.45 +                fd = open(abs_file, "rb")
    1.46                  break
    1.47      if not fd:
    1.48 -        security.err("Configuration file '"+configfile+"' not found.")
    1.49 +        raise OptionError("Configuration file '%s' not found." % configfile)
    1.50  
    1.51      # read in the domain config file, finding the label line
    1.52      ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
    1.53 @@ -79,7 +79,7 @@ def get_domain_label(configfile):
    1.54  
    1.55      # send error message if we didn't find anything
    1.56      if acline == "":
    1.57 -        security.err("Domain not labeled")
    1.58 +        raise security.ACMError("Domain not labeled")
    1.59  
    1.60      # print out the label
    1.61      (title, data) = acline.split("=", 1)
    1.62 @@ -89,7 +89,7 @@ def get_domain_label(configfile):
    1.63      print data
    1.64  
    1.65  
    1.66 -def main (argv):
    1.67 +def main(argv):
    1.68      if len(argv) != 3:
    1.69          raise OptionError('Requires 2 arguments')
    1.70  
    1.71 @@ -103,6 +103,11 @@ def main (argv):
    1.72          raise OptionError('First subcommand argument must be "dom" or "res"')
    1.73  
    1.74  if __name__ == '__main__':
    1.75 -    main(sys.argv)
    1.76 +    try:
    1.77 +        main(sys.argv)
    1.78 +    except Exception, e:
    1.79 +        sys.stderr.write('Error: %s\n' % str(e))
    1.80 +        sys.exit(-1)
    1.81 +        
    1.82  
    1.83