Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make searching filenames for matches optional #128

Merged
merged 3 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pywhat/identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def identify(
dist: Distribution = None,
key: Optional[Callable] = None,
reverse: Optional[bool] = None,
boundaryless: Optional[Filter] = None
boundaryless: Optional[Filter] = None,
include_filenames=False,
) -> dict:
if dist is None:
dist = self.distribution
Expand Down Expand Up @@ -68,7 +69,10 @@ def identify(

magic_numbers = self._file_sig.open_binary_scan_magic_nums(string)
contents = self._file_sig.open_file_loc(string)
contents.append(os.path.basename(string))

if include_filenames:
contents.append(os.path.basename(string))

regex = self._regex_id.check(contents, dist)

if not magic_numbers:
Expand Down
24 changes: 21 additions & 3 deletions pywhat/what.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def create_filter(rarity, include, exclude):
default="0.1:1",
)
@click.option("-i", "--include", help="Only show matches with these tags.")
@click.option("-e", "--exclude", help="Disclude matches with these tags.")
@click.option("-e", "--exclude", help="Exclude matches with these tags.")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NICEE!!!!!

@click.option("-o", "--only-text", is_flag=True, help="Do not scan files or folders.")
@click.option("-k", "--key", help="Sort by the specified key.")
@click.option("--reverse", is_flag=True, help="Sort in reverse order.")
Expand All @@ -89,6 +89,12 @@ def create_filter(rarity, include, exclude):
"-db", "--disable-boundaryless", is_flag=True, help="Disable boundaryless mode."
)
@click.option("--json", is_flag=True, help="Return results in json format.")
@click.option(
"-if",
"--include-filenames",
is_flag=True,
help="Search filenames for possible matches."
)
def main(**kwargs):
"""
pyWhat - Identify what something is.
Expand Down Expand Up @@ -199,7 +205,12 @@ def main(**kwargs):
print("Invalid key")
sys.exit(1)
identified_output = what_obj.what_is_this(
kwargs["text_input"], kwargs["only_text"], key, kwargs["reverse"], boundaryless
kwargs["text_input"],
kwargs["only_text"],
key,
kwargs["reverse"],
boundaryless,
kwargs["include_filenames"],
)

p = printer.Printing()
Expand All @@ -216,7 +227,13 @@ def __init__(self, distribution):
self.id = identifier.Identifier(dist=distribution)

def what_is_this(
self, text: str, only_text: bool, key, reverse: bool, boundaryless: Filter
self,
text: str,
only_text: bool,
key,
reverse: bool,
boundaryless: Filter,
include_filenames: bool,
) -> dict:
"""
Returns a Python dictionary of everything that has been identified
Expand All @@ -227,6 +244,7 @@ def what_is_this(
key=key,
reverse=reverse,
boundaryless=boundaryless,
include_filenames=include_filenames
)


Expand Down