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