[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>
This commit is contained in:
atse@norwich.uk.xensource.com committed 2006-09-28 12:23:21 +01:00
1 parent 3c9f8469ed
commit 665dff5cd1
1 file changed
+17 -12
+17 -12
View File
@@ -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)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.