-
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.
(Start to) refactor zipped filesystems
- Loading branch information
Nicholas FitzRoy-Dale
committed
Jun 22, 2024
1 parent
bbd9993
commit c97743e
Showing
3 changed files
with
42 additions
and
52 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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from zipfile import ZipFile, Path | ||
|
||
def get_zipfile_main_dir(zf: ZipFile) -> Path: | ||
""" | ||
Zipped filesystem support assumes that there is one directory in the .zip file | ||
and all the other files and directories are located withn that directory. | ||
file.zip | ||
|- main_dir | ||
|- _rime_settings.db | ||
|- sdcard | ||
|- ... | ||
|- data | ||
|- ... | ||
""" | ||
path = Path(zf) | ||
for element in path.iterdir(): | ||
if element.is_dir(): | ||
return element | ||
|
||
raise ValueError("The zipfile does not contain a single directory.") |