Permalink
Browse files

Ran code inspector and corrected a number of issues.

  • Loading branch information...
1 parent 32797f2 commit 53db94a1c61bf8d3bbf58d4f04ed8bc4ffd2fca7 @dwighthubbard committed Sep 14, 2012
View
View
@@ -0,0 +1 @@
+hostlists.py
View
@@ -10,6 +10,7 @@
to actually obtain the listings.
"""
+#noinspection PyStatementEffect
"""
Copyright (c) 2010 Yahoo! Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,7 +30,6 @@
import os
import sys
import optparse
-import site
import imp
import json
@@ -92,6 +92,7 @@ def expand(range_list,onepass=False):
range_list=[range_list]
new_list=[]
set1=None
+ operation=None
for item in range_list:
if set1 and operation:
set2=expand_item(item)
@@ -115,7 +116,7 @@ def multiple_names(plugin):
count = 0
for item in plugins.keys():
if plugins[item]==plugin:
- count=count+1
+ count += 1
if count > 1:
return True
else:
@@ -170,9 +171,9 @@ def compress(range_list):
return ','.join(range_list).strip(',')
def range_split(range):
- """ Split up a range string, this needs to seperate comma seperated
+ """ Split up a range string, this needs to separate comma separated
items unless they are within square brackets and split out set operations
- as seperate items."""
+ as separate items."""
in_brackets=False
current=""
result_list=[]
@@ -198,9 +199,9 @@ def range_split(range):
if __name__ == "__main__":
parser = optparse.OptionParser(usage="usage: %prog [options] plugin:parameters")
- parser.add_option("-s","--sep",dest="sep",default=',',help="Seperator character, default=\",\"")
+ parser.add_option("-s","--sep",dest="sep",default=',',help="Separator character, default=\",\"")
parser.add_option("--onepass",dest="onepass",default=False,action="store_true")
- parser.add_option("--expand","-e",dest="expand",default=False,action="store_true",help="Expand the host list and dislay one host per line")
+ parser.add_option("--expand","-e",dest="expand",default=False,action="store_true",help="Expand the host list and display one host per line")
(options, args) = parser.parse_args()
range=range_split(','.join(args))
if options.expand:
View
@@ -1,6 +1,7 @@
#!/usr/bin/env python
""" hostlists plugin to get hosts from dns """
+#noinspection PyStatementEffect
"""
Copyright (c) 2012 Yahoo! Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,7 @@
#!/usr/bin/env python
""" hostlists plugin to get hosts from dns """
+#noinspection PyStatementEffect
"""
Copyright (c) 2012 Yahoo! Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +24,6 @@ def name():
def expand(value):
tmplist=[]
- adresses=[]
try:
answers = list(dns.resolver.query(value))
except dns.resolver.NoAnswer:
@@ -35,14 +35,14 @@ def get_haproxy_socket_filename():
def query_haproxy_socket(socket_file='/tmp/haproxy',command='show stat'):
if not command.endswith('\n'):
- command=command+'\n'
+ command += '\n'
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(socket_file)
s.send(command)
data=""
d=s.recv(1024)
while d:
- data=data+d
+ data+=d
d=s.recv(1024)
#data = s.recv()
s.close()
@@ -1,6 +1,7 @@
#!/usr/bin/env python
""" haproxy host plugin """
+#noinspection PyStatementEffect
"""
Copyright (c) 2012 Yahoo! Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,6 +17,7 @@
limitations under the License. See accompanying LICENSE file.
"""
+#noinspection PyStatementEffect
"""
NOTE:
This script is primarily intended as a proof of concept of adding a load
@@ -125,7 +127,7 @@ def expand(value,name='haproxy',method=None):
except:
return []
else:
- url="http://%s/haproxy?stats;csv" % (haproxy)
+ url="http://%s/haproxy?stats;csv" % haproxy
request = urllib2.Request(url)
if userid and password:
base64string = base64.encodestring('%s:%s' % (userid, password)).replace('\n', '')
@@ -1,6 +1,7 @@
#!/usr/bin/env python
""" hostlists plugin to get hosts from a file """
+#noinspection PyStatementEffect
"""
Copyright (c) 2012 Yahoo! Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
@@ -47,7 +48,7 @@ def block_to_list(block):
val1_len=len(val1)
val=''
if letter == ',':
- if val1 != None:
+ if val1 is not None:
result.append(val1.zfill(val1_len))
else:
in_range=True
View
@@ -1,6 +1,6 @@
#!/usr/bin/python
-import os
from distutils.core import setup
+#noinspection PyStatementEffect
"""
Copyright (c) 2012 Yahoo! Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
View
View
@@ -0,0 +1 @@
+sshmap.py
View
@@ -1,6 +1,7 @@
#!/usr/bin/env python
""" Python based ssh multiplexer optimized for map operations """
+#noinspection PyStatementEffect
"""
Copyright (c) 2012 Yahoo! Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,20 +25,15 @@
import sys
import os
import stat
-import urllib
-import urllib2
import getpass
import socket
import types
import base64
-import time
-import re
import random
import signal
from optparse import OptionParser
import multiprocessing
import subprocess
-import traceback
# Imports from external python extension modules
import paramiko
@@ -50,7 +46,7 @@
try:
for line in open('/proc/%d/limits'%os.getpid(),'r').readlines():
if line.startswith('Max processes'):
- JOB_MAX=int(line.strip().split()[2])/3
+ JOB_MAX=int(line.strip().split()[2])/3
except:
pass
@@ -241,11 +237,11 @@ def run_command(host,command="uname -a",username=None,password=None,sudo=False,s
result.ssh_retcode=RUN_OK
return result
-""" Handy utility functions """
+# Handy utility functions
def get_parm_val(parm=None,key=None):
"""
Return the value of a key
-
+
>>> get_parm_val(parm={'test':'val'},key='test')
'val'
>>> get_parm_val(parm={'test':'val'},key='foo')
@@ -272,11 +268,11 @@ def status_clear():
sys.stderr.flush()
# Built in callbacks
-""" Filter callback handlers """
+# Filter callback handlers
def callback_flowthrough(result):
"""
Builtin Callback, return the raw data passed
-
+
>>> result=callback_flowthrough(ssh_result(["output"], ["error"],"foo", 0))
>>> result.dump()
foo output error 0 0 None
@@ -339,7 +335,7 @@ def callback_filter_base64(result):
result.err=[base64.b64encode(result.err_string)]
return result
-""" Status callback handlers """
+#Status callback handlers
def callback_status_count(result):
"""
Builtin Callback, show the count complete/remaining
@@ -350,7 +346,7 @@ def callback_status_count(result):
sys.stderr.flush()
return result
-""" Output callback handlers """
+#Output callback handlers
def callback_output_prefix_host(result):
"""
Builtin Callback, print the output with the hostname: prefixed to each line
@@ -408,14 +404,13 @@ def read_conf(key=None,prompt=True):
if key and prompt:
conf[key]=raw_input(conf_desc[key]+': ')
fh=open(os.path.expanduser('~/.fastssh2.conf'),'w')
- os.fchmod(fh.fileno(),stat.S_IRUSR|stat.S_IWUSR)
+ os.fchmod(fh.fileno(),stat.S_IRUSR|stat.S_IWUSR)
json.dump(conf,fh)
- fh.close()
+ fh.close()
return conf[key]
else:
return None
-
def init_worker():
""" Set up the signal handler for new worker threads """
signal.signal(signal.SIGINT, signal.SIG_IGN)
@@ -463,7 +458,7 @@ def run(range,command,username=None,password=None,sudo=False,script=None,timeout
# Create a process pool and pass the parameters to it
try:
for result in map_command(run_command,[(host,command,username,password,sudo,script,timeout,results.parm,client) for host in hosts]):
- results.parm['completed_host_count']=results.parm['completed_host_count']+1
+ results.parm['completed_host_count'] += 1
result.parm=results.parm
if isinstance(output_callback,types.ListType):
for callback in output_callback:
@@ -501,7 +496,7 @@ def run(range,command,username=None,password=None,sudo=False,script=None,timeout
parser.add_option("--no_status",dest="show_status",default=True,action="store_false",help="Don't show a status count as the command progresses")
parser.add_option("--sudo",dest="sudo",default=False,action="store_true",help="Use sudo to run the command as root")
parser.add_option("--password",dest="password",default=None,action="store_true",help="Prompt for a password")
-
+
(options, args) = parser.parse_args()
if len(args) == 1 and options.runscript:

0 comments on commit 53db94a

Please sign in to comment.