change 'except' syntax to python 3 style.
Everywhere that there occurred: except Exception, e: changed to except Exception as e:
This commit is contained in:
parent
c826d27388
commit
cf95473556
@ -65,7 +65,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
(outfmt, errfmt) = CC.get_output_cfg(cc.cfg,modename)
|
(outfmt, errfmt) = CC.get_output_cfg(cc.cfg,modename)
|
||||||
CC.redirect_output(outfmt, errfmt)
|
CC.redirect_output(outfmt, errfmt)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
err("Failed to get and set output config: %s\n" % e)
|
err("Failed to get and set output config: %s\n" % e)
|
||||||
|
|
||||||
cloudinit.logging_set_from_cfg(cc.cfg)
|
cloudinit.logging_set_from_cfg(cc.cfg)
|
||||||
|
@ -57,7 +57,7 @@ def main():
|
|||||||
cfg = cloudinit.get_base_cfg()
|
cfg = cloudinit.get_base_cfg()
|
||||||
(outfmt, errfmt) = CC.get_output_cfg(cfg,"init")
|
(outfmt, errfmt) = CC.get_output_cfg(cfg,"init")
|
||||||
CC.redirect_output(outfmt, errfmt)
|
CC.redirect_output(outfmt, errfmt)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
warn("Failed to get and set output config: %s\n" % e)
|
warn("Failed to get and set output config: %s\n" % e)
|
||||||
|
|
||||||
msg = "cloud-init %s running: %s. up %s seconds" % (cmd, now, uptime)
|
msg = "cloud-init %s running: %s. up %s seconds" % (cmd, now, uptime)
|
||||||
@ -70,7 +70,7 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
cloudinit.initfs()
|
cloudinit.initfs()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
warn("failed to initfs, likely bad things to come: %s\n" % str(e))
|
warn("failed to initfs, likely bad things to come: %s\n" % str(e))
|
||||||
|
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ def main():
|
|||||||
if outfmt_orig != outfmt or errfmt_orig != errfmt:
|
if outfmt_orig != outfmt or errfmt_orig != errfmt:
|
||||||
warn("stdout, stderr changing to (%s,%s)" % (outfmt,errfmt))
|
warn("stdout, stderr changing to (%s,%s)" % (outfmt,errfmt))
|
||||||
CC.redirect_output(outfmt, errfmt)
|
CC.redirect_output(outfmt, errfmt)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
warn("Failed to get and set output config: %s\n" % e)
|
warn("Failed to get and set output config: %s\n" % e)
|
||||||
|
|
||||||
module_list = CC.read_cc_modules(cc.cfg,"cloud_init_modules")
|
module_list = CC.read_cc_modules(cc.cfg,"cloud_init_modules")
|
||||||
|
@ -38,6 +38,6 @@ def handle(name,cfg,cloud,log,args):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
apply_locale(locale)
|
apply_locale(locale)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
log.debug(traceback.format_exc(e))
|
log.debug(traceback.format_exc(e))
|
||||||
raise Exception("failed to apply locale %s" % locale)
|
raise Exception("failed to apply locale %s" % locale)
|
||||||
|
@ -88,7 +88,7 @@ def handle(name,cfg,cloud,log,args):
|
|||||||
util.readurl(url, submit_keys)
|
util.readurl(url, submit_keys)
|
||||||
log.debug("succeeded submit to %s on try %i" % (url, i+1))
|
log.debug("succeeded submit to %s on try %i" % (url, i+1))
|
||||||
return
|
return
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
log.debug("failed to post to %s on try %i" % (url, i+1))
|
log.debug("failed to post to %s on try %i" % (url, i+1))
|
||||||
last_e = e
|
last_e = e
|
||||||
sleep(3)
|
sleep(3)
|
||||||
|
@ -34,7 +34,7 @@ def handle(name,cfg,cloud,log,args):
|
|||||||
cmd = ['blkid', '-sTYPE', '-ovalue', '/dev/root']
|
cmd = ['blkid', '-sTYPE', '-ovalue', '/dev/root']
|
||||||
try:
|
try:
|
||||||
(fstype,err) = util.subp(cmd)
|
(fstype,err) = util.subp(cmd)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
log.warn("Failed to get filesystem type via %s" % cmd)
|
log.warn("Failed to get filesystem type via %s" % cmd)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ def handle(name,cfg,cloud,log,args):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
(out,err) = util.subp(resize_cmd)
|
(out,err) = util.subp(resize_cmd)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
log.warn("Failed to resize filesystem (%s,%s)" % cmd)
|
log.warn("Failed to resize filesystem (%s,%s)" % cmd)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ def handle(name,cfg,cloud,log,args):
|
|||||||
try:
|
try:
|
||||||
content = util.readurl(url)
|
content = util.readurl(url)
|
||||||
util.write_file(fname, content, mode=0700)
|
util.write_file(fname, content, mode=0700)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if not first_e: first_e = None
|
if not first_e: first_e = None
|
||||||
log.warn("%s failed to read %s: %s" % (my_name, url, e))
|
log.warn("%s failed to read %s: %s" % (my_name, url, e))
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ def handle(name,cfg,cloud,log,args):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
util.write_file(filename, content + "\n", omode=omode)
|
util.write_file(filename, content + "\n", omode=omode)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
log.debug(traceback.format_exc(e))
|
log.debug(traceback.format_exc(e))
|
||||||
elst.append((content, "failed to write to %s" % filename))
|
elst.append((content, "failed to write to %s" % filename))
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ def handle(name,cfg,cloud,log,args):
|
|||||||
p = util.subp(['service', 'rsyslog', 'restart'])
|
p = util.subp(['service', 'rsyslog', 'restart'])
|
||||||
restarted = True
|
restarted = True
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
elst.append(("restart", str(e)))
|
elst.append(("restart", str(e)))
|
||||||
|
|
||||||
if restarted:
|
if restarted:
|
||||||
|
@ -26,7 +26,7 @@ def handle(name,cfg,cloud,log,args):
|
|||||||
try:
|
try:
|
||||||
hostname = util.get_cfg_option_str(cfg,"hostname",cloud.get_hostname())
|
hostname = util.get_cfg_option_str(cfg,"hostname",cloud.get_hostname())
|
||||||
set_hostname(hostname, log)
|
set_hostname(hostname, log)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
util.logexc(log)
|
util.logexc(log)
|
||||||
log.warn("failed to set hostname\n")
|
log.warn("failed to set hostname\n")
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ def handle(name,cfg,cloud,log,args):
|
|||||||
hostname = util.get_cfg_option_str(cfg,"hostname",cloud.get_hostname())
|
hostname = util.get_cfg_option_str(cfg,"hostname",cloud.get_hostname())
|
||||||
prev ="%s/%s" % (cloud.get_cpath('datadir'),"previous-hostname")
|
prev ="%s/%s" % (cloud.get_cpath('datadir'),"previous-hostname")
|
||||||
update_hostname(hostname, prev, log)
|
update_hostname(hostname, prev, log)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
log.warn("failed to set hostname\n")
|
log.warn("failed to set hostname\n")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ def read_hostname(filename, default=None):
|
|||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
if line:
|
if line:
|
||||||
return line
|
return line
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
if e.errno != errno.ENOENT: raise
|
if e.errno != errno.ENOENT: raise
|
||||||
return default
|
return default
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ def update_hostname(hostname, prev_file, log):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
hostname_prev = read_hostname(prev_file)
|
hostname_prev = read_hostname(prev_file)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
log.warn("Failed to open %s: %s" % (prev_file, e))
|
log.warn("Failed to open %s: %s" % (prev_file, e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -99,9 +99,9 @@ class DataSourceEc2(DataSource.DataSource):
|
|||||||
resp = urllib2.urlopen(req, timeout=2)
|
resp = urllib2.urlopen(req, timeout=2)
|
||||||
if resp.read() != "": return True
|
if resp.read() != "": return True
|
||||||
reason = "empty data [%s]" % resp.getcode()
|
reason = "empty data [%s]" % resp.getcode()
|
||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError as e:
|
||||||
reason = "http error [%s]" % e.code
|
reason = "http error [%s]" % e.code
|
||||||
except urllib2.URLError, e:
|
except urllib2.URLError as e:
|
||||||
reason = "url error [%s]" % e.reason
|
reason = "url error [%s]" % e.reason
|
||||||
|
|
||||||
if x == 0:
|
if x == 0:
|
||||||
|
@ -222,7 +222,7 @@ class CloudInit:
|
|||||||
def set_cur_instance(self):
|
def set_cur_instance(self):
|
||||||
try:
|
try:
|
||||||
os.unlink(cur_instance_link)
|
os.unlink(cur_instance_link)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENOENT: raise
|
if e.errno != errno.ENOENT: raise
|
||||||
|
|
||||||
os.symlink("./instances/%s" % self.get_instance_id(), cur_instance_link)
|
os.symlink("./instances/%s" % self.get_instance_id(), cur_instance_link)
|
||||||
|
@ -43,7 +43,7 @@ def retry_url(url, retry_on_404=True):
|
|||||||
req = urllib2.Request(url)
|
req = urllib2.Request(url)
|
||||||
resp = urllib2.urlopen(req)
|
resp = urllib2.urlopen(req)
|
||||||
return resp.read()
|
return resp.read()
|
||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError as e:
|
||||||
# in 2.6 you use getcode(), in 2.5 and earlier you use code
|
# in 2.6 you use getcode(), in 2.5 and earlier you use code
|
||||||
if hasattr(e, 'getcode'):
|
if hasattr(e, 'getcode'):
|
||||||
code = e.getcode()
|
code = e.getcode()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user