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
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
if field_def.type in {'Single select','Multiple select'}:
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
if field_def.type in {'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]:
custom_fields = {}
for field_assignment in card.custom_fields:
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)
del field_assignment
str_value = to_custom_field_value(field_assignment, field_def)
if str_value is not None:
custom_fields[field_def.name] = str_value
del field_assignment, str_value
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]
assignments = [
favro_client.get_user(assignment.user).name for assignment in card.assignments
@ -101,7 +103,7 @@ class FileSystemItem:
class RootFileSystemItem(FileSystemItem):
@staticmethod
def from_path_segment(segment: str) -> 'RootFileSystemItem':
def from_path_segment(_segment: str) -> 'RootFileSystemItem':
return RootFileSystemItem()
def __str__(self):
@ -111,6 +113,9 @@ class RootFileSystemItem(FileSystemItem):
class CollectionFileSystemItem(FileSystemItem):
collection_name: str
def __post_init__(self):
assert '/' not in self.collection_name
@staticmethod
def from_path_segment(segment: str) -> 'CollectionFileSystemItem':
return CollectionFileSystemItem(segment)
@ -155,7 +160,6 @@ class FavroFuse(fuse.Fuse):
def getattr(self, path: str) -> FavroStat | int:
file_system_item = path_to_file_system_item(path, self.path_components)
print(file_system_item )
st = FavroStat()
if isinstance(file_system_item, RootFileSystemItem | CollectionFileSystemItem):
@ -181,19 +185,18 @@ class FavroFuse(fuse.Fuse):
if isinstance(file_system_item, RootFileSystemItem):
for collection in self.favro_client.get_collections():
print(collection)
yield fuse.Direntry(str(CollectionFileSystemItem(collection.name)))
collection_name = collection.name.replace('/', '')
yield fuse.Direntry(str(CollectionFileSystemItem(collection_name)))
del collection
elif isinstance(file_system_item, CollectionFileSystemItem):
# TODO: move into own function
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
del collection
print('Collection', collection_id)
for card in self.favro_client.get_cards(collection_id=collection_id):
yield fuse.Direntry(str(CardFileSystemItem(card.seq_id)))
del card