Skip to content

Commit

Permalink
chore(CI): fix CI workflows (AlertaDengue#214)
Browse files Browse the repository at this point in the history
* fix(CI): fix CI workflows

* run pre-commit

* include pre-commit before testing

* include pre-commit before commiting

* linting pt.1

* linting pt.2

* replace mocked tests by endpoint tests

* remove compose-go

* linting pt.3 final
  • Loading branch information
luabida authored and felipeadeildo committed Nov 27, 2024
1 parent e1c86c9 commit aff7724
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions pysus/ftp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
import humanize
from aioftp import Client
from loguru import logger
from pysus.data.local import Data
from tqdm import tqdm
from typing_extensions import Self

from pysus.data.local import Data

# Type aliases
PathLike = Union[str, pathlib.Path]
FileContent = Dict[str, Union["Directory", "File"]]
Expand Down Expand Up @@ -339,6 +338,13 @@ def load(self) -> Self:
self.loaded = True
return self

def reload(self):
"""
Reloads the content of the Directory
"""
self.loaded = False
return self.load()

def __str__(self) -> str:
return self.path

Expand Down Expand Up @@ -366,14 +372,22 @@ def load_directory_content(path: str) -> FileContent:
def line_parser(line: str):
if "<DIR>" in line:
date, time, _, name = line.strip().split(maxsplit=3)
modify = datetime.strptime(f"{date} {time}", "%m-%d-%y %I:%M%p")
modify = datetime.strptime(
f"{date} {time}", "%m-%d-%y %I:%M%p"
)
info = {"size": 0, "type": "dir", "modify": modify}
xpath = f"{path}/{name}"
content[name] = Directory(xpath)
else:
date, time, size, name = line.strip().split(maxsplit=3)
modify = datetime.strptime(f"{date} {time}", "%m-%d-%y %I:%M%p")
info: FileInfo = {"size": size, "type": "file", "modify": modify}
modify = datetime.strptime(
f"{date} {time}", "%m-%d-%y %I:%M%p"
)
info: FileInfo = {
"size": size,
"type": "file",
"modify": modify,
}
content[name] = File(path, name, info)

ftp.retrlines("LIST", line_parser)
Expand Down Expand Up @@ -440,7 +454,9 @@ def content(self) -> List[Union[Directory, File]]:
inside content, `load()` the directory and call `content` again.
"""
if not self.__content__:
logger.info("content is not loaded, use `load()` to load default paths")
logger.info(
"content is not loaded, use `load()` to load default paths"
)
return []
return sorted(list(self.__content__.values()), key=str)

Expand Down Expand Up @@ -505,7 +521,9 @@ def get_files(self, *args, **kwargs) -> list[File]:
"""
...

def download(self, files: List[File], local_dir: str = CACHEPATH) -> List[str]:
def download(
self, files: List[File], local_dir: str = CACHEPATH
) -> List[str]:
"""
Downloads a list of Files.
"""
Expand All @@ -520,7 +538,9 @@ def download(self, files: List[File], local_dir: str = CACHEPATH) -> List[str]:
return dfiles[0]
return dfiles

async def async_download(self, files: List[File], local_dir: str = CACHEPATH):
async def async_download(
self, files: List[File], local_dir: str = CACHEPATH
):
"""
Asynchronously downloads a list of files
"""
Expand Down

0 comments on commit aff7724

Please sign in to comment.