update hacking requirement to version 0.10

This patch updates hacking requiremes and fixes
all pep8 errors, including python3 syntax.

Almost all errors are comments, not separated by
space from sharp symbol.

Also there was one xrange usage and 'file', which
are not available in python3.

Change-Id: I13af226e8409d2e8576d07a974e34676cfa8137c
Closes-bug: #1546446
This commit is contained in:
Dmitry Guryanov 2016-02-29 13:49:01 +03:00
parent 8313c4d8ab
commit 8228aefe5a
18 changed files with 173 additions and 166 deletions

View File

@ -56,7 +56,8 @@ class WidgetType(object):
class ModuleHelper(object):
@classmethod
def get_setting(cls, settings, key):
"""Retrieving setting by key
"""Retrieving setting by key.
:param settings: settings from config file
:param key: setting name (format: '[{section_name}/]{setting_name}')
:returns: setting value
@ -71,7 +72,8 @@ class ModuleHelper(object):
@classmethod
def set_setting(cls, settings, key, value, default_settings=None):
"""Sets new setting by key
"""Sets new setting by key.
:param settings: settings from config file
:param key: setting name (format: '[{section_name}/]{setting_name}')
:param value: new value

View File

@ -134,7 +134,8 @@ def netmaskToCidr(netmask):
def duplicateIPExists(ip, iface, arping_bind=False):
"""Checks for duplicate IP addresses using arping
"""Checks for duplicate IP addresses using arping.
Don't use arping_bind unless you know what you are doing.
:param ip: IP to scan for

View File

@ -15,6 +15,8 @@
import random
import string
from six.moves import range
def password(arg=None):
try:
@ -22,4 +24,4 @@ def password(arg=None):
except Exception:
length = 24
chars = string.letters + string.digits
return ''.join([random.choice(chars) for _ in xrange(length)])
return ''.join([random.choice(chars) for _ in range(length)])

View File

@ -37,7 +37,8 @@ def TextField(keyword, label, width, default_value=None, tooltip=None,
if disabled:
wrapped_obj = urwid.WidgetDisable(urwid.AttrWrap(edit_obj,
'important', 'editfc'))
#Add get_edit_text and set_edit_text to wrapped_obj so we can use later
# Add get_edit_text and set_edit_text to
# wrapped_obj so we can use later
wrapped_obj.set_edit_text = edit_obj.set_edit_text
wrapped_obj.get_edit_text = edit_obj.get_edit_text
return wrapped_obj

View File

@ -97,7 +97,7 @@ to advertise via DHCP to nodes",
if fieldname != "blank" and "label" not in fieldname:
responses[fieldname] = self.edits[index].get_edit_text()
###Validate each field
# Validate each field
errors = []
# Set internal_{ipaddress,netmask,interface}
@ -154,7 +154,7 @@ else deployment will likely fail."))
dialog.display_dialog(self, urwid.Pile(dhcp_info),
"DHCP Servers Found on %s"
% self.activeiface)
###Ensure pool start and end are on the same subnet as mgmt_if
# Ensure pool start and end are on the same subnet as mgmt_if
# Ensure mgmt_if has an IP first
if len(self.netsettings[responses[
"ADMIN_NETWORK/interface"]]["addr"]) == 0:
@ -202,7 +202,8 @@ interface first.")
except Exception:
errors.append("Invalid IP address for DHCP Pool end")
#Ensure pool start and end are in the same subnet of each other
# Ensure pool start and end are in the same
# subnet of each other
netmask = self.netsettings[responses[
"ADMIN_NETWORK/interface"
]]["netmask"]
@ -292,7 +293,7 @@ interface first.")
return oldsettings
def save(self, responses):
## Generic settings start ##
# Generic settings start ##
newsettings = ModuleHelper.save(self, responses)
for setting in responses.keys():
if "/" in setting:
@ -303,9 +304,9 @@ interface first.")
newsettings[part1][part2] = responses[setting]
else:
newsettings[setting] = responses[setting]
## Generic settings end ##
# Generic settings end
## Need to calculate and netmask
# Need to calculate and netmask
newsettings['ADMIN_NETWORK']['netmask'] = \
self.netsettings[newsettings['ADMIN_NETWORK']['interface']][
"netmask"]
@ -334,9 +335,9 @@ interface first.")
def radioSelect(self, current, state, user_data=None):
"""Update network details and display information."""
### Urwid returns the previously selected radio button.
### The previous object has True state, which is wrong.
### Somewhere in rb group a RadioButton is set to True.
# Urwid returns the previously selected radio button.
# The previous object has True state, which is wrong.
# Somewhere in rb group a RadioButton is set to True.
for rb in current.group:
if rb.get_label() == current.get_label():
continue
@ -373,9 +374,9 @@ interface first.")
# If DHCP pool start and matches activeiface network, don't update
# This means if you change your pool values, go to another page, then
# go back, it will not reset your changes. But what is more likely is
#you will change the network settings for admin interface and then come
#back to this page to update your DHCP settings. If the inSameSubnet
#test fails, just recalculate and set new values.
# you will change the network settings for admin interface and then
# come back to this page to update your DHCP settings. If the
# inSameSubnet test fails, just recalculate and set new values.
for index, key in enumerate(self.fields):
if key == "ADMIN_NETWORK/dhcp_pool_start":
dhcp_start = self.edits[index].get_edit_text()

View File

@ -111,7 +111,7 @@ is accessible"}
else:
responses[fieldname] = self.edits[index].get_edit_text()
###Validate each field
# Validate each field
errors = []
# hostname must be under 60 chars
@ -341,7 +341,7 @@ is accessible"}
return searches, domain, ",".join(nameservers)
def save(self, responses):
## Generic settings start ##
# Generic settings start
newsettings = dict()
for setting in responses.keys():
if "/" in setting:
@ -352,7 +352,7 @@ is accessible"}
newsettings[part1][part2] = responses[setting]
else:
newsettings[setting] = responses[setting]
## Generic settings end ##
# Generic settings end
# log.debug(str(newsettings))
Settings().write(newsettings,

View File

@ -134,7 +134,7 @@ class interfaces(urwid.WidgetWrap):
else:
responses[fieldname] = self.edits[index].get_edit_text()
###Validate each field
# Validate each field
errors = []
# Check for the duplicate IP provided
@ -339,10 +339,10 @@ class interfaces(urwid.WidgetWrap):
def radioSelectIface(self, current, state, user_data=None):
"""Update network details and display information."""
### This makes no sense, but urwid returns the previous object.
### The previous object has True state, which is wrong.
### Somewhere in current.group a RadioButton is set to True.
### Our quest is to find it.
# This makes no sense, but urwid returns the previous object.
# The previous object has True state, which is wrong.
# Somewhere in current.group a RadioButton is set to True.
# Our quest is to find it.
for rb in current.group:
if rb.get_label() == current.get_label():
continue
@ -354,10 +354,10 @@ class interfaces(urwid.WidgetWrap):
def radioSelect(self, current, state, user_data=None):
"""Update network details and display information."""
### This makes no sense, but urwid returns the previous object.
### The previous object has True state, which is wrong.
### Somewhere in current.group a RadioButton is set to True.
### Our quest is to find it.
# This makes no sense, but urwid returns the previous object.
# The previous object has True state, which is wrong.
# Somewhere in current.group a RadioButton is set to True.
# Our quest is to find it.
for rb in current.group:
if rb.get_label() == current.get_label():
continue

View File

@ -85,7 +85,7 @@ class ntpsetup(urwid.WidgetWrap):
else:
responses[fieldname] = self.edits[index].get_edit_text()
###Validate each field
# Validate each field
errors = []
warnings = []
if responses['ntpenabled'] == "No":
@ -179,7 +179,7 @@ class ntpsetup(urwid.WidgetWrap):
return ModuleHelper.load(self, ignoredparams=['ntpenabled'])
def save(self, responses):
## Generic settings start ##
# Generic settings start
newsettings = dict()
for setting in responses.keys():
if "/" in setting:
@ -190,7 +190,7 @@ class ntpsetup(urwid.WidgetWrap):
newsettings[part1][part2] = responses[setting]
else:
newsettings[setting] = responses[setting]
## Generic settings end ##
# Generic settings end
Settings().write(newsettings,
defaultsfile=self.parent.defaultsettingsfile,
@ -222,10 +222,10 @@ class ntpsetup(urwid.WidgetWrap):
def radioSelect(self, current, state, user_data=None):
"""Update network details and display information."""
### This makes no sense, but urwid returns the previous object.
### The previous object has True state, which is wrong.
### Somewhere in current.group a RadioButton is set to True.
### Our quest is to find it.
# This makes no sense, but urwid returns the previous object.
# The previous object has True state, which is wrong.
# Somewhere in current.group a RadioButton is set to True.
# Our quest is to find it.
for rb in current.group:
if rb.get_label() == current.get_label():
continue

View File

@ -23,7 +23,7 @@ import urwid.web_display
blank = urwid.Divider()
class saveandquit():
class saveandquit(object):
def __init__(self, parent):
self.name = "Quit Setup"
self.priority = 99

View File

@ -147,7 +147,7 @@ class servicepws(urwid.WidgetWrap):
return ModuleHelper.load(self)
def save(self, responses):
## Generic settings start ##
# Generic settings start
newsettings = OrderedDict()
for setting in responses.keys():
if "/" in setting:
@ -168,7 +168,7 @@ class servicepws(urwid.WidgetWrap):
defaultsfile=self.parent.defaultsettingsfile,
outfn=self.parent.settingsfile)
## Generic settings end ##
# Generic settings end
log.debug('done saving servicepws')
# Set oldsettings to reflect new settings

View File

@ -23,7 +23,7 @@ import urwid.web_display
blank = urwid.Divider()
class shell():
class shell(object):
def __init__(self, parent):
self.name = "Shell Login"
self.priority = 90

View File

@ -98,7 +98,7 @@ class Settings(object):
settings = self.read(defaultsfile)
settings.update(self.read(outfn))
settings.update(newvalues)
outfile = file(outfn, 'w')
with open(outfn, 'w') as outfile:
yaml.dump(settings, outfile, default_style='"',
default_flow_style=False)
return True

View File

@ -14,7 +14,7 @@ commands =
py.test -vv {posargs:fuelmenu/tests}
[testenv:pep8]
deps = hacking==0.7
deps = hacking==0.10
usedevelop = False
commands =
flake8 {posargs:.}