Skip to content

Commit

Permalink
simplify to_rows()
Browse files Browse the repository at this point in the history
  • Loading branch information
epogrebnyak committed Mar 4, 2024
1 parent d8f394c commit 2e9915c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
3 changes: 2 additions & 1 deletion justpath/oneliners.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def print(self):
bash='echo $PATH | tr ":" "\\n" | sort | uniq -d # does not preserve order from PATH',
)


def print_alternatives():
for job in [RAW, DUPLICATES, BY_LINE]:
job.print()
print()
print()
17 changes: 7 additions & 10 deletions justpath/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,13 @@ def max_digits(self) -> int:
return len(str(max(self.keys()))) if self.keys() else 0

def to_rows(self, follow_symlinks: bool) -> list["Row"]:
if follow_symlinks:
getter = resolve
else:
getter = as_is
counter = Counter([getter(p) for p in self.values()])
rows = []
for i, path in self.items():
row = Row(i, path, counter[getter(path)])
rows.append(row)
return rows
getter = resolve if follow_symlinks else as_is
counter = Counter([getter(path) for path in self.values()])

def make_row(i, path):
return Row(i, path, counter[getter(path)])

return [make_row(i, path) for i, path in self.items()]


def resolve(path: Path):
Expand Down

0 comments on commit 2e9915c

Please sign in to comment.