Ruff
This commit is contained in:
parent
6201fc9c8c
commit
016a01cece
|
@ -4,11 +4,10 @@ Implements methods for interacting with the [Favro API](https://favro.com/devel
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import dataclasses
|
import dataclasses
|
||||||
from typing import Any
|
|
||||||
import requests_cache
|
|
||||||
import datetime
|
import datetime
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import requests_util
|
import requests_util
|
||||||
|
@ -112,16 +111,24 @@ class FavroClient:
|
||||||
|
|
||||||
# Setup caching
|
# Setup caching
|
||||||
requests_util.setup_limiter(
|
requests_util.setup_limiter(
|
||||||
self.session, URL_API_ROOT, datetime.timedelta(days=7),
|
self.session,
|
||||||
|
URL_API_ROOT,
|
||||||
|
datetime.timedelta(days=7),
|
||||||
)
|
)
|
||||||
requests_util.setup_limiter(
|
requests_util.setup_limiter(
|
||||||
self.session, URL_GET_CARDS, datetime.timedelta(minutes=10),
|
self.session,
|
||||||
|
URL_GET_CARDS,
|
||||||
|
datetime.timedelta(minutes=10),
|
||||||
)
|
)
|
||||||
requests_util.setup_limiter(
|
requests_util.setup_limiter(
|
||||||
self.session, URL_GET_TASKS, datetime.timedelta(minutes=10),
|
self.session,
|
||||||
|
URL_GET_TASKS,
|
||||||
|
datetime.timedelta(minutes=10),
|
||||||
)
|
)
|
||||||
requests_util.setup_limiter(
|
requests_util.setup_limiter(
|
||||||
self.session, URL_GET_CUSTOM_FIELD, datetime.timedelta(days=30),
|
self.session,
|
||||||
|
URL_GET_CUSTOM_FIELD,
|
||||||
|
datetime.timedelta(days=30),
|
||||||
)
|
)
|
||||||
|
|
||||||
def check_logged_in(self) -> None:
|
def check_logged_in(self) -> None:
|
||||||
|
@ -137,9 +144,16 @@ class FavroClient:
|
||||||
collection_id: CollectionId | None = None,
|
collection_id: CollectionId | None = None,
|
||||||
todo_list=False,
|
todo_list=False,
|
||||||
) -> Iterator[Card]:
|
) -> Iterator[Card]:
|
||||||
logger.info('Getting cards: seq_id=%s, collection_id=%s, todo_list=%s', seq_id, collection_id, todo_list)
|
logger.info(
|
||||||
|
'Getting cards: seq_id=%s, collection_id=%s, todo_list=%s',
|
||||||
|
seq_id,
|
||||||
|
collection_id,
|
||||||
|
todo_list,
|
||||||
|
)
|
||||||
request = self._get_cards_request(
|
request = self._get_cards_request(
|
||||||
seq_id=seq_id, todo_list=todo_list, collection_id=collection_id,
|
seq_id=seq_id,
|
||||||
|
todo_list=todo_list,
|
||||||
|
collection_id=collection_id,
|
||||||
)
|
)
|
||||||
for card in self._get_paginated(request, Card.from_json):
|
for card in self._get_paginated(request, Card.from_json):
|
||||||
self.card_cache.add_card(card)
|
self.card_cache.add_card(card)
|
||||||
|
@ -269,7 +283,9 @@ class FavroClient:
|
||||||
return self.update_card_contents_locally(card_id, card_contents)
|
return self.update_card_contents_locally(card_id, card_contents)
|
||||||
|
|
||||||
def _get_paginated(
|
def _get_paginated(
|
||||||
self, base_request: requests.Request, entity_from_json,
|
self,
|
||||||
|
base_request: requests.Request,
|
||||||
|
entity_from_json,
|
||||||
) -> Iterator:
|
) -> Iterator:
|
||||||
page = 0
|
page = 0
|
||||||
request_id = None
|
request_id = None
|
||||||
|
|
|
@ -164,7 +164,8 @@ class CustomFieldInfo:
|
||||||
custom_field_items: list[CustomFieldItem]
|
custom_field_items: list[CustomFieldItem]
|
||||||
|
|
||||||
def get_field_item(
|
def get_field_item(
|
||||||
self, field_item_id: CustomFieldItemId,
|
self,
|
||||||
|
field_item_id: CustomFieldItemId,
|
||||||
) -> CustomFieldItem | None:
|
) -> CustomFieldItem | None:
|
||||||
for item in self.custom_field_items:
|
for item in self.custom_field_items:
|
||||||
if item.custom_field_item_id == field_item_id:
|
if item.custom_field_item_id == field_item_id:
|
||||||
|
|
|
@ -34,7 +34,8 @@ CARD_FILENAME_REGEX = r'^PAR\-(\d+)\.md$'
|
||||||
|
|
||||||
|
|
||||||
def to_custom_field_value(
|
def to_custom_field_value(
|
||||||
custom_field: CustomField, field_def: CustomFieldInfo,
|
custom_field: CustomField,
|
||||||
|
field_def: CustomFieldInfo,
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
value: CustomFieldItemId | list[CustomFieldItemId] = custom_field.value
|
value: CustomFieldItemId | list[CustomFieldItemId] = custom_field.value
|
||||||
if field_def.type in {'Single select', 'Multiple select'}:
|
if field_def.type in {'Single select', 'Multiple select'}:
|
||||||
|
@ -154,12 +155,14 @@ class CardFileSystemItem(FileSystemItem):
|
||||||
|
|
||||||
|
|
||||||
def path_to_file_system_item(
|
def path_to_file_system_item(
|
||||||
path_str: str, path_components: list[type[FileSystemItem]],
|
path_str: str,
|
||||||
|
path_components: list[type[FileSystemItem]],
|
||||||
) -> FileSystemItem | None:
|
) -> FileSystemItem | None:
|
||||||
path = re.findall(r'[^/]+', path_str)
|
path = re.findall(r'[^/]+', path_str)
|
||||||
component = path_components[len(path)]
|
component = path_components[len(path)]
|
||||||
return component.from_path_segment(path[-1] if path else None)
|
return component.from_path_segment(path[-1] if path else None)
|
||||||
|
|
||||||
|
|
||||||
FAST_GETATTR = True
|
FAST_GETATTR = True
|
||||||
|
|
||||||
|
|
||||||
|
@ -233,7 +236,7 @@ class FavroFuse(fuse.Fuse):
|
||||||
|
|
||||||
elif isinstance(file_system_item, CollectionFileSystemItem):
|
elif isinstance(file_system_item, CollectionFileSystemItem):
|
||||||
if not self._is_allowed_collection(file_system_item):
|
if not self._is_allowed_collection(file_system_item):
|
||||||
return # Yield nothing
|
return # Yield nothing
|
||||||
|
|
||||||
# TODO: move into own function
|
# TODO: move into own function
|
||||||
for collection in self.favro_client.get_collections():
|
for collection in self.favro_client.get_collections():
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
import frontmatter
|
import frontmatter
|
||||||
import marko
|
import marko
|
||||||
|
|
Loading…
Reference in New Issue
Block a user