miscellaneous cleanups, and add tools/run-pylint
adding run-pylint makes it easy to run pylint with given configuration against the code.
This commit is contained in:
		@@ -18,7 +18,7 @@
 | 
			
		||||
import cloudinit.util as util
 | 
			
		||||
import os
 | 
			
		||||
import re
 | 
			
		||||
import string
 | 
			
		||||
from string import whitespace  # pylint: disable=W0402
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def is_mdname(name):
 | 
			
		||||
@@ -139,7 +139,7 @@ def handle(_name, cfg, cloud, log, _args):
 | 
			
		||||
 | 
			
		||||
    fstab_lines = []
 | 
			
		||||
    fstab = open("/etc/fstab", "r+")
 | 
			
		||||
    ws = re.compile("[%s]+" % string.whitespace)
 | 
			
		||||
    ws = re.compile("[%s]+" % whitespace)
 | 
			
		||||
    for line in fstab.read().splitlines():
 | 
			
		||||
        try:
 | 
			
		||||
            toks = ws.split(line)
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@
 | 
			
		||||
import cloudinit.util as util
 | 
			
		||||
import sys
 | 
			
		||||
import random
 | 
			
		||||
import string
 | 
			
		||||
from string import letters, digits  # pylint: disable=W0402
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def handle(_name, cfg, _cloud, log, args):
 | 
			
		||||
@@ -117,11 +117,11 @@ def handle(_name, cfg, _cloud, log, args):
 | 
			
		||||
    return
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def rand_str(strlen=32, select_from=string.letters + string.digits):
 | 
			
		||||
def rand_str(strlen=32, select_from=letters + 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 = (letters.translate(None, 'loLOI') +
 | 
			
		||||
               digits.translate(None, '01'))
 | 
			
		||||
    return(rand_str(pwlen, select_from=selfrom))
 | 
			
		||||
 
 | 
			
		||||
@@ -25,12 +25,8 @@ 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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def handle(_name, cfg, cloud, log, _args):
 | 
			
		||||
    global global_log
 | 
			
		||||
    global_log = log
 | 
			
		||||
 | 
			
		||||
    # remove the static keys from the pristine image
 | 
			
		||||
    if cfg.get("ssh_deletekeys", True):
 | 
			
		||||
@@ -87,14 +83,14 @@ def handle(_name, cfg, cloud, log, _args):
 | 
			
		||||
            cfgkeys = cfg["ssh_authorized_keys"]
 | 
			
		||||
            keys.extend(cfgkeys)
 | 
			
		||||
 | 
			
		||||
        apply_credentials(keys, user, disable_root, disable_root_opts)
 | 
			
		||||
        apply_credentials(keys, user, disable_root, disable_root_opts, log)
 | 
			
		||||
    except:
 | 
			
		||||
        util.logexc(log)
 | 
			
		||||
        log.warn("applying credentials failed!\n")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def apply_credentials(keys, user, disable_root,
 | 
			
		||||
                      disable_root_opts=DISABLE_ROOT_OPTS, log=global_log):
 | 
			
		||||
                      disable_root_opts=DISABLE_ROOT_OPTS, log=None):
 | 
			
		||||
    keys = set(keys)
 | 
			
		||||
    if user:
 | 
			
		||||
        sshutil.setup_user_keys(keys, user, '', log)
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,6 @@ import cloudinit.DataSource as DataSource
 | 
			
		||||
from cloudinit import seeddir as base_seeddir
 | 
			
		||||
from cloudinit import log
 | 
			
		||||
import cloudinit.util as util
 | 
			
		||||
import sys
 | 
			
		||||
import os.path
 | 
			
		||||
import os
 | 
			
		||||
from xml.dom import minidom
 | 
			
		||||
@@ -313,16 +312,19 @@ def get_datasource_list(depends):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    import sys
 | 
			
		||||
    envStr = open(sys.argv[1]).read()
 | 
			
		||||
    props = getProperties(envStr)
 | 
			
		||||
    import pprint
 | 
			
		||||
    pprint.pprint(props)
 | 
			
		||||
    def main():
 | 
			
		||||
        import sys
 | 
			
		||||
        envStr = open(sys.argv[1]).read()
 | 
			
		||||
        props = getProperties(envStr)
 | 
			
		||||
        import pprint
 | 
			
		||||
        pprint.pprint(props)
 | 
			
		||||
 | 
			
		||||
    md, ud, cfg = read_ovf_environment(envStr)
 | 
			
		||||
    print "=== md ==="
 | 
			
		||||
    pprint.pprint(md)
 | 
			
		||||
    print "=== ud ==="
 | 
			
		||||
    pprint.pprint(ud)
 | 
			
		||||
    print "=== cfg ==="
 | 
			
		||||
    pprint.pprint(cfg)
 | 
			
		||||
        md, ud, cfg = read_ovf_environment(envStr)
 | 
			
		||||
        print "=== md ==="
 | 
			
		||||
        pprint.pprint(md)
 | 
			
		||||
        print "=== ud ==="
 | 
			
		||||
        pprint.pprint(ud)
 | 
			
		||||
        print "=== cfg ==="
 | 
			
		||||
        pprint.pprint(cfg)
 | 
			
		||||
 | 
			
		||||
    main()
 | 
			
		||||
 
 | 
			
		||||
@@ -156,39 +156,6 @@ def setup_user_keys(keys, user, key_prefix, log=None):
 | 
			
		||||
    os.umask(saved_umask)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    import sys
 | 
			
		||||
    # usage: orig_file, new_keys, [key_prefix]
 | 
			
		||||
    #   prints out merged, where 'new_keys' will trump old
 | 
			
		||||
    ##  example
 | 
			
		||||
    ## ### begin auth_keys ###
 | 
			
		||||
    # ssh-rsa AAAAB3NzaC1xxxxxxxxxV3csgm8cJn7UveKHkYjJp8= smoser-work
 | 
			
		||||
    # ssh-rsa AAAAB3NzaC1xxxxxxxxxCmXp5Kt5/82cD/VN3NtHw== smoser@brickies
 | 
			
		||||
    # ### end authorized_keys ###
 | 
			
		||||
    #
 | 
			
		||||
    # ### begin new_keys ###
 | 
			
		||||
    # ssh-rsa nonmatch smoser@newhost
 | 
			
		||||
    # ssh-rsa AAAAB3NzaC1xxxxxxxxxV3csgm8cJn7UveKHkYjJp8= new_comment
 | 
			
		||||
    # ### end new_keys ###
 | 
			
		||||
    #
 | 
			
		||||
    # Then run as:
 | 
			
		||||
    #  program auth_keys new_keys \
 | 
			
		||||
    #      'no-port-forwarding,command=\"echo hi world;\"'
 | 
			
		||||
    def_prefix = None
 | 
			
		||||
    orig_key_file = sys.argv[1]
 | 
			
		||||
    new_key_file = sys.argv[2]
 | 
			
		||||
    if len(sys.argv) > 3:
 | 
			
		||||
        def_prefix = sys.argv[3]
 | 
			
		||||
    fp = open(new_key_file)
 | 
			
		||||
 | 
			
		||||
    newkeys = []
 | 
			
		||||
    for line in fp.readlines():
 | 
			
		||||
        newkeys.append(AuthKeyEntry(line, def_prefix))
 | 
			
		||||
 | 
			
		||||
    fp.close()
 | 
			
		||||
    print update_authorized_keys(orig_key_file, newkeys)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def parse_ssh_config(fname="/etc/ssh/sshd_config"):
 | 
			
		||||
    ret = {}
 | 
			
		||||
    fp = open(fname)
 | 
			
		||||
@@ -200,3 +167,40 @@ def parse_ssh_config(fname="/etc/ssh/sshd_config"):
 | 
			
		||||
        ret[key] = val
 | 
			
		||||
    fp.close()
 | 
			
		||||
    return(ret)
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    def main():
 | 
			
		||||
        import sys
 | 
			
		||||
        # usage: orig_file, new_keys, [key_prefix]
 | 
			
		||||
        #   prints out merged, where 'new_keys' will trump old
 | 
			
		||||
        ##  example
 | 
			
		||||
        ## ### begin auth_keys ###
 | 
			
		||||
        # ssh-rsa AAAAB3NzaC1xxxxxxxxxV3csgm8cJn7UveKHkYjJp8= smoser-work
 | 
			
		||||
        # ssh-rsa AAAAB3NzaC1xxxxxxxxxCmXp5Kt5/82cD/VN3NtHw== smoser@brickies
 | 
			
		||||
        # ### end authorized_keys ###
 | 
			
		||||
        #
 | 
			
		||||
        # ### begin new_keys ###
 | 
			
		||||
        # ssh-rsa nonmatch smoser@newhost
 | 
			
		||||
        # ssh-rsa AAAAB3NzaC1xxxxxxxxxV3csgm8cJn7UveKHkYjJp8= new_comment
 | 
			
		||||
        # ### end new_keys ###
 | 
			
		||||
        #
 | 
			
		||||
        # Then run as:
 | 
			
		||||
        #  program auth_keys new_keys \
 | 
			
		||||
        #      'no-port-forwarding,command=\"echo hi world;\"'
 | 
			
		||||
        def_prefix = None
 | 
			
		||||
        orig_key_file = sys.argv[1]
 | 
			
		||||
        new_key_file = sys.argv[2]
 | 
			
		||||
        if len(sys.argv) > 3:
 | 
			
		||||
            def_prefix = sys.argv[3]
 | 
			
		||||
        fp = open(new_key_file)
 | 
			
		||||
 | 
			
		||||
        newkeys = []
 | 
			
		||||
        for line in fp.readlines():
 | 
			
		||||
            newkeys.append(AuthKeyEntry(line, def_prefix))
 | 
			
		||||
 | 
			
		||||
        fp.close()
 | 
			
		||||
        print update_authorized_keys(orig_key_file, newkeys)
 | 
			
		||||
 | 
			
		||||
    main()
 | 
			
		||||
 | 
			
		||||
# vi: ts=4 expandtab
 | 
			
		||||
 
 | 
			
		||||
@@ -246,9 +246,12 @@ def walk_userdata(istr, callback, data=None):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    import sys
 | 
			
		||||
    data = decomp_str(file(sys.argv[1]).read())
 | 
			
		||||
    newmsg = MIMEMultipart()
 | 
			
		||||
    process_includes(message_from_string(data), newmsg)
 | 
			
		||||
    print newmsg
 | 
			
		||||
    print "#found %s parts" % multi_part_count(newmsg)
 | 
			
		||||
    def main():
 | 
			
		||||
        import sys
 | 
			
		||||
        data = decomp_str(file(sys.argv[1]).read())
 | 
			
		||||
        newmsg = MIMEMultipart()
 | 
			
		||||
        process_includes(message_from_string(data), newmsg)
 | 
			
		||||
        print newmsg
 | 
			
		||||
        print "#found %s parts" % multi_part_count(newmsg)
 | 
			
		||||
 | 
			
		||||
    main()
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,6 @@ per_once = "once"
 | 
			
		||||
parsed_cfgs = {}
 | 
			
		||||
 | 
			
		||||
import os
 | 
			
		||||
from   configobj import ConfigObj
 | 
			
		||||
 | 
			
		||||
import cPickle
 | 
			
		||||
import sys
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										49
									
								
								tools/run-pylint
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										49
									
								
								tools/run-pylint
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
def_files='cloud*.py cloudinit/*.py cloudinit/CloudConfig/*.py'
 | 
			
		||||
 | 
			
		||||
if [ $# -eq 0 ]; then
 | 
			
		||||
   files=( )
 | 
			
		||||
   for f in $def_files; do
 | 
			
		||||
      [ -f "$f" ] || { echo "failed, $f not a file" 1>&2; exit 1; }
 | 
			
		||||
      files[${#files[@]}]=${f}
 | 
			
		||||
   done
 | 
			
		||||
else
 | 
			
		||||
   files=( "$@" );
 | 
			
		||||
fi 
 | 
			
		||||
 | 
			
		||||
cmd=(
 | 
			
		||||
    pylint
 | 
			
		||||
    --reports=n
 | 
			
		||||
    --include-ids=y
 | 
			
		||||
    --max-line-length=79
 | 
			
		||||
 | 
			
		||||
    --disable=R
 | 
			
		||||
    --disable=I
 | 
			
		||||
 | 
			
		||||
    --disable=W0142 # Used * or ** magic
 | 
			
		||||
    --disable=W0511 # TODO/FIXME note
 | 
			
		||||
    --disable=W0702 # No exception type(s) specified
 | 
			
		||||
    --disable=W0703 # Catch "Exception"
 | 
			
		||||
 | 
			
		||||
    --disable=C0103 # Invalid name
 | 
			
		||||
    --disable=C0111 # Missing docstring
 | 
			
		||||
 | 
			
		||||
    "${files[@]}"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
echo -e "\nRunning pylint:"
 | 
			
		||||
echo "${cmd[@]}"
 | 
			
		||||
"${cmd[@]}"
 | 
			
		||||
 | 
			
		||||
cmd=(
 | 
			
		||||
    pep8
 | 
			
		||||
 | 
			
		||||
    --ignore=E501 # Line too long (these are caught by pylint above)
 | 
			
		||||
 | 
			
		||||
    "${files[@]}"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
echo -e "\nRunning pep8:"
 | 
			
		||||
echo "${cmd[@]}"
 | 
			
		||||
"${cmd[@]}"
 | 
			
		||||
		Reference in New Issue
	
	Block a user