-#!/usr/bin/env python3
"""Collecting Day and date-related items."""
from datetime import datetime
--- /dev/null
+"""plom's task manager"""
+from http.server import BaseHTTPRequestHandler
+from http.server import HTTPServer
+from urllib.parse import urlparse
+from os.path import split as path_split
+from jinja2 import Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader
+from plomtask.days import Day
+from plomtask.misc import HandledException
+
+TEMPLATES_DIR = 'templates'
+
+
+class TaskServer(HTTPServer):
+ """Variant of HTTPServer that knows .jinja as Jinja Environment."""
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(self, *args, **kwargs)
+ self.jinja = JinjaEnv(loader=JinjaFSLoader(TEMPLATES_DIR))
+
+
+class TaskHandler(BaseHTTPRequestHandler):
+ """Handles single HTTP request."""
+ server: TaskServer
+
+ def send_html(self, html: str, code: int = 200):
+ """Send HTML as proper HTTP response."""
+ self.send_response(code)
+ self.end_headers()
+ self.wfile.write(bytes(html, 'utf-8'))
+
+ def send_msg(self, msg: str, code: int = 400):
+ """Send message in HTML formatting as HTTP response."""
+ html = self.server.jinja.get_template('msg.html').render(msg=msg)
+ self.send_html(html, code)
+
+ def do_GET(self):
+ """Handle any GET request."""
+ try:
+ parsed_url = urlparse(self.path)
+ site = path_split(parsed_url.path)[1]
+ if 'calendar' == site:
+ html = self.do_GET_calendar()
+ else:
+ raise HandledException('Test!')
+ self.send_html(html)
+ except HandledException as error:
+ self.send_msg(error)
+
+ def do_GET_calendar(self):
+ """Show sorted Days."""
+ days = [Day('2024-01-03'), Day('2024-01-01'), Day('2024-01-02')]
+ days.sort()
+ return self.server.jinja.get_template('calendar.html').render(
+ days=days)
--- /dev/null
+"""
+Whatever fits nowhere else, and/or is too small/trivial
+to merit its own module at this point.
+"""
+
+
+class HandledException(Exception):
+ """To identify Exceptions based on expected (if faulty) user behavior."""
+++ /dev/null
-#!/usr/bin/env python3
-"""plom's task manager"""
-from http.server import BaseHTTPRequestHandler
-from http.server import HTTPServer
-from urllib.parse import urlparse
-from os.path import split as path_split
-from jinja2 import Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader
-from .days import Day
-
-HTTP_PORT = 8082
-TEMPLATES_DIR = 'templates'
-
-
-class HandledException(Exception):
- """To identify Exceptions based on expected (if faulty) user behavior."""
-
-
-class TaskServer(HTTPServer):
- """Variant of HTTPServer that knows .jinja as Jinja Environment."""
-
- def __init__(self, *args, **kwargs):
- super().__init__(self, *args, **kwargs)
- self.jinja = JinjaEnv(loader=JinjaFSLoader(TEMPLATES_DIR))
-
-
-class TaskHandler(BaseHTTPRequestHandler):
- """Handles single HTTP request."""
- server: TaskServer
-
- def send_html(self, html: str, code: int = 200):
- """Send HTML as proper HTTP response."""
- self.send_response(code)
- self.end_headers()
- self.wfile.write(bytes(html, 'utf-8'))
-
- def send_msg(self, msg: str, code: int = 400):
- """Send message in HTML formatting as HTTP response."""
- html = self.server.jinja.get_template('msg.html').render(msg=msg)
- self.send_html(html, code)
-
- def do_GET(self):
- """Handle any GET request."""
- try:
- parsed_url = urlparse(self.path)
- site = path_split(parsed_url.path)[1]
- if 'calendar' == site:
- html = self.do_GET_calendar()
- else:
- raise HandledException('Test!')
- self.send_html(html)
- except HandledException as error:
- self.send_msg(error)
-
- def do_GET_calendar(self):
- """Show sorted Days."""
- days = [Day('2024-01-03'), Day('2024-01-01'), Day('2024-01-02')]
- days.sort()
- return self.server.jinja.get_template('calendar.html').render(
- days=days)
-
-
-def main():
- """Main loop."""
- server = TaskServer(('localhost', HTTP_PORT), TaskHandler)
- print(f'running at port {HTTP_PORT}')
- try:
- server.serve_forever()
- except KeyboardInterrupt:
- print('aborting due to keyboard interrupt')
- server.server_close()
-
-
-if __name__ == '__main__':
- from sys import exit as sys_exit
- try:
- main()
- except HandledException as e:
- print(f'Aborting due to: {e}')
- sys_exit(1)
--- /dev/null
+#!/usr/bin/env python3
+"""Call this to start the application."""
+from sys import exit as sys_exit
+from plomtask.misc import HandledException
+from plomtask.http import TaskHandler, TaskServer
+
+HTTP_PORT = 8082
+
+
+if __name__ == '__main__':
+ try:
+ server = TaskServer(('localhost', HTTP_PORT), TaskHandler)
+ print(f'running at port {HTTP_PORT}')
+ try:
+ server.serve_forever()
+ except KeyboardInterrupt:
+ print('aborting due to keyboard interrupt')
+ server.server_close()
+ except HandledException as e:
+ print(f'Aborting due to: {e}')
+ sys_exit(1)
#!/bin/sh
set -e
-python3 -m mypy plomtask/*.py
-python3 -m flake8 plomtask/*.py
-python3 -m pylint plomtask/*.py
-python3 -m mypy tests/*.py
-python3 -m flake8 tests/*.py
-python3 -m pylint tests/*.py
+for dir in $(echo '.' 'plomtask' 'tests'); do
+ echo "Running mypy on ${dir}/ …."
+ python3 -m mypy ${dir}/*.py
+ echo "Running flake8 on ${dir}/ …"
+ python3 -m flake8 ${dir}/*.py
+ echo "Running pylint on ${dir}/ …"
+ python3 -m pylint ${dir}/*.py
+done
+echo "Running unittest on tests/."
python3 -m unittest tests/*.py
exit 0