direct-io.hg

changeset 11640:911b7c6d03ea

[XM] Removed traceback printing for non ACMError exceptions

Removing try,except block as cfgbootpolicy should allow exceptions to
propagate instead of printing traceback to stdout.
(http://bugzilla.xensource.com/bugzilla/show_bug.cgi?id=778)

Changed usage of string.join, string.split when creating security
policy path name.

Signed-off-by: Alastair Tse <atse@xensource.com>
author atse@norwich.uk.xensource.com
date Thu Sep 28 11:50:51 2006 +0100 (2006-09-28)
parents e57815fcc352
children 0de76117acb6
files tools/python/xen/xm/cfgbootpolicy.py
line diff
     1.1 --- a/tools/python/xen/xm/cfgbootpolicy.py	Thu Sep 28 12:03:10 2006 +0100
     1.2 +++ b/tools/python/xen/xm/cfgbootpolicy.py	Thu Sep 28 11:50:51 2006 +0100
     1.3 @@ -140,44 +140,41 @@ def insert_policy(boot_file, kernel_vers
     1.4  
     1.5  
     1.6  def main(argv):
     1.7 -    try:
     1.8 -        user_kver = None
     1.9 -        policy = None
    1.10 -        if len(argv) == 2:
    1.11 -            policy = argv[1]
    1.12 -        elif len(argv) == 3:
    1.13 -            policy = argv[1]
    1.14 -            user_kver = argv[2]
    1.15 -        else:
    1.16 -            raise OptionError('Invalid number of arguments')
    1.17 -
    1.18 -        if not policy_name_re.match(policy):
    1.19 -            err("Illegal policy name \'" + policy + "\'")
    1.20 +    user_kver = None
    1.21 +    policy = None
    1.22 +    if len(argv) == 2:
    1.23 +        policy = argv[1]
    1.24 +    elif len(argv) == 3:
    1.25 +        policy = argv[1]
    1.26 +        user_kver = argv[2]
    1.27 +    else:
    1.28 +        raise OptionError('Invalid number of arguments')
    1.29 +    
    1.30 +    if not policy_name_re.match(policy):
    1.31 +        raise OptionError("Illegal policy name: '%s'" % policy)
    1.32  
    1.33 -        policy_file = policy_dir_prefix + "/" + string.join(string.split(policy, "."), "/")
    1.34 -        src_binary_policy_file = policy_file + ".bin"
    1.35 -        #check if .bin exists or if policy file exists
    1.36 -        if not os.path.isfile(src_binary_policy_file):
    1.37 -            if not os.path.isfile(policy_file + "-security_policy.xml"):
    1.38 -                err("Unknown policy \'" + policy +"\'")
    1.39 -            else:
    1.40 -                err("Cannot find binary file for policy \'" + policy +
    1.41 -                    "\'. Please use makepolicy to create binary file.")
    1.42 -        dst_binary_policy_file = "/boot/" + policy + ".bin"
    1.43 -        shutil.copyfile(src_binary_policy_file, dst_binary_policy_file)
    1.44 -
    1.45 -        kernel_version = determine_kernelversion(user_kver)
    1.46 -        insert_policy(boot_filename, kernel_version, policy)
    1.47 -        print "Boot entry created and \'%s\' copied to /boot" % (policy + ".bin")
    1.48 -
    1.49 -    except ACMError:
    1.50 -        sys.exit(-1)
    1.51 -    except:
    1.52 -        traceback.print_exc(limit=1)
    1.53 -        sys.exit(-1)
    1.54 -
    1.55 -
    1.56 +    policy_file = '/'.join([policy_dir_prefix] + policy.split('.'))
    1.57 +    src_binary_policy_file = policy_file + ".bin"
    1.58 +    #check if .bin exists or if policy file exists
    1.59 +    if not os.path.isfile(src_binary_policy_file):
    1.60 +        if not os.path.isfile(policy_file + "-security_policy.xml"):
    1.61 +            raise OptionError("Unknown policy '%s'" % policy)
    1.62 +        else:
    1.63 +            err_msg = "Cannot find binary file for policy '%s'." % policy
    1.64 +            err_msg += " Please use makepolicy to create binary file."
    1.65 +            raise OptionError(err_msg)
    1.66 +    
    1.67 +    dst_binary_policy_file = "/boot/" + policy + ".bin"
    1.68 +    shutil.copyfile(src_binary_policy_file, dst_binary_policy_file)
    1.69 +    
    1.70 +    kernel_version = determine_kernelversion(user_kver)
    1.71 +    insert_policy(boot_filename, kernel_version, policy)
    1.72 +    print "Boot entry created and \'%s\' copied to /boot" % (policy + ".bin")
    1.73  
    1.74  if __name__ == '__main__':
    1.75 -    main(sys.argv)
    1.76 -
    1.77 +    try:
    1.78 +        main(sys.argv)
    1.79 +    except Exception, e:
    1.80 +        sys.stderr.write('Error: ' + str(e) + '\n')    
    1.81 +        sys.exit(-1)
    1.82 +