Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jubeaz committed May 25, 2024
1 parent f5948bb commit 77b8c0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
10 changes: 3 additions & 7 deletions arsenal/modules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ def compute_args(self, cheat, gvars):
Process cmdline from the cheatsheet to get args names
"""
self.args = {}
# Use a list of tuples here instead of dict in case
# the cmd has multiple args with the same name..
position = 0
for arg_name in re.findall(r'<([^ <>]+)>', cheat.command):
for position, arg_name in enumerate(re.findall(r"<([^ <>]+)>", cheat.command)):
if "|" in arg_name: # Format <name|default_value>
name, var = arg_name.split("|")[:2]
self._add_arg(name, var, position)
Expand All @@ -60,7 +57,6 @@ def compute_args(self, cheat, gvars):
self._add_arg(arg_name, cheat.variables[arg_name], position)
else:
self._add_arg(arg_name, "", position)
position += 1

def _add_arg(self, name=None, value="", position=0):
if name in self.args:
Expand All @@ -86,7 +82,7 @@ def set_arg_value(self, position, value):

def get_command_parts(self):
if self.nb_place_holder != 0:
regex = '|'.join('<' + arg + '>' for arg in self.args)
regex = "|".join("<" + arg + ">" for arg in self.args)
cmdparts = re.split(regex, self.cmdline)
else:
cmdparts = [self.cmdline]
Expand All @@ -103,7 +99,7 @@ def build(self):
argsval = [a[1] for a in self.args]
if "" not in argsval:
# split cmdline at each arg position
regex = '|'.join('<' + arg + '>' for arg in self.args)
regex = "|".join("<" + arg + ">" for arg in self.args)
cmdparts = re.split(regex, self.cmdline)
# concat command parts and arguments values to build the command
self.cmdline = ""
Expand Down
18 changes: 3 additions & 15 deletions arsenal/modules/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ def get_nb_preview_new_lines(self):
firstline = False

# extract len of args in the current line
i = 0
for arg_name, arg_val in Gui.cmd.args.items():
for i, (arg_name, arg_val) in enumerate(Gui.cmd.args.items()):
if i == next_arg and nb_args_todo > 0:
if arg_val["value"] != "":
# use value len if not empty
Expand All @@ -436,7 +435,6 @@ def get_nb_preview_new_lines(self):
nbchar += (len(arg_name) + 2)
next_arg += 1
nb_args_todo -= 1
i += 1

# len of the cmd body
for p in parts:
Expand Down Expand Up @@ -556,12 +554,7 @@ def draw_cmd_preview(self, argprev, p_x, p_y=1):
self.draw_preview_part(argprev, cmdparts[i // 2], curses.color_pair(Gui.BASIC_COLOR))
else:
arg_name, arg_value = Gui.cmd.get_arg((i - 1) // 2)
if arg_value == "":
# if arg empty use its name
arg = '<' + arg_name + '>'
else:
# else its value
arg = arg_value
arg = "<" + arg_name + ">" if arg_value == "" else arg_value

# draw argument
if self.current_arg_name == arg_name:
Expand Down Expand Up @@ -590,10 +583,6 @@ def draw(self, stdscr):
# draw argslist menu popup
self.prev_lastline_len = 0
nbpreviewnewlines = self.get_nb_preview_new_lines()
# if len(Gui.cmd.args) != 0:
# nbpreviewnewlines = self.get_nb_preview_new_lines()
# else:
# nbpreviewnewlines = 0

# -------------- border
# cmd
Expand Down Expand Up @@ -664,7 +653,7 @@ def autocomplete_arg(self):
"""
# current argument value
# look for all files that match the argument in the working directory
matches = glob.glob('{}*'.format(self.current_arg_value))
matches = glob.glob(f"{self.current_arg_value}*")

if not matches:
return False
Expand Down Expand Up @@ -791,7 +780,6 @@ class Gui:
INFO_DESC_COLOR = 0
INFO_CMD_COLOR = 0
ARG_NAME_COLOR = 5

loaded_menu = False

def __init__(self):
Expand Down

0 comments on commit 77b8c0f

Please sign in to comment.