Skip to content

Commit

Permalink
Replace self.__directory with Path object and raise QueueDoesNotExist…
Browse files Browse the repository at this point in the history
…Error if queue does not exist
  • Loading branch information
campb303 committed Jun 17, 2021
1 parent 08748d9 commit ab40762
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/webqueue2api/parser/queue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os, re
from pathlib import Path
from .item import Item
from .config import config
from .errors import QueueDoesNotExistError



Expand All @@ -18,11 +20,17 @@ class Queue:
name: The name of the queue.
items: A list of Items in the queue.
jsonData: A JSON serializable representation of the Queue.
Raises:
QueueDoesNotExistError: If a queue's directory does not exist on the filesystem.
"""

def __init__(self, name: str) -> None:
self.name = name
self.__directory = config.queue_directory + "/" + self.name + "/"
self.__directory = Path(config.queue_directory, self.name)
if not self.__directory.exists():
raise QueueDoesNotExistError(str(self.__directory))

self.items = self.__getItems()

self.jsonData = {
Expand All @@ -39,9 +47,9 @@ def __getItems(self) -> list:
items = []

for item in os.listdir(self.__directory):
itemPath = self.__directory + "/" + item
item_path = Path(self.__directory, item)

isFile = True if os.path.isfile(itemPath) else False
isFile = True if os.path.isfile(item_path) else False

if isFile and isValidItemName(item):
items.append(Item(self.name, item))
Expand Down

0 comments on commit ab40762

Please sign in to comment.