Conversation
| 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']))) |
There was a problem hiding this comment.
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
| if not 'unknown' in self._ifAttributes: | ||
| if 'unknown' not in self._ifAttributes: |
There was a problem hiding this comment.
Function NetworkAdapter.setUnknown refactored with the following changes:
- Simplify logical expression
| 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': [], | ||
| } |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Function DnsmasqRange.__init__ refactored with the following changes:
- Replace if statement with if expression
| if not "dhcp-range" in self._config: | ||
| if "dhcp-range" not in self._config: |
There was a problem hiding this comment.
Function DnsmasqRange.set refactored with the following changes:
- Simplify logical expression
| if line.startswith('#') is True: | ||
| pass | ||
| else: | ||
| if line.startswith('#') is not True: |
There was a problem hiding this comment.
Function Hostapd.read refactored with the following changes:
- Swap if/else to remove empty if body
| 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: |
There was a problem hiding this comment.
Function InterfacesReader._read_lines_from_file refactored with the following changes:
- Swap if/else to remove empty if body
| 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]) |
There was a problem hiding this comment.
Function InterfacesReader._parse_details refactored with the following changes:
- Add guard clause
- Replace multiple comparisons of same variable with
inoperator
| if word == 'auto': | ||
| pass | ||
| else: | ||
| if word != 'auto': |
There was a problem hiding this comment.
Function InterfacesReader._read_auto refactored with the following changes:
- Swap if/else to remove empty if body
| if word == 'allow-hotplug': | ||
| pass | ||
| else: | ||
| if word != 'allow-hotplug': |
There was a problem hiding this comment.
Function InterfacesReader._read_hotplug refactored with the following changes:
- Swap if/else to remove empty if body
Branch
masterrefactored 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
masterbranch, then run: