1
0

Fix collection names
All checks were successful
Test Python / Test (push) Successful in 26s

This commit is contained in:
Jon Michael Aanes 2024-10-08 21:38:52 +02:00
parent a476c6eac4
commit 32ad9f1476
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -26,7 +26,7 @@ CARD_FILENAME_REGEX = r'^PAR\-(\d+)\.md$'
################################################################################ ################################################################################
# Formatting # Formatting
def to_custom_field_value(custom_field: CustomField, field_def: CustomFieldInfo) -> str: def to_custom_field_value(custom_field: CustomField, field_def: CustomFieldInfo) -> 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'}:
items = [field_def.get_field_item(item_id) for item_id in value] items = [field_def.get_field_item(item_id) for item_id in value]
@ -34,17 +34,19 @@ def to_custom_field_value(custom_field: CustomField, field_def: CustomFieldInfo)
return items[0].name return items[0].name
if field_def.type in {'Color'}: if field_def.type in {'Color'}:
return custom_field.color return custom_field.color
assert False, 'Unknown type: ' + field_def.type return None
def to_custom_fields(card: Card, favro_client: FavroClient) -> dict[str,str]: def to_custom_fields(card: Card, favro_client: FavroClient) -> dict[str,str]:
custom_fields = {} custom_fields = {}
for field_assignment in card.custom_fields: for field_assignment in card.custom_fields:
field_def = favro_client.get_custom_field(field_assignment.custom_field_id) field_def = favro_client.get_custom_field(field_assignment.custom_field_id)
custom_fields[field_def.name] = to_custom_field_value(field_assignment, field_def) str_value = to_custom_field_value(field_assignment, field_def)
del field_assignment if str_value is not None:
custom_fields[field_def.name] = str_value
del field_assignment, str_value
return custom_fields return custom_fields
def to_card_contents(card: Card, favro_client: FavroClient) -> str: def to_card_contents(card: Card, favro_client: FavroClient) -> CardContents:
tags = [favro_client.get_tag(tag_id).name for tag_id in card.tags] tags = [favro_client.get_tag(tag_id).name for tag_id in card.tags]
assignments = [ assignments = [
favro_client.get_user(assignment.user).name for assignment in card.assignments favro_client.get_user(assignment.user).name for assignment in card.assignments
@ -101,7 +103,7 @@ class FileSystemItem:
class RootFileSystemItem(FileSystemItem): class RootFileSystemItem(FileSystemItem):
@staticmethod @staticmethod
def from_path_segment(segment: str) -> 'RootFileSystemItem': def from_path_segment(_segment: str) -> 'RootFileSystemItem':
return RootFileSystemItem() return RootFileSystemItem()
def __str__(self): def __str__(self):
@ -111,6 +113,9 @@ class RootFileSystemItem(FileSystemItem):
class CollectionFileSystemItem(FileSystemItem): class CollectionFileSystemItem(FileSystemItem):
collection_name: str collection_name: str
def __post_init__(self):
assert '/' not in self.collection_name
@staticmethod @staticmethod
def from_path_segment(segment: str) -> 'CollectionFileSystemItem': def from_path_segment(segment: str) -> 'CollectionFileSystemItem':
return CollectionFileSystemItem(segment) return CollectionFileSystemItem(segment)
@ -155,7 +160,6 @@ class FavroFuse(fuse.Fuse):
def getattr(self, path: str) -> FavroStat | int: def getattr(self, path: str) -> FavroStat | int:
file_system_item = path_to_file_system_item(path, self.path_components) file_system_item = path_to_file_system_item(path, self.path_components)
print(file_system_item )
st = FavroStat() st = FavroStat()
if isinstance(file_system_item, RootFileSystemItem | CollectionFileSystemItem): if isinstance(file_system_item, RootFileSystemItem | CollectionFileSystemItem):
@ -181,19 +185,18 @@ class FavroFuse(fuse.Fuse):
if isinstance(file_system_item, RootFileSystemItem): if isinstance(file_system_item, RootFileSystemItem):
for collection in self.favro_client.get_collections(): for collection in self.favro_client.get_collections():
print(collection) collection_name = collection.name.replace('/', '')
yield fuse.Direntry(str(CollectionFileSystemItem(collection.name))) yield fuse.Direntry(str(CollectionFileSystemItem(collection_name)))
del collection del collection
elif isinstance(file_system_item, CollectionFileSystemItem): elif isinstance(file_system_item, CollectionFileSystemItem):
# 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():
if collection.name == file_system_item.collection_name: if collection.name.replace('/', '') == file_system_item.collection_name:
collection_id = collection.collection_id collection_id = collection.collection_id
del collection del collection
print('Collection', collection_id)
for card in self.favro_client.get_cards(collection_id=collection_id): for card in self.favro_client.get_cards(collection_id=collection_id):
yield fuse.Direntry(str(CardFileSystemItem(card.seq_id))) yield fuse.Direntry(str(CardFileSystemItem(card.seq_id)))
del card del card