Skip to content

Sourcery refactored master branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Jun 10, 2020

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -51 to +52
if 'in' in validations:
if not val in validations['in']:
raise ValueError("{} should be in {}".format(opt, ", ".join(validations['in'])))
if 'in' in validations and val not in validations['in']:
raise ValueError("{} should be in {}".format(opt, ", ".join(validations['in'])))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NetworkAdapter.validateOne refactored with the following changes:

  • Merge nested if conditions
  • Swap positions of nested conditionals
  • Hoist repeated code outside conditional statement
  • Simplify logical expression

Comment on lines -186 to +185
if not 'unknown' in self._ifAttributes:
if 'unknown' not in self._ifAttributes:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NetworkAdapter.setUnknown refactored with the following changes:

  • Simplify logical expression

Comment on lines -228 to +233
self._ifAttributes = {}
self._ifAttributes['bridge-opts'] = {}
self._ifAttributes['up'] = []
self._ifAttributes['down'] = []
self._ifAttributes['pre-up'] = []
self._ifAttributes['post-down'] = []
self._ifAttributes = {
'bridge-opts': {},
'up': [],
'down': [],
'pre-up': [],
'post-down': [],
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NetworkAdapter.reset refactored with the following changes:

  • Merge dictionary assignment with declaration

self.backup_path = path + ".bak"
else:
self.backup_path = backup_path
self.backup_path = path + ".bak" if not backup_path else backup_path
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DnsmasqRange.__init__ refactored with the following changes:

  • Replace if statement with if expression

Comment on lines -26 to +23
if not "dhcp-range" in self._config:
if "dhcp-range" not in self._config:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DnsmasqRange.set refactored with the following changes:

  • Simplify logical expression

Comment on lines -111 to +106
if line.startswith('#') is True:
pass
else:
if line.startswith('#') is not True:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Hostapd.read refactored with the following changes:

  • Swap if/else to remove empty if body

Comment on lines -59 to +62
if line.strip().startswith("#") is True:
pass
else:
if line.strip().startswith("#") is not True:
self._parse_iface(line)
# Ignore blank lines.
if line.isspace() is True:
pass
else:
if line.isspace() is not True:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function InterfacesReader._read_lines_from_file refactored with the following changes:

  • Swap if/else to remove empty if body

Comment on lines -81 to +108
if line[0].isspace() is True:
sline = line.split()
if sline[0] == 'address':
self._adapters[self._context].setAddress(sline[1])
elif sline[0] == 'netmask':
self._adapters[self._context].setNetmask(sline[1])
elif sline[0] == 'gateway':
self._adapters[self._context].setGateway(sline[1])
elif sline[0] == 'broadcast':
self._adapters[self._context].setBroadcast(sline[1])
elif sline[0] == 'network':
self._adapters[self._context].setNetwork(sline[1])
elif sline[0].startswith('bridge') is True:
opt = sline[0].split('_')
sline.pop(0)
ifs = " ".join(sline)
self._adapters[self._context].replaceBropt(opt[1], ifs)
elif sline[0] == 'up' or sline[0] == 'down' or sline[0] == 'pre-up' or sline[0] == 'post-down':
ud = sline.pop(0)
cmd = ' '.join(sline)
if ud == 'up':
self._adapters[self._context].appendUp(cmd)
elif ud == 'down':
self._adapters[self._context].appendDown(cmd)
elif ud == 'pre-up':
self._adapters[self._context].appendPreUp(cmd)
elif ud == 'post-down':
self._adapters[self._context].appendPostDown(cmd)
else:
# store as if so as not to loose it
self._adapters[self._context].setUnknown(sline[0], sline[1])
if line[0].isspace() is not True:
return
sline = line.split()
if sline[0] == 'address':
self._adapters[self._context].setAddress(sline[1])
elif sline[0] == 'netmask':
self._adapters[self._context].setNetmask(sline[1])
elif sline[0] == 'gateway':
self._adapters[self._context].setGateway(sline[1])
elif sline[0] == 'broadcast':
self._adapters[self._context].setBroadcast(sline[1])
elif sline[0] == 'network':
self._adapters[self._context].setNetwork(sline[1])
elif sline[0].startswith('bridge') is True:
opt = sline[0].split('_')
sline.pop(0)
ifs = " ".join(sline)
self._adapters[self._context].replaceBropt(opt[1], ifs)
elif sline[0] in ['up', 'down', 'pre-up', 'post-down']:
ud = sline.pop(0)
cmd = ' '.join(sline)
if ud == 'up':
self._adapters[self._context].appendUp(cmd)
elif ud == 'down':
self._adapters[self._context].appendDown(cmd)
elif ud == 'pre-up':
self._adapters[self._context].appendPreUp(cmd)
elif ud == 'post-down':
self._adapters[self._context].appendPostDown(cmd)
else:
# store as if so as not to loose it
self._adapters[self._context].setUnknown(sline[0], sline[1])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function InterfacesReader._parse_details refactored with the following changes:

  • Add guard clause
  • Replace multiple comparisons of same variable with in operator

Comment on lines -118 to +115
if word == 'auto':
pass
else:
if word != 'auto':
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function InterfacesReader._read_auto refactored with the following changes:

  • Swap if/else to remove empty if body

Comment on lines -128 to +123
if word == 'allow-hotplug':
pass
else:
if word != 'allow-hotplug':
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function InterfacesReader._read_hotplug refactored with the following changes:

  • Swap if/else to remove empty if body

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant