Permalink
Browse files

flake8 cleanup for command and pylib

  • Loading branch information...
masonkatz committed Sep 12, 2017
1 parent 03e469e commit 69448ee4c8290d1ae84c53a39da12c85be03f0c2
Showing 391 changed files with 1,053 additions and 1,034 deletions.
View
12 .flake8
@@ -5,11 +5,21 @@ ignore=
W291,
W293,
W391,
E101,
E122,
E123,
E124,
E126,
E127,
E128,
E201,
E202,
E203,
E221,
E222,
E241,
E242,
E261,
E265,
E303,
F403,
E223
@@ -18,28 +18,28 @@
import fnmatch
import syslog
import pwd
import types
import sys
import json
import marshal
import hashlib
import subprocess
from functools import partial
import stack
from stack.cond import EvalCondExpr
from stack.attr import *
import stack.graph
from stack.exception import *
from stack.bool import *
from xml.sax import saxutils
from xml.sax import handler
from xml.sax import make_parser
from pymysql import OperationalError, ProgrammingError
from functools import partial
import stack.graph
import stack
from stack.cond import EvalCondExpr
from stack.exception import CommandError, ParamRequired
from stack.bool import str2bool, bool2str
_logPrefix = ''
_debug = False
def Log(message, level=syslog.LOG_INFO):
"""
Send a message to syslog
@@ -169,7 +169,7 @@ def getBoxNames(self, args=None):
return list
def getBoxPallets(self, box = 'default'):
def getBoxPallets(self, box='default'):
"""Returns a list of pallets for a box"""
#
@@ -232,6 +232,7 @@ def getNetworkName(self, netid):
return netname
class CartArgumentProcessor:
"""An Interface class to add the ability to process cart arguments."""
@@ -389,7 +390,7 @@ def getHostnames(self, names=[], managed_only=False, subnet=None, host_filter=No
if names:
hostDict[host] = None
else:
hostDict[host] = self.db.getNodeName(host,
hostDict[host] = self.db.getNodeName(host,
subnet)
@@ -455,7 +456,7 @@ def getHostnames(self, names=[], managed_only=False, subnet=None, host_filter=No
if res:
s = self.db.getHostname(host, subnet)
hostDict[host] = s
if not host in explicit:
if host not in explicit:
explicit[host] = False
# Debug('group %s is %s for %s' %
# (exp, res, host))
@@ -466,7 +467,7 @@ def getHostnames(self, names=[], managed_only=False, subnet=None, host_filter=No
for host in fnmatch.filter(hostList, name):
s = self.db.getHostname(host, subnet)
hostDict[host] = s
if not host in explicit:
if host not in explicit:
explicit[host] = False
@@ -931,7 +932,7 @@ def getMarkDown(self):
s = s + '### Related\n'
for related in self.section['related']:
r = '-'.join(related.split()).strip()
s += '[%s](%s)\n\n' % (related,r)
s += '[%s](%s)\n\n' % (related, r)
s = s + '\n'
return s
@@ -1070,7 +1071,7 @@ def execute(self, command):
t0 = time.time()
result = self.link.execute(command)
t1 = time.time()
Debug('SQL EX: %.3f %s' % ((t1-t0), command))
Debug('SQL EX: %.3f %s' % ((t1 - t0), command))
return result
return None
@@ -1096,15 +1097,15 @@ def getHostOS(self, host):
Return the OS name for the given host.
"""
for (name, os) in self.select(
for (name, osname) in self.select(
"""
n.name, o.name from
boxes b, nodes n, oses o
where n.box = b.id and
b.os = o.id
"""):
if name == host:
return os
return osname
return None
def getHostAppliance(self, host):
@@ -1350,7 +1351,7 @@ def getHostname(self, hostname=None, subnet=None):
'networks nt, subnets s where ' +\
'nt.subnet=s.id and ' +\
'nt.node=n.id and ' +\
's.zone="%s" and ' % (domain)+ \
's.zone="%s" and ' % domain +\
'(nt.name="%s" or n.name="%s")' \
% (name, name)
@@ -1535,7 +1536,7 @@ def __init__(self, database, debug=False):
'reset': { 'tput': 'sgr0', 'code': '' },
'beginline': { 'tput': 'smul', 'code': ''},
'endline': { 'tput': 'rmul', 'code': ''}
}
}
if sys.stdout.isatty() and False:
# TODO(p3) - figure out why we aren't capturing the tput code
# correctly. We get data but not the full escape seq
@@ -1628,7 +1629,7 @@ def call(self, command, args=[]):
def notify(self, message):
# print self.level
#print(self.level)
if self.notifications:
sys.stderr.write('%s%s' % (_logPrefix, message))
@@ -1638,7 +1639,7 @@ def command(self, command, args=[]):
Returns and output string."""
modpath = 'stack.commands.%s' % command
# print('+ ', command)
#print('+ ', command)
__import__(modpath)
mod = eval(modpath)
@@ -1653,7 +1654,7 @@ def command(self, command, args=[]):
# the return code. The actual text is what we return.
self.rc = o.runWrapper(name, args, self.level + 1)
# print ('- ', command)
#print ('- ', command)
return o.getText()
@@ -1733,7 +1734,7 @@ def runPlugins(self, args='', plugins=None):
for plugin in plugins:
Log('run %s' % plugin)
retval = plugin.run(args)
if not retval == None:
if retval is not None:
results.append((plugin.provides(), retval))
return results
@@ -1762,7 +1763,7 @@ def loadImplementation(self, name=None):
module = eval(module)
try:
o = getattr(module, 'Implementation')(self)
n = re.sub('^imp_','', base)
n = re.sub('^imp_', '', base)
self.impl_list[n] = o
except AttributeError:
continue
@@ -1771,7 +1772,7 @@ def runImplementation(self, name, args=None):
# Check to see if implementation list
# has named implementation. If not, try
# to load named implementation
if not name in self.impl_list:
if name not in self.impl_list:
self.loadImplementation(name)
# If the named implementation was loaded,
@@ -1831,7 +1832,7 @@ def clearText(self):
def addText(self, s):
"""Append a string to the output text buffer."""
if s:
if type(s) == type(''):
if isinstance(s, str):
self.text += s
else:
self.bytes += s
@@ -1853,17 +1854,17 @@ def addOutput(self, owner, vals):
# VALS can be a list, tuple, or primitive type.
list = ['%s' % owner]
if type(vals) == type([]):
list.extend(vals)
elif type(vals) == type(()):
out = ['%s' % owner]
if isinstance(vals, type([])):
out.extend(vals)
elif isinstance(vals, tuple):
for e in vals:
list.append(e)
out.append(e)
else:
list.append(vals)
out.append(vals)
self.output.append(list)
self.output.append(out)
def endOutput(self, header=[], padChar='-', trimOwner=False):
@@ -1914,7 +1915,7 @@ def endOutput(self, header=[], padChar='-', trimOwner=False):
key = header[i]
val = line[i]
if key in dict:
if not type(dict[key]) ==types.ListType:
if not isinstance(dict[key], list):
dict[key] = [dict[key]]
dict[key].append(val)
else:
@@ -1933,8 +1934,8 @@ def endOutput(self, header=[], padChar='-', trimOwner=False):
n = '%d_' % i
else:
n = ''
for k,v in list[i].items():
self.addText('stack_%s%s="%s"\n' % (n,k,v))
for k, v in list[i].items():
self.addText('stack_%s%s="%s"\n' % (n, k, v))
self.addText('\n')
elif format == 'python':
self.addText('%s' % list)
@@ -1991,8 +1992,8 @@ def endOutput(self, header=[], padChar='-', trimOwner=False):
for i in range(0, len(line)):
if len(colwidth) <= i:
colwidth.append(0)
if type(line[i]) != type(''):
if line[i] == None:
if not isinstance(line[i], str):
if line[i] is None:
itemlen = 0
else:
itemlen = len(repr(line[i]))
@@ -2006,8 +2007,8 @@ def endOutput(self, header=[], padChar='-', trimOwner=False):
# If we know the output is too long for the terminal
# switch from table view to a field view that will
# display nicer (e.g. stack list os boot).
if self.width and header and startOfLine == 0 and (sum(colwidth)+len(line)) > self.width:
if self.width and header and startOfLine == 0 and (sum(colwidth) + len(line)) > self.width:
maxWidth = 0
for label in output[0]:
n = len(label)
@@ -2020,10 +2021,10 @@ def endOutput(self, header=[], padChar='-', trimOwner=False):
else:
s = str(line[i])
if s:
self.addText('%s%s%s %s\n' % (self.colors['bold']['code'],
output[0][i].ljust(maxWidth),
self.colors['reset']['code'],
s))
self.addText('%s%s%s %s\n' % (
self.colors['bold']['code'],
output[0][i].ljust(maxWidth),
self.colors['reset']['code'], s))
self.addText('\n')
return
@@ -2041,7 +2042,7 @@ def endOutput(self, header=[], padChar='-', trimOwner=False):
else:
s = str(line[i])
if padChar != '' and i != len(line)-1:
if padChar != '' and i != len(line) - 1:
if s:
o = s.ljust(colwidth[i])
else:
@@ -2122,9 +2123,9 @@ def hasAccess(self, name):
# supplemental list.
groups.append(gid)
rows = self.db.select('command, groupid from access')
rows = self.db.select('command, groupid from access')
if rows:
for c,g in rows:
for c, g in rows:
if g in groups:
if fnmatch.filter([name], c):
allowed = True
@@ -2191,7 +2192,7 @@ def runWrapper(self, name, argv, level=0):
if not arg:
continue
if arg[0] == '[' and arg[-1] != ']':
if arg[0] == '[' and arg[-1] != ']':
s += '%s' % arg
n += 1
if n == 1:
@@ -2221,7 +2222,7 @@ def runWrapper(self, name, argv, level=0):
# list.append(arg)
if arg.find('where') == 0:
list.append(arg)
elif len(arg.split('=',1)) == 2:
elif len(arg.split('=', 1)) == 2:
(key, val) = arg.split('=', 1)
dict[key] = val
else:
@@ -2231,8 +2232,9 @@ def runWrapper(self, name, argv, level=0):
self.help(name, dict)
else:
if not self.hasAccess(name):
raise CommandError(self, 'user "%s" does not have access "%s"' %
(username, name))
raise CommandError(self,
'user "%s" does not have access "%s"' %
(username, name))
else:
self._argv = argv # raw arg list
self._args = list # required arguments
@@ -2323,7 +2325,7 @@ def run(self):
stack.graph.GraphIterator.run(self)
list = []
self.nodes.sort()
for time, node in self.nodes:
for tm, node in self.nodes:
list.append(node)
list.reverse()
return list
@@ -32,5 +32,6 @@
import stack.commands
class command(stack.commands.Command):
pass
Oops, something went wrong.

0 comments on commit 69448ee

Please sign in to comment.