[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] [XM] Fix stray quotes in usage message in getlabel.py



# HG changeset patch
# User atse@xxxxxxxxxxxxxxxxxxxxxxxx
# Node ID 98ba161961b5334657e80f260e4c6be11ac3e90c
# Parent  0de76117acb6116354b221eba8d322ae1190f2f7
[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@xxxxxxxxxxxxx>
---
 tools/python/xen/xm/getlabel.py |   29 +++++++++++++++++------------
 1 files changed, 17 insertions(+), 12 deletions(-)

diff -r 0de76117acb6 -r 98ba161961b5 tools/python/xen/xm/getlabel.py
--- a/tools/python/xen/xm/getlabel.py   Thu Sep 28 12:16:11 2006 +0100
+++ b/tools/python/xen/xm/getlabel.py   Thu Sep 28 12:23:21 2006 +0100
@@ -25,8 +25,9 @@ from xen.xm.opts import OptionError
 
 def help():
     return """
-    Usage: xm getlabel dom <configfile>"
-           xm getlabel res <resource>\n"
+    Usage: xm getlabel dom <configfile>
+           xm getlabel res <resource>
+           
     This program shows the label for a domain or resource."""
 
 def get_resource_label(resource):
@@ -37,7 +38,7 @@ def get_resource_label(resource):
     try:
         access_control = dictio.dict_read("resources", file)
     except:
-        security.err("Resource label file not found")
+        raise OptionError("Resource label file not found")
 
     # get the entry and print label
     if access_control.has_key(resource):
@@ -45,23 +46,22 @@ def get_resource_label(resource):
         label = access_control[resource][1]
         print "policy="+policy+",label="+label
     else:
-        security.err("Resource not labeled")
+        raise security.ACMError("Resource not labeled")
 
 
 def get_domain_label(configfile):
     # open the domain config file
     fd = None
-    file = None
     if configfile[0] == '/':
         fd = open(configfile, "rb")
     else:
         for prefix in [".", "/etc/xen"]:
-            file = prefix + "/" + configfile
-            if os.path.isfile(file):
-                fd = open(file, "rb")
+            abs_file = prefix + "/" + configfile
+            if os.path.isfile(abs_file):
+                fd = open(abs_file, "rb")
                 break
     if not fd:
-        security.err("Configuration file '"+configfile+"' not found.")
+        raise OptionError("Configuration file '%s' not found." % configfile)
 
     # read in the domain config file, finding the label line
     ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
@@ -79,7 +79,7 @@ def get_domain_label(configfile):
 
     # send error message if we didn't find anything
     if acline == "":
-        security.err("Domain not labeled")
+        raise security.ACMError("Domain not labeled")
 
     # print out the label
     (title, data) = acline.split("=", 1)
@@ -89,7 +89,7 @@ def get_domain_label(configfile):
     print data
 
 
-def main (argv):
+def main(argv):
     if len(argv) != 3:
         raise OptionError('Requires 2 arguments')
 
@@ -103,6 +103,11 @@ def main (argv):
         raise OptionError('First subcommand argument must be "dom" or "res"')
 
 if __name__ == '__main__':
-    main(sys.argv)
+    try:
+        main(sys.argv)
+    except Exception, e:
+        sys.stderr.write('Error: %s\n' % str(e))
+        sys.exit(-1)
+        
 
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.