-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from tr0yspradling/master
Enhancements: cleaned up unused code, fixed linter warnings, using custom PathEntry instead of os.DirEntry…
- Loading branch information
Showing
6 changed files
with
147 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,6 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Idea configurations | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
T = TypeVar('T') | ||
|
||
|
||
class IconSet(Generic[T]): | ||
""" | ||
A storage for icons. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import os | ||
import stat | ||
|
||
|
||
class PathEntry: | ||
""" | ||
PathEntry is a utility class that represents a filesystem entry at a given path. The entry can represent a file, | ||
directory, or symbolic link. The class provides methods for checking the type of the entry and obtaining file | ||
statistics for it. | ||
The class can be used to mirror the behavior of PathEntry, because PathEntry objects returned by os.scandir() | ||
do not handle individual file paths and do not allow selective control over following symbolic links for | ||
different operations. | ||
""" | ||
|
||
def __init__(self, path: str) -> None: | ||
""" | ||
Initialize a new instance of the PathEntry class. | ||
:param path: A string containing a path to a file or directory. | ||
:type path: str | ||
""" | ||
self.path = path | ||
self.name = os.path.basename(path) | ||
|
||
def is_dir(self, follow_symlinks: bool = True) -> bool: | ||
""" | ||
Check if the path represents a directory. | ||
:param follow_symlinks: If True (default), symlinks are followed (i.e., if the path points to a directory | ||
through a symlink, it will return True). If False, symlinks are not followed (i.e., | ||
if the path points to a directory through a symlink, it will return False). | ||
:type follow_symlinks: bool | ||
:return: True if the path represents a directory, False otherwise. | ||
:rtype: bool | ||
""" | ||
if follow_symlinks: | ||
return os.path.isdir(self.path) | ||
else: | ||
return stat.S_ISDIR(self.stat(follow_symlinks=follow_symlinks).st_mode) | ||
|
||
def is_file(self, follow_symlinks: bool = True) -> bool: | ||
""" | ||
Check if the path represents a file. | ||
:param follow_symlinks: If True (default), symlinks are followed (i.e., if the path points to a file through a | ||
symlink, it will return True). If False, symlinks are not followed (i.e., if the path | ||
points to a file through a symlink, it will return False). | ||
:type follow_symlinks: bool | ||
:return: True if the path represents a file, False otherwise. | ||
:rtype: bool | ||
""" | ||
if follow_symlinks: | ||
return os.path.isfile(self.path) | ||
else: | ||
return stat.S_ISREG(self.stat(follow_symlinks=follow_symlinks).st_mode) | ||
|
||
def is_symlink(self) -> bool: | ||
""" | ||
Check if the path represents a symbolic link. | ||
:return: True if the path represents a symbolic link, False otherwise. | ||
:rtype: bool | ||
""" | ||
return os.path.islink(self.path) | ||
|
||
def stat(self, follow_symlinks: bool = True) -> os.stat_result: | ||
""" | ||
Perform a stat system call on the given path. | ||
:param follow_symlinks: If True (default), symlinks are followed, similar to os.stat(). If False, symlinks are | ||
not followed, similar to os.lstat(). | ||
:type follow_symlinks: bool | ||
:return: The result of the stat or lstat call on the path. | ||
:rtype: os.stat_result | ||
""" | ||
if follow_symlinks: | ||
return os.stat(self.path) | ||
else: | ||
return os.lstat(self.path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters