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

View File

@ -134,7 +134,8 @@ def netmaskToCidr(netmask):
def duplicateIPExists(ip, iface, arping_bind=False): 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. Don't use arping_bind unless you know what you are doing.
:param ip: IP to scan for :param ip: IP to scan for

View File

@ -15,6 +15,8 @@
import random import random
import string import string
from six.moves import range
def password(arg=None): def password(arg=None):
try: try:
@ -22,4 +24,4 @@ def password(arg=None):
except Exception: except Exception:
length = 24 length = 24
chars = string.letters + string.digits 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: if disabled:
wrapped_obj = urwid.WidgetDisable(urwid.AttrWrap(edit_obj, wrapped_obj = urwid.WidgetDisable(urwid.AttrWrap(edit_obj,
'important', 'editfc')) '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.set_edit_text = edit_obj.set_edit_text
wrapped_obj.get_edit_text = edit_obj.get_edit_text wrapped_obj.get_edit_text = edit_obj.get_edit_text
return wrapped_obj return wrapped_obj

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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