diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-01-17 12:33:38 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-01-17 12:33:38 -0500 |
commit | 89eafa0a6c1a28331b3b3c59ba94803052c63583 (patch) | |
tree | 8ebd0885d0caded95d6c5c6d471b0c35fc16272a | |
parent | 1d00c0936bfc63117493d89268da8c81611b3c40 (diff) | |
download | vyos-cloud-init-89eafa0a6c1a28331b3b3c59ba94803052c63583.tar.gz vyos-cloud-init-89eafa0a6c1a28331b3b3c59ba94803052c63583.zip |
[PATCH 1/4] Fix pylint conventions C0321 (more than one statement on a single line)
From: Juerg Haefliger <juerg.haefliger@hp.com>
25 files changed, 202 insertions, 101 deletions
diff --git a/cloud-init.py b/cloud-init.py index 8279a0b0..ba2b4499 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -117,7 +117,8 @@ def main(): try: os.unlink(nonet_path) except OSError as e: - if e.errno != errno.ENOENT: raise + if e.errno != errno.ENOENT: + raise msg = "cloud-init %s running: %s. up %s seconds" % (cmd, now, uptime) sys.stderr.write(msg + "\n") diff --git a/cloudinit/CloudConfig/__init__.py b/cloudinit/CloudConfig/__init__.py index f5c4143c..a30940fa 100644 --- a/cloudinit/CloudConfig/__init__.py +++ b/cloudinit/CloudConfig/__init__.py @@ -49,7 +49,8 @@ class CloudConfig(): cloudinit.log.critical("Failed loading of cloud config '%s'. Continuing with empty config\n" % cfgfile) cloudinit.log.debug(traceback.format_exc() + "\n") cfg = None - if cfg is None: cfg = { } + if cfg is None: + cfg = { } try: ds_cfg = self.cloud.datasource.get_config_obj() @@ -76,7 +77,8 @@ class CloudConfig(): # reads a cloudconfig module list, returns # a 2 dimensional array suitable to pass to run_cc_modules def read_cc_modules(cfg,name): - if name not in cfg: return([]) + if name not in cfg: + return([]) module_list = [] # create 'module_list', an array of arrays # where array[0] = config @@ -126,13 +128,15 @@ def run_cc_modules(cc,module_list,log): # None if if none is given def get_output_cfg(cfg, mode="init"): ret = [ None, None ] - if not 'output' in cfg: return ret + if not 'output' in cfg: + return ret outcfg = cfg['output'] if mode in outcfg: modecfg = outcfg[mode] else: - if 'all' not in outcfg: return ret + if 'all' not in outcfg: + return ret # if there is a 'all' item in the output list # then it applies to all users of this (init, config, final) modecfg = outcfg['all'] @@ -143,7 +147,8 @@ def get_output_cfg(cfg, mode="init"): # if its a list, then we expect (stdout, stderr) if isinstance(modecfg,list): - if len(modecfg) > 0: ret[0] = modecfg[0] + if len(modecfg) > 0: + ret[0] = modecfg[0] if len(modecfg) > 1: ret[1] = modecfg[1] @@ -157,11 +162,13 @@ def get_output_cfg(cfg, mode="init"): # if err's entry == "&1", then make it same as stdout # as in shell syntax of "echo foo >/dev/null 2>&1" - if ret[1] == "&1": ret[1] = ret[0] + if ret[1] == "&1": + ret[1] = ret[0] swlist = [ ">>", ">", "|" ] for i in range(len(ret)): - if not ret[i]: continue + if not ret[i]: + continue val = ret[i].lstrip() found = False for s in swlist: @@ -191,7 +198,8 @@ def redirect_output(outfmt,errfmt, o_out=sys.stdout, o_err=sys.stderr): (mode, arg) = outfmt.split(" ",1) if mode == ">" or mode == ">>": owith = "ab" - if mode == ">": owith = "wb" + if mode == ">": + owith = "wb" new_fp = open(arg, owith) elif mode == "|": proc = subprocess.Popen(arg, shell=True, stdin=subprocess.PIPE) @@ -209,7 +217,8 @@ def redirect_output(outfmt,errfmt, o_out=sys.stdout, o_err=sys.stderr): (mode, arg) = errfmt.split(" ",1) if mode == ">" or mode == ">>": owith = "ab" - if mode == ">": owith = "wb" + if mode == ">": + owith = "wb" new_fp = open(arg, owith) elif mode == "|": proc = subprocess.Popen(arg, shell=True, stdin=subprocess.PIPE) @@ -223,13 +232,15 @@ def redirect_output(outfmt,errfmt, o_out=sys.stdout, o_err=sys.stderr): def run_per_instance(name, func, args, clear_on_fail=False): semfile = "%s/%s" % (cloudinit.get_ipath_cur("data"),name) - if os.path.exists(semfile): return + if os.path.exists(semfile): + return util.write_file(semfile,str(time.time())) try: func(*args) except: - if clear_on_fail: os.unlink(semfile) + if clear_on_fail: + os.unlink(semfile) raise # apt_get top level command (install, update...), and args to pass it diff --git a/cloudinit/CloudConfig/cc_apt_update_upgrade.py b/cloudinit/CloudConfig/cc_apt_update_upgrade.py index 0cbe02d4..e911db89 100644 --- a/cloudinit/CloudConfig/cc_apt_update_upgrade.py +++ b/cloudinit/CloudConfig/cc_apt_update_upgrade.py @@ -104,7 +104,8 @@ def handle(_name,cfg,cloud,log,_args): def mirror2lists_fileprefix(mirror): string=mirror # take of http:// or ftp:// - if string.endswith("/"): string=string[0:-1] + if string.endswith("/"): + string=string[0:-1] pos=string.find("://") if pos >= 0: string=string[pos+3:] @@ -115,7 +116,8 @@ def rename_apt_lists(omirror,new_mirror,lists_d="/var/lib/apt/lists"): oprefix="%s/%s" % (lists_d,mirror2lists_fileprefix(omirror)) nprefix="%s/%s" % (lists_d,mirror2lists_fileprefix(new_mirror)) - if(oprefix==nprefix): return + if(oprefix==nprefix): + return olen=len(oprefix) for filename in glob.glob("%s_*" % oprefix): os.rename(filename,"%s%s" % (nprefix, filename[olen:])) @@ -143,7 +145,8 @@ def add_sources(srclist, searchList=None): source=ent['source'] if source.startswith("ppa:"): - try: util.subp(["add-apt-repository",source]) + try: + util.subp(["add-apt-repository",source]) except: elst.append([source, "add-apt-repository failed"]) continue @@ -159,7 +162,8 @@ def add_sources(srclist, searchList=None): if ( ent.has_key('keyid') and not ent.has_key('key') ): ks = "keyserver.ubuntu.com" - if ent.has_key('keyserver'): ks = ent['keyserver'] + if ent.has_key('keyserver'): + ks = ent['keyserver'] try: ent['key'] = util.getkeybyid(ent['keyid'], ks) except: @@ -167,11 +171,13 @@ def add_sources(srclist, searchList=None): continue if ent.has_key('key'): - try: util.subp(('apt-key', 'add', '-'), ent['key']) + try: + util.subp(('apt-key', 'add', '-'), ent['key']) except: elst.append([source, "failed add key"]) - try: util.write_file(ent['filename'], source + "\n", omode="ab") + try: + util.write_file(ent['filename'], source + "\n", omode="ab") except: elst.append([source, "failed write to file %s" % ent['filename']]) diff --git a/cloudinit/CloudConfig/cc_byobu.py b/cloudinit/CloudConfig/cc_byobu.py index dd510dda..76c6f286 100644 --- a/cloudinit/CloudConfig/cc_byobu.py +++ b/cloudinit/CloudConfig/cc_byobu.py @@ -25,7 +25,8 @@ def handle(_name,cfg,_cloud,log,args): else: value = util.get_cfg_option_str(cfg,"byobu_by_default","") - if not value: return + if not value: + return if value == "user" or value == "system": value = "enable-%s" % value diff --git a/cloudinit/CloudConfig/cc_chef.py b/cloudinit/CloudConfig/cc_chef.py index 977fe80f..c40f1293 100644 --- a/cloudinit/CloudConfig/cc_chef.py +++ b/cloudinit/CloudConfig/cc_chef.py @@ -25,7 +25,8 @@ ruby_version_default = "1.8" def handle(_name,cfg,cloud,log,_args): # If there isn't a chef key in the configuration don't do anything - if not cfg.has_key('chef'): return + if not cfg.has_key('chef'): + return chef_cfg = cfg['chef'] # ensure the chef directories we use exist @@ -57,7 +58,8 @@ def handle(_name,cfg,cloud,log,_args): initial_json['run_list'] = chef_cfg['run_list'] if chef_cfg.has_key('initial_attributes'): initial_attributes = chef_cfg['initial_attributes'] - for k in initial_attributes.keys(): initial_json[k] = initial_attributes[k] + for k in initial_attributes.keys(): + initial_json[k] = initial_attributes[k] firstboot_json_fh.write(json.dumps(initial_json)) # If chef is not installed, we install chef based on 'install_type' diff --git a/cloudinit/CloudConfig/cc_grub_dpkg.py b/cloudinit/CloudConfig/cc_grub_dpkg.py index 97d79bdb..fde8cca1 100644 --- a/cloudinit/CloudConfig/cc_grub_dpkg.py +++ b/cloudinit/CloudConfig/cc_grub_dpkg.py @@ -33,10 +33,13 @@ def handle(_name,cfg,_cloud,log,_args): if (( os.path.exists("/dev/sda1") and not os.path.exists("/dev/sda") ) or ( os.path.exists("/dev/xvda1") and not os.path.exists("/dev/xvda") )): - if idevs == None: idevs="" - if idevs_empty == None: idevs_empty="true" + if idevs == None: + idevs="" + if idevs_empty == None: + idevs_empty="true" else: - if idevs_empty == None: idevs_empty="false" + if idevs_empty == None: + idevs_empty="false" if idevs == None: idevs = "/dev/sda" for dev in ( "/dev/sda", "/dev/vda", "/dev/sda1", "/dev/vda1"): diff --git a/cloudinit/CloudConfig/cc_locale.py b/cloudinit/CloudConfig/cc_locale.py index 8e91d3bf..31e3f56e 100644 --- a/cloudinit/CloudConfig/cc_locale.py +++ b/cloudinit/CloudConfig/cc_locale.py @@ -37,7 +37,8 @@ def handle(_name,cfg,cloud,log,args): locale_cfgfile = util.get_cfg_option_str(cfg, "locale_configfile", "/etc/default/locale") - if not locale: return + if not locale: + return log.debug("setting locale to %s" % locale) diff --git a/cloudinit/CloudConfig/cc_mcollective.py b/cloudinit/CloudConfig/cc_mcollective.py index 38fe4a3c..0d1f01b3 100644 --- a/cloudinit/CloudConfig/cc_mcollective.py +++ b/cloudinit/CloudConfig/cc_mcollective.py @@ -34,13 +34,17 @@ class FakeSecHead(object): self.sechead = '[nullsection]\n' def readline(self): if self.sechead: - try: return self.sechead - finally: self.sechead = None - else: return self.fp.readline() + try: + return self.sechead + finally: + self.sechead = None + else: + return self.fp.readline() def handle(_name,cfg,_cloud,_log,_args): # If there isn't a mcollective key in the configuration don't do anything - if not cfg.has_key('mcollective'): return + if not cfg.has_key('mcollective'): + return mcollective_cfg = cfg['mcollective'] # Start by installing the mcollective package ... cc.install_packages(("mcollective",)) diff --git a/cloudinit/CloudConfig/cc_mounts.py b/cloudinit/CloudConfig/cc_mounts.py index a3036d5a..94ad1bba 100644 --- a/cloudinit/CloudConfig/cc_mounts.py +++ b/cloudinit/CloudConfig/cc_mounts.py @@ -50,7 +50,8 @@ def handle(_name,cfg,cloud,log,_args): for i in range(len(cfgmnt)): # skip something that wasn't a list - if not isinstance(cfgmnt[i],list): continue + if not isinstance(cfgmnt[i],list): + continue # workaround, allow user to specify 'ephemeral' # rather than more ec2 correct 'ephemeral0' @@ -98,7 +99,8 @@ def handle(_name,cfg,cloud,log,_args): # entry has the same device name for defmnt in defmnts: devname = cloud.device_name_to_device(defmnt[0]) - if devname is None: continue + if devname is None: + continue if devname.startswith("/"): defmnt[0] = devname else: @@ -110,7 +112,8 @@ def handle(_name,cfg,cloud,log,_args): cfgmnt_has = True break - if cfgmnt_has: continue + if cfgmnt_has: + continue cfgmnt.append(defmnt) @@ -118,7 +121,8 @@ def handle(_name,cfg,cloud,log,_args): # if the second field is None (not the string, the value) we skip it actlist = [x for x in cfgmnt if x[1] is not None] - if len(actlist) == 0: return + if len(actlist) == 0: + return comment="comment=cloudconfig" cc_lines = [ ] @@ -127,8 +131,10 @@ def handle(_name,cfg,cloud,log,_args): for line in actlist: # write 'comment' in the fs_mntops, entry, claiming this line[3]="%s,comment=cloudconfig" % line[3] - if line[2] == "swap": needswap = True - if line[1].startswith("/"): dirs.append(line[1]) + if line[2] == "swap": + needswap = True + if line[1].startswith("/"): + dirs.append(line[1]) cc_lines.append('\t'.join(line)) fstab_lines = [ ] @@ -137,7 +143,8 @@ def handle(_name,cfg,cloud,log,_args): for line in fstab.read().splitlines(): try: toks = ws.split(line) - if toks[3].find(comment) != -1: continue + if toks[3].find(comment) != -1: + continue except: pass fstab_lines.append(line) @@ -150,13 +157,20 @@ def handle(_name,cfg,cloud,log,_args): fstab.close() if needswap: - try: util.subp(("swapon", "-a")) - except: log.warn("Failed to enable swap") + try: + util.subp(("swapon", "-a")) + except: + log.warn("Failed to enable swap") for d in dirs: - if os.path.exists(d): continue - try: os.makedirs(d) - except: log.warn("Failed to make '%s' config-mount\n",d) + if os.path.exists(d): + continue + try: + os.makedirs(d) + except: + log.warn("Failed to make '%s' config-mount\n",d) - try: util.subp(("mount","-a")) - except: log.warn("'mount -a' failed") + try: + util.subp(("mount","-a")) + except: + log.warn("'mount -a' failed") diff --git a/cloudinit/CloudConfig/cc_phone_home.py b/cloudinit/CloudConfig/cc_phone_home.py index 7897d31b..008139b7 100644 --- a/cloudinit/CloudConfig/cc_phone_home.py +++ b/cloudinit/CloudConfig/cc_phone_home.py @@ -35,7 +35,8 @@ def handle(_name,cfg,cloud,log,args): if len(args) != 0: ph_cfg = util.readconf(args[0]) else: - if not 'phone_home' in cfg: return + if not 'phone_home' in cfg: + return ph_cfg = cfg['phone_home'] if 'url' not in ph_cfg: diff --git a/cloudinit/CloudConfig/cc_puppet.py b/cloudinit/CloudConfig/cc_puppet.py index 3748559a..1a8c7f3a 100644 --- a/cloudinit/CloudConfig/cc_puppet.py +++ b/cloudinit/CloudConfig/cc_puppet.py @@ -27,7 +27,8 @@ import cloudinit.util as util def handle(_name,cfg,cloud,log,_args): # If there isn't a puppet key in the configuration don't do anything - if not cfg.has_key('puppet'): return + if not cfg.has_key('puppet'): + return puppet_cfg = cfg['puppet'] # Start by installing the puppet package ... cc.install_packages(("puppet",)) diff --git a/cloudinit/CloudConfig/cc_resizefs.py b/cloudinit/CloudConfig/cc_resizefs.py index adec70be..29e0fa34 100644 --- a/cloudinit/CloudConfig/cc_resizefs.py +++ b/cloudinit/CloudConfig/cc_resizefs.py @@ -33,7 +33,8 @@ def handle(_name,cfg,_cloud,log,args): else: resize_root = util.get_cfg_option_bool(cfg,"resize_rootfs",True) - if not resize_root: return + if not resize_root: + return # this really only uses the filename from mktemp, then we mknod into it (fd, devpth) = tempfile.mkstemp() diff --git a/cloudinit/CloudConfig/cc_rightscale_userdata.py b/cloudinit/CloudConfig/cc_rightscale_userdata.py index 2b43023c..fdbee954 100644 --- a/cloudinit/CloudConfig/cc_rightscale_userdata.py +++ b/cloudinit/CloudConfig/cc_rightscale_userdata.py @@ -51,7 +51,8 @@ def handle(_name,_cfg,cloud,log,_args): try: mdict = parse_qs(ud) - if not my_hookname in mdict: return + if not my_hookname in mdict: + return except: log.warn("failed to urlparse.parse_qa(userdata_raw())") raise @@ -66,7 +67,8 @@ def handle(_name,_cfg,cloud,log,_args): content = util.readurl(url) util.write_file(fname, content, mode=0700) 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)) if first_e: diff --git a/cloudinit/CloudConfig/cc_rsyslog.py b/cloudinit/CloudConfig/cc_rsyslog.py index ab85a6d8..90d09545 100644 --- a/cloudinit/CloudConfig/cc_rsyslog.py +++ b/cloudinit/CloudConfig/cc_rsyslog.py @@ -33,7 +33,8 @@ def handle(_name,cfg,_cloud,log,_args): # *.* @@syslogd.example.com # process 'rsyslog' - if not 'rsyslog' in cfg: return + if not 'rsyslog' in cfg: + return def_dir = cfg.get('rsyslog_dir', DEF_DIR) def_fname = cfg.get('rsyslog_filename', DEF_FILENAME) diff --git a/cloudinit/CloudConfig/cc_ssh.py b/cloudinit/CloudConfig/cc_ssh.py index 0aad2187..897ba9dc 100644 --- a/cloudinit/CloudConfig/cc_ssh.py +++ b/cloudinit/CloudConfig/cc_ssh.py @@ -33,8 +33,10 @@ def handle(_name,cfg,cloud,log,_args): # remove the static keys from the pristine image if cfg.get("ssh_deletekeys", True): for f in glob.glob("/etc/ssh/ssh_host_*key*"): - try: os.unlink(f) - except: pass + try: + os.unlink(f) + except: + pass if cfg.has_key("ssh_keys"): # if there are keys in cloud-config, use them @@ -56,7 +58,8 @@ def handle(_name,cfg,cloud,log,_args): cmd = 'o=$(ssh-keygen -yf "%s") && echo "$o" root@localhost > "%s"' for priv,pub in priv2pub.iteritems(): - if pub in cfg['ssh_keys'] or not priv in cfg['ssh_keys']: continue + if pub in cfg['ssh_keys'] or not priv in cfg['ssh_keys']: + continue pair=(key2file[priv][0], key2file[pub][0]) subprocess.call(('sh', '-xc', cmd % pair)) log.debug("generated %s from %s" % pair) diff --git a/cloudinit/CloudConfig/cc_ssh_import_id.py b/cloudinit/CloudConfig/cc_ssh_import_id.py index 7e7a54a1..e4588eaf 100644 --- a/cloudinit/CloudConfig/cc_ssh_import_id.py +++ b/cloudinit/CloudConfig/cc_ssh_import_id.py @@ -29,7 +29,8 @@ def handle(_name,cfg,_cloud,log,args): user = util.get_cfg_option_str(cfg,"user","ubuntu") ids = util.get_cfg_option_list_or_str(cfg,"ssh_import_id",[]) - if len(ids) == 0: return + if len(ids) == 0: + return cmd = [ "sudo", "-Hu", user, "ssh-import-id" ] + ids diff --git a/cloudinit/CloudConfig/cc_timezone.py b/cloudinit/CloudConfig/cc_timezone.py index 26b2796d..091271f4 100644 --- a/cloudinit/CloudConfig/cc_timezone.py +++ b/cloudinit/CloudConfig/cc_timezone.py @@ -30,7 +30,8 @@ def handle(_name,cfg,_cloud,log,args): else: timezone = util.get_cfg_option_str(cfg,"timezone",False) - if not timezone: return + if not timezone: + return tz_file = "%s/%s" % (tz_base , timezone) diff --git a/cloudinit/CloudConfig/cc_update_hostname.py b/cloudinit/CloudConfig/cc_update_hostname.py index 4bc1cb2b..9d09bbb8 100644 --- a/cloudinit/CloudConfig/cc_update_hostname.py +++ b/cloudinit/CloudConfig/cc_update_hostname.py @@ -51,7 +51,8 @@ def read_hostname(filename, default=None): if line: return line except IOError as e: - if e.errno != errno.ENOENT: raise + if e.errno != errno.ENOENT: + raise return default def update_hostname(hostname, prev_file, log): diff --git a/cloudinit/DataSource.py b/cloudinit/DataSource.py index ac79f757..edf62359 100644 --- a/cloudinit/DataSource.py +++ b/cloudinit/DataSource.py @@ -64,7 +64,8 @@ class DataSource: def get_public_ssh_keys(self): keys = [] - if not self.metadata.has_key('public-keys'): return([]) + if not self.metadata.has_key('public-keys'): + return([]) if isinstance(self.metadata['public-keys'], str): return([self.metadata['public-keys'],]) @@ -163,7 +164,8 @@ def list_sources(cfg_list, depends, pkglist=None): retlist = [] for ds_coll in cfg_list: for pkg in pkglist: - if pkg: pkg="%s." % pkg + if pkg: + pkg="%s." % pkg try: mod = __import__("%sDataSource%s" % (pkg, ds_coll)) if pkg: diff --git a/cloudinit/DataSourceEc2.py b/cloudinit/DataSourceEc2.py index 9191e647..1c2bac9f 100644 --- a/cloudinit/DataSourceEc2.py +++ b/cloudinit/DataSourceEc2.py @@ -174,7 +174,8 @@ class DataSourceEc2(DataSource.DataSource): return(found) for nfrom, tlist in mappings.items(): - if not short.startswith(nfrom): continue + if not short.startswith(nfrom): + continue for nto in tlist: cand = "/dev/%s%s" % (nto, short[len(nfrom):]) if os.path.exists(cand): @@ -192,7 +193,8 @@ class DataSourceEc2(DataSource.DataSource): def is_vpc(self): # per comment in LP: #615545 - ph="public-hostname"; p4="public-ipv4" + ph="public-hostname" + p4="public-ipv4" if ((ph not in self.metadata or self.metadata[ph] == "") and (p4 not in self.metadata or self.metadata[p4] == "")): return True diff --git a/cloudinit/DataSourceNoCloud.py b/cloudinit/DataSourceNoCloud.py index 2f4bd604..3ddae914 100644 --- a/cloudinit/DataSourceNoCloud.py +++ b/cloudinit/DataSourceNoCloud.py @@ -110,7 +110,8 @@ def parse_cmdline_data(ds_id,fill,cmdline=None): # cmdline can contain: # ds=nocloud[;key=val;key=val] for tok in cmdline.split(): - if tok.startswith(ds_id): argline=tok.split("=",1) + if tok.startswith(ds_id): + argline=tok.split("=",1) # argline array is now 'nocloud' followed optionally by # a ';' and then key=value pairs also terminated with ';' @@ -128,7 +129,8 @@ def parse_cmdline_data(ds_id,fill,cmdline=None): except: k=item v=None - if k in s2l: k=s2l[k] + if k in s2l: + k=s2l[k] fill[k]=v return(True) diff --git a/cloudinit/DataSourceOVF.py b/cloudinit/DataSourceOVF.py index 1c510688..cdfa0c64 100644 --- a/cloudinit/DataSourceOVF.py +++ b/cloudinit/DataSourceOVF.py @@ -65,7 +65,8 @@ class DataSourceOVF(DataSource.DataSource): 'vmware-guestd' : transport_vmware_guestd, } for name, transfunc in np.iteritems(): (contents, _dev, _fname) = transfunc() - if contents: break + if contents: + break if contents: (md, ud, cfg) = read_ovf_environment(contents) @@ -103,7 +104,8 @@ class DataSourceOVF(DataSource.DataSource): return True def get_public_ssh_keys(self): - if not 'public-keys' in self.metadata: return([]) + if not 'public-keys' in self.metadata: + return([]) return([self.metadata['public-keys'],]) # the data sources' config_obj is a cloud-config formated @@ -126,7 +128,8 @@ def read_ovf_environment(contents): cfg_props = [ 'password', ] md_props = [ 'seedfrom', 'local-hostname', 'public-keys', 'instance-id' ] for prop, val in props.iteritems(): - if prop == 'hostname': prop = "local-hostname" + if prop == 'hostname': + prop = "local-hostname" if prop in md_props: md[prop] = val elif prop in cfg_props: @@ -174,7 +177,8 @@ def transport_iso9660(require_iso=False): (dev,mp,fstype,_opts,_freq,_passno) = mpline.split() mounted[dev]=(dev,fstype,mp,False) mp = mp.replace("\\040"," ") - if fstype != "iso9660" and require_iso: continue + if fstype != "iso9660" and require_iso: + continue if cdmatch.match(dev[5:]) == None: # take off '/dev/' continue @@ -201,7 +205,8 @@ def transport_iso9660(require_iso=False): fp.read(512) fp.close() except: - if fp: fp.close() + if fp: + fp.close() continue if tmpd is None: @@ -213,7 +218,8 @@ def transport_iso9660(require_iso=False): pass cmd = [ "mount", "-o", "ro", fullp, tmpd ] - if require_iso: cmd.extend(('-t','iso9660')) + if require_iso: + cmd.extend(('-t','iso9660')) rc = subprocess.call(cmd, stderr=dvnull, stdout=dvnull, stdin=dvnull) if rc: @@ -250,9 +256,11 @@ def transport_vmware_guestd(): def findChild(node,filter_func): ret = [] - if not node.hasChildNodes(): return ret + if not node.hasChildNodes(): + return ret for child in node.childNodes: - if filter_func(child): ret.append(child) + if filter_func(child): + ret.append(child) return(ret) def getProperties(environString): diff --git a/cloudinit/UserDataHandler.py b/cloudinit/UserDataHandler.py index 14aea58b..feaf27cf 100644 --- a/cloudinit/UserDataHandler.py +++ b/cloudinit/UserDataHandler.py @@ -53,7 +53,8 @@ def do_include(content, appendmsg): # also support '#include <url here>' includeonce = False for line in content.splitlines(): - if line == "#include": continue + if line == "#include": + continue if line == "#include-once": includeonce = True continue @@ -62,7 +63,8 @@ def do_include(content, appendmsg): includeonce = True elif line.startswith("#include"): line = line[len("#include"):].lstrip() - if line.startswith("#"): continue + if line.startswith("#"): + continue # urls cannot not have leading or trailing white space msum = hashlib.md5() diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index d74a0f1f..554ebf6b 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -70,7 +70,8 @@ import glob import traceback class NullHandler(logging.Handler): - def emit(self,record): pass + def emit(self,record): + pass log = logging.getLogger(logger_name) log.addHandler(NullHandler()) @@ -147,7 +148,8 @@ class CloudInit: try: from configobj import ConfigObj oldcfg = ConfigObj(self.old_conffile) - if oldcfg is None: oldcfg = { } + if oldcfg is None: + oldcfg = { } conf = util.mergedict(conf,oldcfg) except: pass @@ -185,7 +187,8 @@ class CloudInit: raise def get_data_source(self): - if self.datasource is not None: return True + if self.datasource is not None: + return True if self.restore_from_cache(): log.debug("restored from cache type %s" % self.datasource) @@ -216,7 +219,8 @@ class CloudInit: try: os.unlink(cur_instance_link) except OSError as e: - if e.errno != errno.ENOENT: raise + if e.errno != errno.ENOENT: + raise iid = self.get_instance_id() os.symlink("./instances/%s" % iid, cur_instance_link) @@ -258,7 +262,8 @@ class CloudInit: return("%s/%s.%s" % (get_cpath("sem"), name, freq)) def sem_has_run(self,name,freq): - if freq == per_always: return False + if freq == per_always: + return False semfile = self.sem_getpath(name,freq) if os.path.exists(semfile): return True @@ -339,7 +344,8 @@ class CloudInit: part_handlers = { } # add handlers in cdir for fname in glob.glob("%s/*.py" % cdir): - if not os.path.isfile(fname): continue + if not os.path.isfile(fname): + continue modname = os.path.basename(fname)[0:-3] try: mod = __import__(modname) @@ -370,7 +376,8 @@ class CloudInit: handler_call_end(mod, data, frequency) def handle_user_script(self,_data,ctype,filename,payload, _frequency): - if ctype == "__end__": return + if ctype == "__end__": + return if ctype == "__begin__": # maybe delete existing things here return @@ -385,7 +392,8 @@ class CloudInit: if frequency != per_instance: return - if ctype == "__end__" or ctype == "__begin__": return + if ctype == "__end__" or ctype == "__begin__": + return if not filename.endswith(".conf"): filename=filename+".conf" @@ -413,8 +421,10 @@ class CloudInit: self.cloud_config_str+="\n#%s\n%s" % (filename,payload) def handle_cloud_boothook(self,_data,ctype,filename,payload, _frequency): - if ctype == "__end__": return - if ctype == "__begin__": return + if ctype == "__end__": + return + if ctype == "__begin__": + return filename=filename.replace(os.sep,'_') payload = util.dos2unix(payload) @@ -476,18 +486,22 @@ def initfs(): fp.close() if log_file and perms: (u,g) = perms.split(':',1) - if u == "-1" or u == "None": u = None - if g == "-1" or g == "None": g = None + if u == "-1" or u == "None": + u = None + if g == "-1" or g == "None": + g = None util.chownbyname(log_file, u, g) def purge_cache(rmcur=True): rmlist = [ boot_finished ] - if rmcur: rmlist.append(cur_instance_link) + if rmcur: + rmlist.append(cur_instance_link) for f in rmlist: try: os.unlink(f) except OSError as e: - if e.errno == errno.ENOENT: continue + if e.errno == errno.ENOENT: + continue return(False) except: return(False) @@ -503,7 +517,8 @@ def get_cpath(name=None): return("%s%s" % (varlibdir, pathmap[name])) def get_base_cfg(cfg_path=None): - if cfg_path is None: cfg_path = system_config + if cfg_path is None: + cfg_path = system_config return(util.get_base_cfg(cfg_path,cfg_builtin,parsed_cfgs)) def get_builtin_cfg(): diff --git a/cloudinit/util.py b/cloudinit/util.py index 5bf8e8b2..ec1cb01c 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -74,21 +74,27 @@ def get_base_cfg(cfgfile,cfg_builtin="", parsed_cfgs=None): return(fin) def get_cfg_option_bool(yobj, key, default=False): - if not yobj.has_key(key): return default + if not yobj.has_key(key): + return default val = yobj[key] - if val is True: return True + if val is True: + return True if str(val).lower() in [ 'true', '1', 'on', 'yes']: return True return False def get_cfg_option_str(yobj, key, default=None): - if not yobj.has_key(key): return default + if not yobj.has_key(key): + return default return yobj[key] def get_cfg_option_list_or_str(yobj, key, default=None): - if not yobj.has_key(key): return default - if yobj[key] is None: return [] - if isinstance(yobj[key],list): return yobj[key] + if not yobj.has_key(key): + return default + if yobj[key] is None: + return [] + if isinstance(yobj[key],list): + return yobj[key] return([yobj[key]]) # get a cfg entry by its path array @@ -96,7 +102,8 @@ def get_cfg_option_list_or_str(yobj, key, default=None): def get_cfg_by_path(yobj,keyp,default=None): cur = yobj for tok in keyp: - if tok not in cur: return(default) + if tok not in cur: + return(default) cur = cur[tok] return(cur) @@ -147,10 +154,12 @@ def getkeybyid(keyid,keyserver): return(subp(args)[0]) def runparts(dirp, skip_no_exist=True): - if skip_no_exist and not os.path.isdir(dirp): return + if skip_no_exist and not os.path.isdir(dirp): + return # per bug 857926, Fedora's run-parts will exit failure on empty dir - if os.path.isdir(dirp) and os.listdir(dirp) == []: return + if os.path.isdir(dirp) and os.listdir(dirp) == []: + return cmd = [ 'run-parts', '--regex', '.*', dirp ] sp = subprocess.Popen(cmd) @@ -268,7 +277,8 @@ def read_file_with_includes(fname, rel = ".", stack=None, patt = None): cur = 0 while True: match = patt.search(contents[cur:]) - if not match: break + if not match: + break loc = match.start() + cur endl = match.end() + cur @@ -314,7 +324,8 @@ def read_conf_with_confd(cfgfile): elif os.path.isdir("%s.d" % cfgfile): confd = "%s.d" % cfgfile - if not confd: return(cfg) + if not confd: + return(cfg) confd_cfg = read_conf_d(confd) @@ -371,8 +382,10 @@ def ensure_dirs(dirlist, mode=0755): else: os.makedirs(d, mode) except OSError as e: - if e.errno != errno.EEXIST: raise - if mode != None: fixmodes.append(d) + if e.errno != errno.EEXIST: + raise + if mode != None: + fixmodes.append(d) for d in fixmodes: os.chmod(d, mode) @@ -380,7 +393,8 @@ def ensure_dirs(dirlist, mode=0755): def chownbyname(fname,user=None,group=None): uid = -1 gid = -1 - if user == None and group == None: return + if user == None and group == None: + return if user: import pwd uid = pwd.getpwnam(user).pw_uid @@ -426,7 +440,8 @@ def shellify(cmdlist): def dos2unix(string): # find first end of line pos = string.find('\n') - if pos <= 0 or string[pos-1] != '\r': return(string) + if pos <= 0 or string[pos-1] != '\r': + return(string) return(string.replace('\r\n','\n')) def islxc(): |