Skip to content

Commit

Permalink
Add headers only loading to Queue
Browse files Browse the repository at this point in the history
  • Loading branch information
campb303 committed Jun 21, 2021
1 parent 48318ac commit 51bddfa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/webqueue2api/parser/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@ class Queue:
QueueDoesNotExistError: If a queue's directory does not exist on the filesystem.
"""

def __init__(self, name: str) -> None:
def __init__(self, name: str, headers_only: bool = True) -> None:
self.name = name
self.path = Path(config.queue_directory, self.name)
if not self.path.exists():
raise QueueDoesNotExistError(str(self.path))

self.items = self.get_items()
self.items = self.get_items(headers_only=headers_only)

self.json_data = {
"name": self.name,
}

def get_items(self) -> list:
def get_items(self, headers_only: bool) -> list:
"""Returns a list of items for this Queue
Args:
headers_only (bool): If True, loads Item headers.
Returns:
list: a list of items for this Queue
"""
Expand All @@ -52,7 +55,7 @@ def get_items(self) -> list:
is_file = True if os.path.isfile(item_path) else False

if is_file and is_valid_item_name(item):
items.append(Item(self.name, item))
items.append(Item(self.name, item, headers_only))

return items

Expand Down Expand Up @@ -92,6 +95,7 @@ def is_valid_item_name(name: str) -> bool:
Args:
name (str): The name to test.
headers_only (bool, optional): Whether or not to parse headers only. Defaults to True.
Returns:
bool: Name is valid item name.
Expand Down

0 comments on commit 51bddfa

Please sign in to comment.