Skip to content

Commit

Permalink
Delete function, rewrite logic in call.
Browse files Browse the repository at this point in the history
  • Loading branch information
LupusE committed Aug 17, 2024
1 parent 336d8f2 commit 251c13d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions software/script/chameleon_cli_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ def check_tools():
print(f'{CR}Warning, tools {", ".join(missing_tools)} not found. '
f'Corresponding commands will not work as intended.{C0}')

dict_keys = set()
def load_dic_file(filename, keys):
#print("Read directory from", filename) ## debug
for dict_key in filename.readlines():
if not dict_key.startswith("#") and not dict_key.isspace():
dict_keys.add(dict_key)

return dict_keys

class BaseCLIUnit:
def __init__(self):
Expand Down Expand Up @@ -951,12 +943,17 @@ def on_exec(self, args: argparse.Namespace):
return

if args.import_dic is not None:
for key in load_dic_file(args.import_dic, keys):
if not re.match(r'^[a-fA-F0-9]{12}$', key):
for key in args.import_dic.readlines():
if key.startswith("#"): # ignore comments
pass
elif key.isspace(): # ignore empty lines
pass
elif re.match(r'^[a-fA-F0-9]{12}$', key): # take only this key format
keys.add(bytes.fromhex(key))
else: # in case of another format, a conversion is needed
print(f' - {CR}Key should in hex[12] format, invalid key is ignored{C0}, key = "{key}"')
continue
keys.add(bytes.fromhex(key))

continue

if len(keys) == 0:
print(f' - {CR}No keys{C0}')
return
Expand Down

0 comments on commit 251c13d

Please sign in to comment.