Skip to content

Commit

Permalink
[FIX] Change --load-hashes to boolean flag, use --hashfiles to pre-lo…
Browse files Browse the repository at this point in the history
…ad hash+path data
  • Loading branch information
KeyWeeUsr committed Sep 16, 2019
1 parent 1cf5896 commit d1ec0d9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 8 additions & 2 deletions bear/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def main(args: Namespace):
elif ctx.community:
open_browser(COMMUNITY_URL)
elif ctx.load_hashes:
if not ctx.hashfiles:
ctx.hashfiles = ctx.load_hashes
load_hashes(ctx=ctx)


Expand Down Expand Up @@ -203,6 +205,10 @@ def run():
"--max-size", metavar="BYTES", action="store", type=int, default=0,
help="exclude files if their size is above the limit, 0=unlimited"
)
parser.add_argument(
'--hashfiles', metavar='FILE', type=str, nargs='+', default=[],
help='files containing hash+path lines'
)

group_verbosity = parser.add_mutually_exclusive_group()
group_verbosity.add_argument(
Expand Down Expand Up @@ -245,8 +251,8 @@ def run():
)
)
group_action.add_argument(
'--load-hashes', metavar='FILE', type=str, nargs='+', default=[],
help='find all duplicated files from files containing hash+path lines'
'--load-hashes', action="store_true",
help='only load data from hashfiles (containing hash+path lines)'
)

group_remove = parser.add_mutually_exclusive_group()
Expand Down
8 changes: 5 additions & 3 deletions bear/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class Context:
blake2: bool
sha256: bool
max_size: int
load_hashes: list
load_hashes: bool
hasher: Hasher
hashfiles: list

@ensure_annotations
def __init__(self, args: Namespace):
Expand All @@ -57,8 +58,9 @@ def __init__(self, args: Namespace):
blake2=False,
sha256=False,
max_size=0,
load_hashes=[],
hasher=Hasher.MD5
load_hashes=False,
hasher=Hasher.MD5,
hashfiles=[]
)

for key, value in vars(args).items():
Expand Down
2 changes: 1 addition & 1 deletion bear/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def load_duplicates_from_hashfiles(ctx: Context) -> dict:
"""
# join values from hashfiles
files = {}
for hashfile in ctx.load_hashes:
for hashfile in ctx.hashfiles:
with open(hashfile) as file:
lines = file.readlines()
for line in lines:
Expand Down

0 comments on commit d1ec0d9

Please sign in to comment.