Skip to content

Update package structure #27

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7668e1c
update ecnqueue from the front end repository
benne238 Apr 1, 2021
647cc79
creation of basic directory schema with proper __init__.py scripts in…
benne238 Apr 1, 2021
29b2fa3
absolute import statements in the __init__ files for the backend
benne238 Apr 2, 2021
18c2742
removed ECNQueue.py from the repo
benne238 Apr 2, 2021
e7e648d
modified __init__.py import statement in the ECNQueue subpackage
benne238 Apr 2, 2021
5cd589f
created Item.py with the Item class in the ECNQueue sub package
benne238 Apr 2, 2021
f97082c
create Queue module with the Queue class in the ECNQueue subpackage
benne238 Apr 2, 2021
d4662b3
creation of the __init__.py for the parser subpackage of the ECNQueue…
benne238 Apr 2, 2021
c70cb00
creation of the parser.py in the parser subpackage
benne238 Apr 2, 2021
66b337c
creation of the utils.py module in the ECNQueue subpackage
benne238 Apr 2, 2021
d3f1c6a
fixed broken import in api.py
benne238 Apr 2, 2021
36695c8
added logger subpackage to webqueue2-api package
benne238 Apr 5, 2021
ba6b0b0
changed relative import statements for the ENCQueue subpackage
benne238 Apr 5, 2021
5012826
added logging to the ECNQueue __init__ module
benne238 Apr 5, 2021
cb85b06
modified relative import statments in the parser submodule of ECNQueue
benne238 Apr 5, 2021
a5d04e1
removal of Path import from the logger __init__.py
benne238 Apr 12, 2021
228ee1e
fixed broken file paths in parser
benne238 Apr 12, 2021
db88fd4
modified parsing argument in Item
benne238 Apr 12, 2021
60cced2
fixed init import statement in parser
benne238 Apr 13, 2021
05d46a2
fixed __init__ import in utils within ECNQueue
benne238 Apr 13, 2021
8884130
fixed __init__ import in Queue within ECNQueue
benne238 Apr 13, 2021
5349118
fixed __init__ import in item within ECNQueue
benne238 Apr 13, 2021
c0fa057
fixed __init__ import in ECNQueue within ECNQueue
benne238 Apr 13, 2021
fae1303
breakup of the api script in the backend into different modules and s…
benne238 Apr 13, 2021
873d53c
added/modified logging in api __init__ to account for bad inputs from…
benne238 Apr 13, 2021
71512f9
modified logging statements in api, ECNQueue, and logger __init__ files
benne238 Apr 13, 2021
2ad404f
added logging to __main__ script in api
benne238 Apr 13, 2021
cd8e0ba
added logging for the item resource in the api resource subpackage
benne238 Apr 13, 2021
eac9b10
added logging to login script in the resources subpackage of the api
benne238 Apr 13, 2021
64b214f
modified resource.login logging statements
benne238 Apr 13, 2021
2e57630
added logging to queue_list module in resources
benne238 Apr 13, 2021
3aaeba4
modified item resource logging in the api
benne238 Apr 13, 2021
00d32ab
added logging to queue resource in the api sub package
benne238 Apr 13, 2021
ae47914
moved logger logger.name declaration to the inside of the class decla…
benne238 Apr 13, 2021
cf04289
added logging to refresh_access_token module in resources
benne238 Apr 14, 2021
9c088c1
edited refresh_access token log messages
benne238 Apr 14, 2021
911f41f
make main script as a part of the webqueue2_api parent package instea…
benne238 Apr 14, 2021
5cb4393
implemented argparse when calling the webqueue2_api package
benne238 Apr 14, 2021
ae77904
added fix for running api with wrapper script
benne238 Apr 14, 2021
5e57b2e
Inititial version of a functioning(ish) api with gunicorn
benne238 Apr 20, 2021
5bf968d
gunicorn working with command line arguments
benne238 Apr 22, 2021
45e37bf
Readability and functionality update
benne238 Apr 29, 2021
61eb186
Tree functionality added to a new utils subpackage in the webqueue2_a…
benne238 May 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,374 changes: 0 additions & 1,374 deletions webqueue2_api/ECNQueue.py

This file was deleted.

72 changes: 72 additions & 0 deletions webqueue2_api/ECNQueue/Item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from . import queue_directory, queues_to_ignore
from .parser import parser
import os
queueDirectory = queue_directory

class Item:
"""A chronological representation of an interaction with a user.
Example:
# Create an Item (ce100)
>>> item = Item("ce", 100, headersOnly=false)
# Create an Item without parsing its contents (ce100)
>>> item = Item("ce", 100, headersOnly=True)
Args:
queue (str): The name of the Item's queue.
number (int): The number of the Item.
headersOnly (bool, optional): Whether or not to parse headers only. Defaults to True.
Attributes:
lastUpdated: An ISO 8601 formatted time string showing the last time the file was updated according to the filesystem.
headers: A list of dictionaries containing header keys and values.
content: A list of section dictionaries (only included if headersOnly is False).
isLocked: A boolean showing whether or not a lockfile for the item is present.
userEmail: The email address of the person who this item is from.
userName: The real name of the person who this item is from.
userAlias: The Purdue career account alias of the person this item is from.
assignedTo: The Purdue career account alias of the person this item is assigned to
subject: The subject of the original message for this item.
status: The most recent status update for the item.
priority: The most recent priority for this item.
department: The most recent department for this item.
dateReceived: The date this item was created.
jsonData: A JSON serializable representation of the Item.
Raises:
ValueError: When the number passed to the constructor cannot be parsed.
"""

def __init__(self, queue: str, number: int, headersOnly: bool = False) -> None:
self.queue = queue
try:
self.number = int(number)
except ValueError:
raise ValueError(f'Could not convert "{number}" to an integer')
self.__path = "/".join([queueDirectory, self.queue, str(self.number)])
self.lastUpdated = parser.getLastUpdated(self.__path)
self.__rawItem = parser.getRawItem(self.__path)
self.headers = parser.parseHeaders(self.__rawItem)
if not headersOnly: self.content = parser.parseSections(self.headers, self.__rawItem, self.__path)
self.isLocked = parser.isLocked(self.__path, self.queue, self.number)
self.userEmail = parser.parseFromData(self.headers, data="userEmail")
self.userName = parser.parseFromData(self.headers, data="userName")
self.userAlias = parser.getUserAlias(self.headers, self.userEmail)
self.assignedTo = parser.getMostRecentHeaderByType(self.headers, "Assigned-To")
self.subject = parser.getMostRecentHeaderByType(self.headers, "Subject")
self.status = parser.getMostRecentHeaderByType(self.headers, "Status")
self.priority = parser.getMostRecentHeaderByType(self.headers, "Priority")
self.department = parser.getMostRecentHeaderByType(self.headers, "Department")
self.building = parser.getMostRecentHeaderByType(self.headers, "Building")
self.dateReceived = parser.getFormattedDate(parser.getMostRecentHeaderByType(self.headers, "Date"))
self.jsonData = {}

for attribute in self.__dir__():
if "_" not in attribute and attribute != "toJson" and attribute != "jsonData":
self.jsonData[attribute] = self.__getattribute__(attribute)

def toJson(self) -> dict:
"""Returns a JSON safe representation of the item.
Returns:
dict: JSON safe representation of the item.
"""
return self.jsonData

def __repr__(self) -> str:
return self.queue + str(self.number)
61 changes: 61 additions & 0 deletions webqueue2_api/ECNQueue/Queue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from . import utils, Item
from .parser import parser
from . import queue_directory
from os import listdir, path

queueDirectory = queue_directory

class Queue:
"""A collection of Items.
Example:
# Create a queue (ce)
>>> queue = Queue("ce")
# Create a queue without parsing item contents (ce)
>>> queue = Queue("ce", headersOnly=False)
Args:
queue (str): The name of the queue.
headersOnly (bool, optional): Whether or not to parse headers only. Defaults to True.
Attributes:
name: The name of the queue.
items: A list of Items in the queue.
jsonData: A JSON serializable representation of the Queue.
"""

def __init__(self, name: str, headersOnly: bool = True) -> None:
self.name = name
self.headersOnly = headersOnly
self.__directory = queueDirectory + "/" + self.name + "/"
self.items = parser.getItems(self.name, self.headersOnly)
self._index = 0

self.jsonData = {
"name": self.name,
"length": len(self)
}

def toJson(self) -> dict:
"""Return JSON safe representation of the Queue
The JSON representation of every item in the Queue is added to the
Queue's JSON data then the Queue's JSON data is returned.
Returns:
dict: JSON safe representation of the Queue
"""
items = []
for item in self.items:
items.append(item.toJson())
self.jsonData["items"] = items

return self.jsonData

def __len__(self) -> int:
return len(self.items)

def __repr__(self) -> str:
return f'{self.name}_queue'

# Implements the interable interface requirements by passing direct references
# to the item list's interable values.
def __iter__(self) -> list:
return iter(self.items)
def __next__(self) -> int:
return iter(self.items).__next__()
18 changes: 18 additions & 0 deletions webqueue2_api/ECNQueue/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import configparser
from ..logger import logger
from .. import global_configs

queue_directory = "/home/pier/e/queue/Mail"
queues_to_ignore = ["archives", "drafts", "inbox", "coral"]

logger.name = __name__

def applyQueueDirectory(dir: str) -> None:
global queue_directory
queue_directory = dir
return

def applyQueuesToIgnore(ignore: list) -> None:
global queues_to_ignore
queues_to_ignore = ignore
return
1 change: 1 addition & 0 deletions webqueue2_api/ECNQueue/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import parser
Loading