Enable PEP8 checks for E121, E129, E231, E265, E302

* E121 continuation line under-indented for hanging indent
* E129 visually indented line with same indent as next logical line
* E302 expected 2 blank lines, found x
* E231 missing whitespace after ','
* E265 block comment should start with '# '

Change-Id: If22172e8a60e962ddbf43db01e7633c60af0a1bc
This commit is contained in:
Christian Berendt 2015-01-09 13:31:11 +01:00
parent 05a27ebb9c
commit b148189d18
11 changed files with 114 additions and 84 deletions

View File

@ -19,12 +19,12 @@ from packstack import version as packstackversion
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
@ -37,7 +37,7 @@ templates_path = ['_templates']
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
@ -57,37 +57,37 @@ release = version
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
@ -99,26 +99,26 @@ html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
@ -127,44 +127,44 @@ html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'packstackdoc'
@ -174,40 +174,40 @@ htmlhelp_basename = 'packstackdoc'
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
# 'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'packstack.tex', u'packstack Documentation', u'Derek Higgins', 'manual'),
('index', 'packstack.tex', u'packstack Documentation', u'Derek Higgins', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
@ -219,7 +219,7 @@ man_pages = [
]
# If true, show URL addresses after external links.
#man_show_urls = False
# man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
@ -228,16 +228,16 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'packstack', u'packstack Documentation',
('index', 'packstack', u'packstack Documentation',
u'Derek Higgins', 'packstack', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# texinfo_show_urls = 'footnote'

View File

@ -14,10 +14,6 @@ they are used in the engine-setup.py
import basedefs
#####################
####INFO MESSAGES####
#####################
INFO_HEADER = "Welcome to the %s setup utility" % basedefs.APP_NAME
INFO_INSTALL_SUCCESS = "\n **** Installation completed successfully ******\n"
INFO_INSTALL = "Installing:"

View File

@ -77,6 +77,7 @@ def process_add_quotes_around_values(param, param_name, config=None):
param = ','.join(params_list)
return param
def process_password(param, param_name, config=None):
"""
Process passwords, checking the following:
@ -84,7 +85,7 @@ def process_password(param, param_name, config=None):
2- Otherwise, check for a global default password, and use it if available
3- As a last resort, generate a random password
"""
if not hasattr(process_password,"pw_dict"):
if not hasattr(process_password, "pw_dict"):
process_password.pw_dict = {}
if param == "PW_PLACEHOLDER":

View File

@ -28,10 +28,11 @@ controller = Controller()
commandLineValues = {}
# List to hold all values to be masked in logging (i.e. passwords and sensitive data)
#TODO: read default values from conf_param?
# TODO: read default values from conf_param?
masked_value_set = set()
tmpfiles = []
def initLogging(debug):
try:
logFile = os.path.join(basedefs.DIR_LOG, basedefs.FILE_LOG)
@ -60,6 +61,7 @@ def initLogging(debug):
return logFile
def _getInputFromUser(param):
"""
this private func reads the data from the user
@ -89,7 +91,7 @@ def _getInputFromUser(param):
message.write(": ")
message.seek(0)
#mask password or hidden fields
# mask password or hidden fields
if (param.MASK_INPUT):
userInput = getpass.getpass("%s :" % (param.PROMPT))
@ -133,6 +135,7 @@ def _getInputFromUser(param):
logging.error(traceback.format_exc())
raise Exception(output_messages.ERR_EXP_READ_INPUT_PARAM % (param.CONF_NAME))
def input_param(param):
"""
this func will read input from user
@ -141,7 +144,7 @@ def input_param(param):
# We need to check if a param needs confirmation, (i.e. ask user twice)
# Do not validate if it was given from the command line
if (param.NEED_CONFIRM and not commandLineValues.has_key(param.CONF_NAME)):
#create a copy of the param so we can call it twice
# create a copy of the param so we can call it twice
confirmedParam = copy.deepcopy(param)
confirmedParamName = param.CONF_NAME + "_CONFIRMED"
confirmedParam.CONF_NAME = confirmedParamName
@ -160,6 +163,7 @@ def input_param(param):
return param
def _askYesNo(question=None):
message = StringIO()
@ -182,6 +186,7 @@ def _askYesNo(question=None):
return answer == 'y'
def _addDefaultsToMaskedValueSet():
"""
For every param in conf_params
@ -195,6 +200,7 @@ def _addDefaultsToMaskedValueSet():
if ((param.MASK_INPUT == True) and param.DEFAULT_VALUE != ""):
masked_value_set.add(param.DEFAULT_VALUE)
def _updateMaskedValueSet():
"""
For every param in conf
@ -207,6 +213,7 @@ def _updateMaskedValueSet():
if (controller.getParamKeyValue(confName, "MASK_INPUT") == True):
masked_value_set.add(controller.CONF[confName])
def mask(input):
"""
Gets a dict/list/str and search maksked values in them.
@ -234,6 +241,7 @@ def mask(input):
return output
def removeMaskString(maskedString):
"""
remove an element from masked_value_set
@ -252,6 +260,7 @@ def removeMaskString(maskedString):
if found:
masked_value_set.remove(maskedString)
def validate_param_value(param, value):
cname = param.CONF_NAME
logging.debug("Validating parameter %s." % cname)
@ -265,6 +274,7 @@ def validate_param_value(param, value):
print 'Parameter %s failed validation: %s' % (cname, ex)
raise
def process_param_value(param, value):
_value = value
proclist = param.PROCESSORS or []
@ -287,6 +297,7 @@ def process_param_value(param, value):
raise
return _value
def _handleGroupCondition(config, conditionName, conditionValue):
"""
handle params group pre/post condition
@ -364,6 +375,7 @@ def _loadParamFromFile(config, section, param_name):
return value
def _handleAnswerFileParams(answerFile):
"""
handle loading and validating
@ -428,6 +440,7 @@ def _getanswerfilepath():
controller.MESSAGES.append(msg)
return path
def _gettmpanswerfilepath():
path = None
msg = "Could not find a suitable path on which to create the temporary answerfile"
@ -441,6 +454,7 @@ def _gettmpanswerfilepath():
return path
def _handleInteractiveParams():
try:
logging.debug("Groups: %s" % ', '.join([x.GROUP_NAME for x in controller.getAllGroups()]))
@ -461,7 +475,7 @@ def _handleInteractiveParams():
for param in group.parameters.itervalues():
if not param.CONDITION:
input_param(param)
#update password list, so we know to mask them
# update password list, so we know to mask them
_updateMaskedValueSet()
postConditionValue = True
@ -474,8 +488,8 @@ def _handleInteractiveParams():
if postConditionValue == group.POST_CONDITION_MATCH:
inputLoop = False
else:
#we clear the value of all params in the group
#in order to re-input them by the user
# we clear the value of all params in the group
# in order to re-input them by the user
for param in group.parameters.itervalues():
if controller.CONF.has_key(param.CONF_NAME):
del controller.CONF[param.CONF_NAME]
@ -498,6 +512,7 @@ def _handleInteractiveParams():
logging.error(traceback.format_exc())
raise Exception(output_messages.ERR_EXP_HANDLE_PARAMS)
def _handleParams(configFile):
_addDefaultsToMaskedValueSet()
if configFile:
@ -505,13 +520,14 @@ def _handleParams(configFile):
else:
_handleInteractiveParams()
def _getConditionValue(matchMember):
returnValue = False
if type(matchMember) == types.FunctionType:
returnValue = matchMember(controller.CONF)
elif type(matchMember) == types.StringType:
#we assume that if we get a string as a member it is the name
#of a member of conf_params
# we assume that if we get a string as a member it is the name
# of a member of conf_params
if not controller.CONF.has_key(matchMember):
param = controller.getParamByName(matchMember)
input_param(param)
@ -521,6 +537,7 @@ def _getConditionValue(matchMember):
return returnValue
def _displaySummary():
print output_messages.INFO_DSPLY_PARAMS
@ -561,12 +578,14 @@ def _displaySummary():
else:
logging.debug("user chose to accept user parameters")
def _printAdditionalMessages():
if len(controller.MESSAGES) > 0:
print "\n",output_messages.INFO_ADDTIONAL_MSG
print "\n", output_messages.INFO_ADDTIONAL_MSG
for msg in controller.MESSAGES:
print output_messages.INFO_ADDTIONAL_MSG_BULLET % (msg)
def _addFinalInfoMsg(logFile):
"""
add info msg to the user finalizing the
@ -590,6 +609,7 @@ def _summaryParamsToLog():
def runSequences():
controller.runAllSequences()
def _main(options, configFile=None, logFile=None):
print output_messages.INFO_HEADER
print("")
@ -611,7 +631,7 @@ def _main(options, configFile=None, logFile=None):
logging.debug(mask(controller.CONF))
# Start configuration stage
print "\n",output_messages.INFO_INSTALL
print "\n", output_messages.INFO_INSTALL
# Initialize Sequences
initPluginsSequences()
@ -620,7 +640,7 @@ def _main(options, configFile=None, logFile=None):
runSequences()
# Lock rhevm version
#_lockRpmVersion()
# _lockRpmVersion()
# Print info
_addFinalInfoMsg(logFile)
@ -656,6 +676,7 @@ def remove_remote_var_dirs(options, config, messages):
logging.exception(e)
messages.append(utils.color_text(msg, 'red'))
def remove_temp_files():
"""
Removes any temporary files generated during
@ -701,6 +722,7 @@ def generateAnswerFile(outputFile, overrides={}):
'conf_name': param.CONF_NAME}
ans_file.write(fmt % args)
def single_step_aio_install(options, logFile):
""" Installs an All in One host on this host"""
@ -717,12 +739,13 @@ def single_step_aio_install(options, logFile):
# If we are doing an all-in-one install, do demo provisioning
# unless specifically told not to
if (options.os_neutron_install != "n" and \
not options.provision_all_in_one_ovs_bridge):
options.provision_all_in_one_ovs_bridge = "y"
if (options.os_neutron_install != "n" and
not options.provision_all_in_one_ovs_bridge):
options.provision_all_in_one_ovs_bridge = "y"
single_step_install(options, logFile)
def single_step_install(options, logFile):
answerfilepath = _gettmpanswerfilepath()
if not answerfilepath:
@ -747,11 +770,12 @@ def single_step_install(options, logFile):
# We can also override defaults with command line options
_set_command_line_values(options)
for key,value in commandLineValues.items():
for key, value in commandLineValues.items():
overrides[key] = value
generateAnswerFile(answerfilepath, overrides)
_main(options,answerfilepath, logFile)
_main(options, answerfilepath, logFile)
def initCmdLineParser():
"""
@ -761,7 +785,7 @@ def initCmdLineParser():
# Init parser and all general flags
usage = "usage: %prog [options] [--help]"
parser = OptionParser(usage=usage,version="%prog {0} {1}".format(version.release_string(), version.version_string()))
parser = OptionParser(usage=usage, version="%prog {0} {1}".format(version.release_string(), version.version_string()))
parser.add_option("--gen-answer-file", help="Generate a template of an answer file, using this option excludes all other options")
parser.add_option("--answer-file", help="Runs the configuration in non-interactive mode, extracting all information from the \
configuration file. using this option excludes all other options")
@ -796,6 +820,7 @@ def initCmdLineParser():
return parser
def printOptions():
"""
print and document the available options to the answer file (rst format)
@ -815,6 +840,7 @@ def printOptions():
print " %s %s" % (paramUsage, optionsList)
print
def plugin_compare(x, y):
"""
Used to sort the plugin file list
@ -826,6 +852,7 @@ def plugin_compare(x, y):
y_cmp = y_match.group(1)
return int(x_cmp) - int(y_cmp)
def loadPlugins():
"""
Load All plugins from ./plugins
@ -852,8 +879,9 @@ def loadPlugins():
logging.error(traceback.format_exc())
raise Exception("Failed to load plugin from file %s" % item)
def checkPlugin(plugin):
for funcName in ['initConfig','initSequences']:
for funcName in ['initConfig', 'initSequences']:
if not hasattr(plugin, funcName):
raise ImportError("Plugin %s does not contain the %s function" % (plugin.__class__, funcName))
@ -877,7 +905,7 @@ def countCmdLineFlags(options, flag):
def validateSingleFlag(options, flag):
counter = countCmdLineFlags(options, flag)
if counter > 0:
flag = flag.replace("_","-")
flag = flag.replace("_", "-")
msg = output_messages.ERR_ONLY_1_FLAG % ("--%s" % flag)
raise FlagValidationError(msg)
@ -886,18 +914,21 @@ def initPluginsConfig():
for plugin in controller.getAllPlugins():
plugin.initConfig(controller)
def initPluginsSequences():
for plugin in controller.getAllPlugins():
plugin.initSequences(controller)
def _set_command_line_values(options):
for key, value in options.__dict__.items():
# Replace the _ with - in the string since optparse replace _ with -
for group in controller.getAllGroups():
param = group.search("CMD_OPTION", key.replace("_","-"))
param = group.search("CMD_OPTION", key.replace("_", "-"))
if len(param) > 0 and value:
commandLineValues[param[0].CONF_NAME] = value
def main():
try:
# Load Plugins
@ -935,9 +966,9 @@ def main():
# We can also override defaults with command line options
overrides = {}
_set_command_line_values(options)
for key,value in commandLineValues.items():
for key, value in commandLineValues.items():
overrides[key] = value
generateAnswerFile(answerfilepath,overrides)
generateAnswerFile(answerfilepath, overrides)
_handleParams(answerfilepath)
generateAnswerFile(options.gen_answer_file)
# Are we installing an all in one
@ -957,7 +988,7 @@ def main():
validateSingleFlag(options, "answer_file")
# If using an answer file, setting a default password
# does not really make sense
if getattr(options,'default_password',None):
if getattr(options, 'default_password', None):
msg = ('Please do not set --default-password '
'when specifying an answer file.')
raise FlagValidationError(msg)

View File

@ -208,6 +208,8 @@ def validate_multi_ping(param, options=None):
_tested_ports = []
def touch_port(host, port):
"""
Check that provided host is listening on provided port.

View File

@ -753,7 +753,7 @@ def create_manifest(config, messages):
fw_details = dict()
for host in split_hosts(config['CONFIG_COMPUTE_HOSTS']):
if (config['CONFIG_NOVA_INSTALL'] == 'y' and
config['CONFIG_VMWARE_BACKEND'] == 'n'):
config['CONFIG_VMWARE_BACKEND'] == 'n'):
key = "cinder_%s" % host
fw_details.setdefault(key, {})
fw_details[key]['host'] = "%s" % host

View File

@ -254,11 +254,11 @@ def initConfig(controller):
{"CMD_OPTION": "os-trove-install",
"USAGE": (
"Set to 'y' if you would like Packstack to install "
"OpenStack Database (Trove)"
"Set to 'y' if you would like Packstack to install "
"OpenStack Database (Trove)"
),
"PROMPT": (
"Should Packstack install OpenStack Database (Trove)"
"Should Packstack install OpenStack Database (Trove)"
),
"OPTION_LIST": ["y", "n"],
"VALIDATORS": [validators.validate_options],
@ -272,11 +272,11 @@ def initConfig(controller):
{"CMD_OPTION": "os-ironic-install",
"USAGE": (
"Set to 'y' if you would like Packstack to install "
"OpenStack Bare Metal (Ironic)"
"Set to 'y' if you would like Packstack to install "
"OpenStack Bare Metal (Ironic)"
),
"PROMPT": (
"Should Packstack install OpenStack Bare Metal (Ironic)"
"Should Packstack install OpenStack Bare Metal (Ironic)"
),
"OPTION_LIST": ["y", "n"],
"VALIDATORS": [validators.validate_options],

View File

@ -12,7 +12,7 @@ from packstack.modules.ospluginutils import (getManifestTemplate,
appendManifestFile,
createFirewallResources)
#------------------ Sahara installer initialization ------------------
# ------------------ Sahara installer initialization ------------------
PLUGIN_NAME = "OS-Sahara"
PLUGIN_NAME_COLORED = utils.color_text(PLUGIN_NAME, "blue")
@ -71,7 +71,7 @@ def initSequences(controller):
]
controller.addSequence("Installing Sahara", [], [], saharasteps)
#-------------------------- step functions --------------------------
# -------------------------- step functions --------------------------
def create_keystone_manifest(config, messages):

View File

@ -33,7 +33,7 @@ class SshTarballTransferMixinTestCase(PackstackTestCaseMixin, TestCase):
def tearDown(self):
# remove the temp directory
#shutil.rmtree(self.tempdir)
# shutil.rmtree(self.tempdir)
pass
def setUp(self):

View File

@ -38,4 +38,4 @@ class ProcessorsTestCase(PackstackTestCaseMixin, TestCase):
# test if key exists
# XXX: process_ssh_key does not create ssh key during test run
# ... not sure why, nevertheless it works in normal run
#self.assertEquals(True, os.path.isfile(path))
# self.assertEquals(True, os.path.isfile(path))

View File

@ -33,6 +33,6 @@ commands = python setup.py build_sphinx
# E123, E125 skipped as they are invalid PEP-8.
#
# All other checks should be enabled in the future.
ignore = E123,E125,H803,E128,F403,F821,E127,F811,E265,F401,F841,E129,E231,E501,E302,E272,E111,E502,E202,W601,E271,E721,E712,E261,E131,E126,E303,E711,E241,E713,E121,E122,E401,H402,H302,H303,H304,H301,H306,H234,H405,H404,H904,H201,H305,H307,H501,H102,H233,H101,H233,H401,H232
ignore = E123,E125,H803,E128,F403,F821,E127,F811,F401,F841,E501,E272,E111,E502,E202,W601,E271,E721,E712,E261,E131,E126,E303,E711,E241,E713,E122,E401,H402,H302,H303,H304,H301,H306,H234,H405,H404,H904,H201,H305,H307,H501,H102,H233,H101,H233,H401,H232
show-source = True
exclude=.venv,.git,.tox