Sourcery refactored master branch#1
Conversation
| print ("Usage: %s <IDA install path> [--install | --remove]" % sys.argv[0]) | ||
| print(f"Usage: {sys.argv[0]} <IDA install path> [--install | --remove]") | ||
| sys.exit(1) | ||
|
|
||
| source_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
|
||
| if install: | ||
| print ("Installing python modules from %s to %s..." % (source_path, py_module_path)) | ||
| print(f"Installing python modules from {source_path} to {py_module_path}...") | ||
| else: | ||
| print ("Removing python modules from %s..." % py_module_path) | ||
| print(f"Removing python modules from {py_module_path}...") | ||
|
|
||
| for py_module in next(os.walk('.'))[1]: | ||
| src = os.path.join(source_path, py_module, py_module + '.py') | ||
| dst = os.path.join(py_module_path, py_module + '.py') | ||
| src = os.path.join(source_path, py_module, f'{py_module}.py') | ||
| dst = os.path.join(py_module_path, f'{py_module}.py') | ||
|
|
||
| if install: | ||
| print ("Installing %s..." % py_module) | ||
| print(f"Installing {py_module}...") | ||
| shutil.copyfile(src, dst) | ||
| else: | ||
| print ("Removing %s..." % py_module) | ||
| print(f"Removing {py_module}...") |
There was a problem hiding this comment.
Lines 14-32 refactored with the following changes:
- Replace interpolated string formatting with f-string [×5] (
replace-interpolation-with-fstring) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| plugins = [] | ||
| for plugin in os.listdir(source_path): | ||
| if not os.path.isdir(os.path.join(source_path, plugin)): | ||
| continue | ||
| plugins.append(plugin) | ||
| return plugins | ||
| return [ | ||
| plugin | ||
| for plugin in os.listdir(source_path) | ||
| if os.path.isdir(os.path.join(source_path, plugin)) | ||
| ] |
There was a problem hiding this comment.
Function get_plugin_directories refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Lift code into else after jump in control flow (
reintroduce-else) - Remove redundant continue statement (
remove-redundant-continue) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| print("Installing plugins from %s to %s..." % (source_path, install_path)) | ||
| print(f"Installing plugins from {source_path} to {install_path}...") | ||
|
|
||
| plugins = get_plugin_directories(source_path) | ||
| for plugin in plugins: | ||
| print("Installing %s..." % plugin, end=''), | ||
| (print(f"Installing {plugin}...", end=''), ) | ||
| if 'shims' in plugin: | ||
| shims_dir = os.path.join(install_path, 'shims') | ||
| try: | ||
| os.mkdir(shims_dir) | ||
| except OSError: | ||
| pass | ||
| src = os.path.join(source_path, plugin, 'ida_' + plugin + '.py') | ||
| dst = os.path.join(shims_dir, 'ida_' + plugin + '.py') | ||
| src = os.path.join(source_path, plugin, f'ida_{plugin}.py') | ||
| dst = os.path.join(shims_dir, f'ida_{plugin}.py') | ||
| open(os.path.join(shims_dir, '__init__.py'), 'a').close() | ||
| else: | ||
| src = os.path.join(source_path, plugin, plugin + '.py') | ||
| dst = os.path.join(install_path, plugin + '.py') | ||
| src = os.path.join(source_path, plugin, f'{plugin}.py') | ||
| dst = os.path.join(install_path, f'{plugin}.py') |
There was a problem hiding this comment.
Function install_plugins refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring) - Use f-string instead of string concatenation [×6] (
use-fstring-for-concatenation)
| print("Removing plugins from %s..." % install_path) | ||
| print(f"Removing plugins from {install_path}...") | ||
|
|
||
| plugins = get_plugin_directories(source_path) | ||
| for plugin in plugins: | ||
| print("Removing %s..." % plugin, end='') | ||
| print(f"Removing {plugin}...", end='') | ||
| try: | ||
| if 'shims' in plugin: | ||
| dst = os.path.join(install_path, 'shims', 'ida_' + | ||
| plugin + '.py') | ||
| shutil.rmtree(os.path.dirname(dst)) | ||
| else: | ||
| dst = os.path.join(install_path, plugin + '.py') | ||
| dst = os.path.join(install_path, f'{plugin}.py') | ||
| os.remove(dst) | ||
| except OSError: | ||
| print('%s was not installed' % plugin) | ||
| print(f'{plugin} was not installed') |
There was a problem hiding this comment.
Function remove_plugins refactored with the following changes:
- Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
|
|
||
| parser.add_argument('-d', '--directory', help='IDA installation directory.') | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| if not os.path.exists(args.directory): | ||
| raise Exception('IDA installation, %s, does not exist.' % | ||
| args.directory) | ||
| raise Exception(f'IDA installation, {args.directory}, does not exist.') |
There was a problem hiding this comment.
Lines 95-102 refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| if self.history_index < 0: | ||
| self.history_index = 0 | ||
| self.history_index = max(self.history_index, 0) |
There was a problem hiding this comment.
Function AlleyCatGraphHistory.undo refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
| else: | ||
| self.cmd_undo = self.AddCommand("Undo", "") | ||
| self.cmd_redo = self.AddCommand("Redo", "") | ||
| self.cmd_reset = self.AddCommand("Reset graph", "") | ||
| self.cmd_exclude = self.AddCommand("Exclude node", "") | ||
| self.cmd_include = self.AddCommand("Include node", "") | ||
| self.cmd_unhighlight = self.AddCommand( | ||
| "Temporarily un-highlight all paths", "") | ||
| return True | ||
| self.cmd_undo = self.AddCommand("Undo", "") | ||
| self.cmd_redo = self.AddCommand("Redo", "") | ||
| self.cmd_reset = self.AddCommand("Reset graph", "") | ||
| self.cmd_exclude = self.AddCommand("Exclude node", "") | ||
| self.cmd_include = self.AddCommand("Include node", "") | ||
| self.cmd_unhighlight = self.AddCommand( | ||
| "Temporarily un-highlight all paths", "") | ||
| return True |
There was a problem hiding this comment.
Function AlleyCatGraph.Show refactored with the following changes:
- Swap if/else branches [×2] (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| for xref in idautils.XrefsTo(edge_node_ea): | ||
| # Is the specified node_id the source of this xref? | ||
| if self.match_xref_source(xref, node_ea): | ||
| xref_locations.append((xref.frm, edge_node_ea)) | ||
|
|
||
| xref_locations.extend( | ||
| (xref.frm, edge_node_ea) | ||
| for xref in idautils.XrefsTo(edge_node_ea) | ||
| if self.match_xref_source(xref, node_ea) | ||
| ) | ||
| if xref_locations: | ||
| xref_locations.sort() | ||
|
|
||
| print("") | ||
| print("Path Xrefs from %s:" % self[node_id]) | ||
| print(f"Path Xrefs from {self[node_id]}:") |
There was a problem hiding this comment.
Function AlleyCatGraph.OnDblClick refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
This removes the following comments ( why? ):
# Is the specified node_id the source of this xref?
| if not name: | ||
| name = "0x%X" % ea | ||
| if not name: | ||
| name = "0x%X" % ea |
There was a problem hiding this comment.
Function AlleyCatGraph.get_name_by_ea refactored with the following changes:
- Hoist conditional out of nested conditional (
hoist-if-from-if)
| # Colorizes an entire code block | ||
| func = idaapi.get_func(ea) | ||
| if func: | ||
| if func := idaapi.get_func(ea): |
There was a problem hiding this comment.
Function AlleyCatGraph.colorize_node refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
This removes the following comments ( why? ):
# Colorizes an entire code block
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:Help us improve this pull request!