mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Add and use utility functions for changing paths
This fixes a small bug in the example config, where some files were put in the wrong locations.
This commit is contained in:
@ -3,6 +3,8 @@ import pathlib
|
||||
|
||||
__all__ = [
|
||||
"get_base_dir",
|
||||
"move",
|
||||
"rename",
|
||||
"stream_to_path",
|
||||
"OutOfTriesException",
|
||||
"UnknownFileTypeException",
|
||||
@ -12,6 +14,14 @@ __all__ = [
|
||||
def get_base_dir(script_file):
|
||||
return pathlib.Path(os.path.dirname(os.path.abspath(script_file)))
|
||||
|
||||
def move(path, from_folders, to_folders):
|
||||
l = len(from_folders)
|
||||
if path.parts[:l] == from_folders:
|
||||
return pathlib.PurePath(*to_folders, *path.parts[l:])
|
||||
|
||||
def rename(path, to_name):
|
||||
return pathlib.PurePath(*path.parts[:-1], to_name)
|
||||
|
||||
async def stream_to_path(resp, to_path, chunk_size=1024**2):
|
||||
with open(to_path, 'wb') as fd:
|
||||
while True:
|
||||
|
Reference in New Issue
Block a user