-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move filesystem data classes to separate module
- Loading branch information
Nicholas FitzRoy-Dale
committed
Oct 18, 2023
1 parent
0cce9df
commit 501f828
Showing
2 changed files
with
42 additions
and
23 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This software is released under the terms of the GNU GENERAL PUBLIC LICENSE. | ||
# See LICENSE.txt for full details. | ||
# Copyright 2023 Telemarq Ltd | ||
|
||
from dataclasses import dataclass | ||
import os | ||
import stat | ||
from typing import Optional | ||
|
||
|
||
@dataclass(frozen=True, unsafe_hash=True) | ||
class File: | ||
""" | ||
""" | ||
pathname: str | ||
mime_type: Optional[str] = None | ||
|
||
|
||
@dataclass(frozen=True, unsafe_hash=True) | ||
class DirEntry: | ||
""" | ||
Mimic os.DirEntry for the scandir() method. Stores metadata at time of instantiation rather than | ||
querying the filesystem the first time (unlike os.DirEntry). | ||
""" | ||
# Ideally we'd use os.DirEntry, but these can't be instantiated. | ||
name: str | ||
path: str | ||
stat_val: os.stat_result | ||
|
||
def is_dir(self): | ||
return stat.S_ISDIR(self.stat_val.st_mode) | ||
|
||
def is_file(self): | ||
return stat.S_ISREG(self.stat_val.st_mode) | ||
|
||
def stat(self): | ||
return self.stat_val |
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