Compare commits
2 Commits
2c8a65f959
...
a1f4a8207e
Author | SHA1 | Date | |
---|---|---|---|
a1f4a8207e | |||
7a42938523 |
|
@ -29,7 +29,7 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
client.check_logged_in()
|
client.check_logged_in()
|
||||||
start_favro_fuse(client)
|
start_favro_fuse(client, secrets.favro_collection_filter())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -215,7 +215,7 @@ class FavroClient:
|
||||||
def _invalidate_cache(self, card_id: CardId) -> None:
|
def _invalidate_cache(self, card_id: CardId) -> None:
|
||||||
card = self.card_cache.remove(card_id)
|
card = self.card_cache.remove(card_id)
|
||||||
if card:
|
if card:
|
||||||
self.session.card_cache.delete(
|
self.session.cache.delete(
|
||||||
requests=[self._get_cards_prepared_request(seq_id=card.seq_id)],
|
requests=[self._get_cards_prepared_request(seq_id=card.seq_id)],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -168,13 +168,16 @@ class FavroFuse(fuse.Fuse):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
*,
|
||||||
favro_client: FavroClient,
|
favro_client: FavroClient,
|
||||||
formatter: CardFileFormatter,
|
formatter: CardFileFormatter,
|
||||||
|
collection_filter: frozenset[str],
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
self.favro_client = favro_client
|
self.favro_client = favro_client
|
||||||
self.formatter = formatter
|
self.formatter = formatter
|
||||||
self.wiped_cards = set()
|
self.wiped_cards = set()
|
||||||
|
self.collection_filter = collection_filter
|
||||||
self.path_components = [
|
self.path_components = [
|
||||||
RootFileSystemItem,
|
RootFileSystemItem,
|
||||||
CollectionFileSystemItem,
|
CollectionFileSystemItem,
|
||||||
|
@ -209,6 +212,11 @@ class FavroFuse(fuse.Fuse):
|
||||||
return -errno.ENOENT
|
return -errno.ENOENT
|
||||||
return st
|
return st
|
||||||
|
|
||||||
|
def _is_allowed_collection(self, item: CollectionFileSystemItem) -> bool:
|
||||||
|
if self.collection_filter is None:
|
||||||
|
return True
|
||||||
|
return item.collection_name in self.collection_filter
|
||||||
|
|
||||||
def readdir(self, path: str, offset: int) -> Iterator[fuse.Direntry]:
|
def readdir(self, path: str, offset: int) -> Iterator[fuse.Direntry]:
|
||||||
logger.info('Reading directory: %s', path)
|
logger.info('Reading directory: %s', path)
|
||||||
file_system_item = path_to_file_system_item(path, self.path_components)
|
file_system_item = path_to_file_system_item(path, self.path_components)
|
||||||
|
@ -218,11 +226,15 @@ 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():
|
||||||
collection_name = collection.name.replace('/', '')
|
item = CollectionFileSystemItem(collection.name.replace('/', ''))
|
||||||
yield fuse.Direntry(str(CollectionFileSystemItem(collection_name)))
|
if self._is_allowed_collection(item):
|
||||||
del collection
|
yield fuse.Direntry(str(item))
|
||||||
|
del collection, item
|
||||||
|
|
||||||
elif isinstance(file_system_item, CollectionFileSystemItem):
|
elif isinstance(file_system_item, CollectionFileSystemItem):
|
||||||
|
if not self._is_allowed_collection(file_system_item):
|
||||||
|
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():
|
||||||
if collection.name.replace('/', '') == file_system_item.collection_name:
|
if collection.name.replace('/', '') == file_system_item.collection_name:
|
||||||
|
@ -337,12 +349,12 @@ Userspace hello example
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def start_favro_fuse(favro_client: FavroClient):
|
def start_favro_fuse(favro_client: FavroClient, collection_filter: frozenset[str]):
|
||||||
logger.info('Starting favro FUSE')
|
logger.info('Starting favro FUSE with collection filter: %s', collection_filter)
|
||||||
# TODO:
|
|
||||||
server = FavroFuse(
|
server = FavroFuse(
|
||||||
favro_client=favro_client,
|
favro_client=favro_client,
|
||||||
formatter=CardFileFormatter(),
|
formatter=CardFileFormatter(),
|
||||||
|
collection_filter=collection_filter,
|
||||||
version='%prog ' + fuse.__version__,
|
version='%prog ' + fuse.__version__,
|
||||||
usage=HELP,
|
usage=HELP,
|
||||||
dash_s_do='setsingle',
|
dash_s_do='setsingle',
|
||||||
|
|
|
@ -17,3 +17,13 @@ def favro_username():
|
||||||
|
|
||||||
def favro_password():
|
def favro_password():
|
||||||
return secrets.load_or_fail('FAVRO_PASSWORD')
|
return secrets.load_or_fail('FAVRO_PASSWORD')
|
||||||
|
|
||||||
|
|
||||||
|
def favro_collection_filter() -> frozenset[str]:
|
||||||
|
loaded = secrets.load('FAVRO_COLLECTION_FILTER')
|
||||||
|
if loaded is None:
|
||||||
|
return None
|
||||||
|
values = loaded.strip().split('\n')
|
||||||
|
values = [v.strip() for v in values]
|
||||||
|
values = [v for v in values if v]
|
||||||
|
return frozenset(values)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user