Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
  • Loading branch information
TG1999 committed Apr 22, 2024
1 parent 971e688 commit 1c08d6f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
3 changes: 1 addition & 2 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2016,8 +2016,7 @@ def win_exes(self):
Keep sync with the content type implementation at ``typecode.contenttype``.
"""
return self.files().filter(
Q(file_type__icontains="for ms windows")
| Q(file_type__istartswith="pe32")
Q(file_type__icontains="for ms windows") | Q(file_type__istartswith="pe32")
)

def mach_os(self):
Expand Down
8 changes: 2 additions & 6 deletions scanpipe/pipelines/deploy_to_develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,12 @@ def map_javascript(self):

@group("Elf")
def map_elf(self):
"""
Map DWARF paths using similarities of path suffixes.
"""
"""Map DWARF paths using similarities of path suffixes."""
d2d.map_elfs(project=self.project, logger=self.log)

@group("Go")
def map_go(self):
"""
Map DWARF paths using similarities of path suffixes.
"""
"""Map GO file paths using similarities of path suffixes."""
d2d.map_go_paths(project=self.project, logger=self.log)

def match_directories_to_purldb(self):
Expand Down
38 changes: 20 additions & 18 deletions scanpipe/pipes/d2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,7 @@ def _map_paths_resource(
continue

matched_path_length = match.matched_path_length
if matched_path_length == 1 and len(match.resource_ids) != 1:
if check_match(match, matched_path_length):
not_mapped_paths.append(path)
continue

Expand Down Expand Up @@ -1717,26 +1717,28 @@ def _map_paths_resource(

if relations:
rels = CodebaseRelation.objects.bulk_create(relations.values())
if logger:
logger(
f"Created {len(rels)} mappings using {', '.join(map_types).upper()} for: {to_resource.path!r}"
)
logger(
f"""Created {len(rels)} mappings using
{', '.join(map_types).upper()} for: {to_resource.path!r}"""
)
else:
if logger:
logger(
f"No mappings using {', '.join(map_types).upper()} for: {to_resource.path!r}"
)
logger(
f"""No mappings using {', '.join(map_types).upper()} for:
{to_resource.path!r}"""
)

for map_type in map_types:
if to_resource.extra_data[f"{map_type}_not_mapped"]:
if to_resource.extra_data.get(f"{map_type}_not_mapped"):
to_resource.save()
if logger:
logger(
f"WARNING: {map_type.upper()} paths NOT mapped for: {to_resource.path!r}: "
+ ", ".join(
map(repr, to_resource.extra_data[f"{map_type}_not_mapped"])
)
)
logger(
f"""WARNING: {map_type.upper()} paths NOT mapped for:
{to_resource.path!r}: """
+ ", ".join(map(repr, to_resource.extra_data[f"{map_type}_not_mapped"]))
)


def check_match(match, matched_path_length):
return matched_path_length == 1 and len(match.resource_ids) != 1


def map_paths(project, file_type, collect_paths_func, map_types, logger=None):
Expand All @@ -1760,7 +1762,7 @@ def map_paths(project, file_type, collect_paths_func, map_types, logger=None):
)

if logger:
logger(f"Done building from/ resources index.")
logger("Done building from/ resources index.")

resource_iterator = to_resources.iterator(chunk_size=2000)
progress = LoopProgress(resource_count, logger)
Expand Down
21 changes: 11 additions & 10 deletions scanpipe/tests/pipes/test_d2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,14 +1485,15 @@ def test_scanpipe_pipes_d2d_map_elfs(self):
)
pipes.collect_and_create_codebase_resources(self.project1)
print(self.project1.codebaseresources.files().from_codebase())
d2d.map_elfs(project=self.project1, logger=None)
assert (
buffer = io.StringIO()
d2d.map_elfs(project=self.project1, logger=buffer.write)
self.assertEqual(
1,
CodebaseRelation.objects.filter(
project=self.project1, map_type="dwarf_included_paths"
).count()
== 1
).count(),
)

def test_scanpipe_pipes_d2d_map_go_paths(self):
input_dir = self.project1.input_path
input_resources = [
Expand All @@ -1514,11 +1515,11 @@ def test_scanpipe_pipes_d2d_map_go_paths(self):
recurse=True,
)
pipes.collect_and_create_codebase_resources(self.project1)

d2d.map_go_paths(project=self.project1, logger=None)
assert (
buffer = io.StringIO()
d2d.map_go_paths(project=self.project1, logger=buffer.write)
self.assertEqual(
1,
CodebaseRelation.objects.filter(
project=self.project1, map_type="go_file_paths"
).count()
== 1
).count(),
)

0 comments on commit 1c08d6f

Please sign in to comment.