From c33eedb47b2b22c797051da197fd80e74f1db179 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 17 Jan 2012 12:34:19 -0500 Subject: [PATCH 2/4] Fix pylint conventions C0322 (operator not preceded by a space) From: Juerg Haefliger --- cloudinit/CloudConfig/__init__.py | 11 +++++------ cloudinit/CloudConfig/cc_apt_update_upgrade.py | 22 +++++++++++----------- cloudinit/CloudConfig/cc_bootcmd.py | 4 ++-- cloudinit/CloudConfig/cc_disable_ec2_metadata.py | 2 +- cloudinit/CloudConfig/cc_final_message.py | 4 ++-- cloudinit/CloudConfig/cc_grub_dpkg.py | 14 +++++++------- cloudinit/CloudConfig/cc_mounts.py | 8 ++++---- cloudinit/CloudConfig/cc_resizefs.py | 4 ++-- cloudinit/CloudConfig/cc_runcmd.py | 2 +- cloudinit/CloudConfig/cc_set_passwords.py | 16 ++++++++-------- cloudinit/CloudConfig/cc_ssh.py | 4 ++-- cloudinit/CloudConfig/cc_timezone.py | 2 +- 12 files changed, 46 insertions(+), 47 deletions(-) (limited to 'cloudinit/CloudConfig') diff --git a/cloudinit/CloudConfig/__init__.py b/cloudinit/CloudConfig/__init__.py index a30940fa..fb390090 100644 --- a/cloudinit/CloudConfig/__init__.py +++ b/cloudinit/CloudConfig/__init__.py @@ -25,7 +25,7 @@ import os import subprocess import time -per_instance= cloudinit.per_instance +per_instance = cloudinit.per_instance per_always = cloudinit.per_always per_once = cloudinit.per_once @@ -247,11 +247,10 @@ def run_per_instance(name, func, args, clear_on_fail=False): def apt_get(tlc,args=None): if args is None: args = [] - e=os.environ.copy() - e['DEBIAN_FRONTEND']='noninteractive' - cmd=[ 'apt-get', - '--option', 'Dpkg::Options::=--force-confold', '--assume-yes', - tlc ] + e = os.environ.copy() + e['DEBIAN_FRONTEND'] = 'noninteractive' + cmd = ['apt-get', '--option', 'Dpkg::Options::=--force-confold', + '--assume-yes', tlc] cmd.extend(args) subprocess.check_call(cmd,env=e) diff --git a/cloudinit/CloudConfig/cc_apt_update_upgrade.py b/cloudinit/CloudConfig/cc_apt_update_upgrade.py index e911db89..e4c08708 100644 --- a/cloudinit/CloudConfig/cc_apt_update_upgrade.py +++ b/cloudinit/CloudConfig/cc_apt_update_upgrade.py @@ -102,23 +102,23 @@ def handle(_name,cfg,cloud,log,_args): return(True) def mirror2lists_fileprefix(mirror): - string=mirror + string = mirror # take of http:// or ftp:// if string.endswith("/"): - string=string[0:-1] - pos=string.find("://") + string = string[0:-1] + pos = string.find("://") if pos >= 0: - string=string[pos+3:] - string=string.replace("/","_") + string = string[pos+3:] + string = string.replace("/","_") return string 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): + oprefix = "%s/%s" % (lists_d,mirror2lists_fileprefix(omirror)) + nprefix = "%s/%s" % (lists_d,mirror2lists_fileprefix(new_mirror)) + if(oprefix == nprefix): return - olen=len(oprefix) + olen = len(oprefix) for filename in glob.glob("%s_*" % oprefix): os.rename(filename,"%s%s" % (nprefix, filename[olen:])) @@ -143,7 +143,7 @@ def add_sources(srclist, searchList=None): elst.append([ "", "missing source" ]) continue - source=ent['source'] + source = ent['source'] if source.startswith("ppa:"): try: util.subp(["add-apt-repository",source]) @@ -154,7 +154,7 @@ def add_sources(srclist, searchList=None): source = util.render_string(source, searchList) if not ent.has_key('filename'): - ent['filename']='cloud_config_sources.list' + ent['filename'] = 'cloud_config_sources.list' if not ent['filename'].startswith("/"): ent['filename'] = "%s/%s" % \ diff --git a/cloudinit/CloudConfig/cc_bootcmd.py b/cloudinit/CloudConfig/cc_bootcmd.py index fc925447..47778897 100644 --- a/cloudinit/CloudConfig/cc_bootcmd.py +++ b/cloudinit/CloudConfig/cc_bootcmd.py @@ -35,8 +35,8 @@ def handle(_name,cfg,cloud,log,_args): raise try: - env=os.environ.copy() - env['INSTANCE_ID']=cloud.get_instance_id() + env = os.environ.copy() + env['INSTANCE_ID'] = cloud.get_instance_id() subprocess.check_call(['/bin/sh'], env=env, stdin=tmpf) tmpf.close() except: diff --git a/cloudinit/CloudConfig/cc_disable_ec2_metadata.py b/cloudinit/CloudConfig/cc_disable_ec2_metadata.py index f06d4dfc..ff95f4bf 100644 --- a/cloudinit/CloudConfig/cc_disable_ec2_metadata.py +++ b/cloudinit/CloudConfig/cc_disable_ec2_metadata.py @@ -23,5 +23,5 @@ frequency = per_always def handle(_name,cfg,_cloud,_log,_args): if util.get_cfg_option_bool(cfg, "disable_ec2_metadata", False): - fwall="route add -host 169.254.169.254 reject" + fwall = "route add -host 169.254.169.254 reject" subprocess.call(fwall.split(' ')) diff --git a/cloudinit/CloudConfig/cc_final_message.py b/cloudinit/CloudConfig/cc_final_message.py index c8631d01..ef0d9ad0 100644 --- a/cloudinit/CloudConfig/cc_final_message.py +++ b/cloudinit/CloudConfig/cc_final_message.py @@ -31,8 +31,8 @@ def handle(_name,cfg,_cloud,log,args): msg_in = util.get_cfg_option_str(cfg,"final_message",final_message) try: - uptimef=open("/proc/uptime") - uptime=uptimef.read().split(" ")[0] + uptimef = open("/proc/uptime") + uptime = uptimef.read().split(" ")[0] uptimef.close() except IOError as e: log.warn("unable to open /proc/uptime\n") diff --git a/cloudinit/CloudConfig/cc_grub_dpkg.py b/cloudinit/CloudConfig/cc_grub_dpkg.py index fde8cca1..4e1ba4d4 100644 --- a/cloudinit/CloudConfig/cc_grub_dpkg.py +++ b/cloudinit/CloudConfig/cc_grub_dpkg.py @@ -22,24 +22,24 @@ import os def handle(_name,cfg,_cloud,log,_args): - idevs=None - idevs_empty=None + idevs = None + idevs_empty = None if "grub-dpkg" in cfg: - idevs=util.get_cfg_option_str(cfg["grub-dpkg"], + idevs = util.get_cfg_option_str(cfg["grub-dpkg"], "grub-pc/install_devices",None) - idevs_empty=util.get_cfg_option_str(cfg["grub-dpkg"], + idevs_empty = util.get_cfg_option_str(cfg["grub-dpkg"], "grub-pc/install_devices_empty",None) 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="" + idevs = "" if idevs_empty == None: - idevs_empty="true" + idevs_empty = "true" else: if idevs_empty == None: - idevs_empty="false" + 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_mounts.py b/cloudinit/CloudConfig/cc_mounts.py index 94ad1bba..248abb24 100644 --- a/cloudinit/CloudConfig/cc_mounts.py +++ b/cloudinit/CloudConfig/cc_mounts.py @@ -76,7 +76,7 @@ def handle(_name,cfg,cloud,log,_args): # but do not convert None to 'None' (LP: #898365) for j in range(len(cfgmnt[i])): if isinstance(cfgmnt[i][j], int): - cfgmnt[i][j]=str(cfgmnt[i][j]) + cfgmnt[i][j] = str(cfgmnt[i][j]) for i in range(len(cfgmnt)): # fill in values with defaults from defvals above @@ -124,13 +124,13 @@ def handle(_name,cfg,cloud,log,_args): if len(actlist) == 0: return - comment="comment=cloudconfig" + comment = "comment=cloudconfig" cc_lines = [ ] needswap = False dirs = [ ] for line in actlist: # write 'comment' in the fs_mntops, entry, claiming this - line[3]="%s,comment=cloudconfig" % line[3] + line[3] = "%s,comment=cloudconfig" % line[3] if line[2] == "swap": needswap = True if line[1].startswith("/"): @@ -138,7 +138,7 @@ def handle(_name,cfg,cloud,log,_args): cc_lines.append('\t'.join(line)) fstab_lines = [ ] - fstab=open("/etc/fstab","r+") + fstab = open("/etc/fstab","r+") ws = re.compile("[%s]+" % string.whitespace) for line in fstab.read().splitlines(): try: diff --git a/cloudinit/CloudConfig/cc_resizefs.py b/cloudinit/CloudConfig/cc_resizefs.py index 29e0fa34..1fdf8647 100644 --- a/cloudinit/CloudConfig/cc_resizefs.py +++ b/cloudinit/CloudConfig/cc_resizefs.py @@ -42,8 +42,8 @@ def handle(_name,cfg,_cloud,log,args): os.close(fd) try: - st_dev=os.stat("/").st_dev - dev=os.makedev(os.major(st_dev),os.minor(st_dev)) + st_dev = os.stat("/").st_dev + dev = os.makedev(os.major(st_dev),os.minor(st_dev)) os.mknod(devpth, 0400 | stat.S_IFBLK, dev) except: if util.islxc(): diff --git a/cloudinit/CloudConfig/cc_runcmd.py b/cloudinit/CloudConfig/cc_runcmd.py index d255223b..0adf31ad 100644 --- a/cloudinit/CloudConfig/cc_runcmd.py +++ b/cloudinit/CloudConfig/cc_runcmd.py @@ -21,7 +21,7 @@ import cloudinit.util as util def handle(_name,cfg,cloud,log,_args): if not cfg.has_key("runcmd"): return - outfile="%s/runcmd" % cloud.get_ipath('scripts') + outfile = "%s/runcmd" % cloud.get_ipath('scripts') try: content = util.shellify(cfg["runcmd"]) util.write_file(outfile,content,0700) diff --git a/cloudinit/CloudConfig/cc_set_passwords.py b/cloudinit/CloudConfig/cc_set_passwords.py index 07e3ca1b..4059e9c1 100644 --- a/cloudinit/CloudConfig/cc_set_passwords.py +++ b/cloudinit/CloudConfig/cc_set_passwords.py @@ -70,7 +70,7 @@ def handle(_name,cfg,_cloud,log,args): '\n'.join(randlist) )) if expire: - enum=len(errors) + enum = len(errors) for u in users: try: util.subp(['passwd', '--expire', u]) @@ -83,13 +83,13 @@ def handle(_name,cfg,_cloud,log,args): if 'ssh_pwauth' in cfg: val = str(cfg['ssh_pwauth']).lower() if val in ( "true", "1", "yes"): - pw_auth="yes" - change_pwauth=True + pw_auth = "yes" + change_pwauth = True elif val in ( "false", "0", "no"): - pw_auth="no" - change_pwauth=True + pw_auth = "no" + change_pwauth = True else: - change_pwauth=False + change_pwauth = False if change_pwauth: pa_s = "\(#*\)\(PasswordAuthentication[[:space:]]\+\)\(yes\|no\)" @@ -118,7 +118,7 @@ def rand_str(strlen=32, select_from=string.letters+string.digits): return("".join([random.choice(select_from) for _x in range(0, strlen)])) def rand_user_password(pwlen=9): - selfrom=(string.letters.translate(None,'loLOI') + - string.digits.translate(None,'01')) + selfrom = (string.letters.translate(None,'loLOI') + + string.digits.translate(None,'01')) return(rand_str(pwlen,select_from=selfrom)) diff --git a/cloudinit/CloudConfig/cc_ssh.py b/cloudinit/CloudConfig/cc_ssh.py index 897ba9dc..6031a436 100644 --- a/cloudinit/CloudConfig/cc_ssh.py +++ b/cloudinit/CloudConfig/cc_ssh.py @@ -21,7 +21,7 @@ import os import glob import subprocess -DISABLE_ROOT_OPTS="no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command=\"echo \'Please login as the user \\\"$USER\\\" rather than the user \\\"root\\\".\';echo;sleep 10\"" +DISABLE_ROOT_OPTS = "no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command=\"echo \'Please login as the user \\\"$USER\\\" rather than the user \\\"root\\\".\';echo;sleep 10\"" global_log = None @@ -60,7 +60,7 @@ def handle(_name,cfg,cloud,log,_args): for priv,pub in priv2pub.iteritems(): if pub in cfg['ssh_keys'] or not priv in cfg['ssh_keys']: continue - pair=(key2file[priv][0], key2file[pub][0]) + pair = (key2file[priv][0], key2file[pub][0]) subprocess.call(('sh', '-xc', cmd % pair)) log.debug("generated %s from %s" % pair) else: diff --git a/cloudinit/CloudConfig/cc_timezone.py b/cloudinit/CloudConfig/cc_timezone.py index 091271f4..e7c855d6 100644 --- a/cloudinit/CloudConfig/cc_timezone.py +++ b/cloudinit/CloudConfig/cc_timezone.py @@ -40,7 +40,7 @@ def handle(_name,cfg,_cloud,log,args): raise Exception("Invalid timezone %s" % tz_file) try: - fp=open("/etc/timezone","wb") + fp = open("/etc/timezone","wb") fp.write("%s\n" % timezone) fp.close() except: -- cgit v1.2.3