Skip to content

Commit

Permalink
feat: Fix PermissionError when reading files
Browse files Browse the repository at this point in the history
  • Loading branch information
Parzival1918 committed Oct 3, 2023
1 parent afcecf9 commit f8966ba
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pu_pjr/dir_stats/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main():
parser.set_defaults(which="main")

parser.add_argument(
"--version", "-v", action="version", version="%(prog)s v0.14.0"
"--version", "-v", action="version", version="%(prog)s v0.15.0"
)

subparser = parser.add_subparsers(required=True)
Expand Down
14 changes: 12 additions & 2 deletions pu_pjr/dir_stats/dir_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def find_files_type(dir: pathlib.Path,
ignore_hidden_dirs: bool = False) -> None:
"""Print all files of a certain type in a directory and subdirectories."""

paths = pathlib.Path(dir).iterdir()
try:
paths = pathlib.Path(dir).iterdir()
except PermissionError as e:
text = Text(f"PERMISSION ERROR. {e.filename}", style="red")
print(text)
return

for path in paths:
if path.is_dir():
Expand Down Expand Up @@ -77,7 +82,12 @@ def find_files_expression(dir: pathlib.Path,
ignore_hidden_dirs: bool = False) -> None:
"""Print all files of a certain type in a directory and subdirectories."""

paths = pathlib.Path(dir).iterdir()
try:
paths = pathlib.Path(dir).iterdir()
except PermissionError as e:
text = Text(f"PERMISSION ERROR. {e.filename}", style="red")
print(text)
return

for path in paths:
if path.is_dir():
Expand Down
2 changes: 1 addition & 1 deletion pu_pjr/plotting/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main():
parser.set_defaults(which="main")

parser.add_argument(
"--version", "-v", action="version", version="%(prog)s v0.14.0"
"--version", "-v", action="version", version="%(prog)s v0.15.0"
)

# Sub-parser for the "xy" command
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pu-pjr"
version = "0.14.0"
version = "0.15.0"
description = "Personal utilities for coding and data analysis"
authors = ["Pedro Juan Royo <pedro.juan.royo@gmail.com>"]
readme = "README.md"
Expand Down

0 comments on commit f8966ba

Please sign in to comment.