Skip to content

Commit

Permalink
refactor for OCD
Browse files Browse the repository at this point in the history
  • Loading branch information
maniac-en committed Jul 28, 2024
1 parent 3acf2aa commit f670777
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
- Multiline markdown blocks should be separated by newlines:<br><br>
```
- Headings (1-6)
- Paragraphs
- Paragraphs
- Quoteblocks
- Codeblocks
- Codeblocks
- Ordered Lists
- Unordered Lists
```
Expand Down
16 changes: 8 additions & 8 deletions src/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __init__(self, *args, directory=None, **kwargs):
def create_handler(
root_path: str,
public_dir: str,
build_handler: Callable[[], None],
build_site_handler: Callable[[], None],
tracked_files: List[str],
tracked_filestamps: Dict[str, float],
) -> type[MyHttpRequestHandler]:
Expand All @@ -147,7 +147,7 @@ def create_handler(
Args:
- root_path (str): The root directory path to monitor.
- public_dir (str): The directory from which to serve public files.
- build_handler (Callable[[], None]): The handler function to execute on build.
- build_site_handler (Callable[[], None]): The handler function to execute on build.
- tracked_files (List[str]): The files the server is tracking for changes
- tracked_filestamps (Dict[str, float]): The last modified timestamps for
the files being tracked
Expand All @@ -171,7 +171,7 @@ def __init__(self, *args, **kwargs):
"""
self.root_path = root_path
self.public_dir = public_dir
self.build_handler = build_handler
self.build_site_handler = build_site_handler
super().__init__(*args, directory=self.public_dir, **kwargs)

def log_message(self, format, *args):
Expand Down Expand Up @@ -202,7 +202,7 @@ def do_GET(self):
self.__class__.tracked_files, self.__class__.tracked_filestamps = (
get_updated_tracked_lists(self.root_path)
)
self.build_handler()
self.build_site_handler()
self.send_response(200)
self.end_headers()
self.wfile.write(b"update")
Expand Down Expand Up @@ -237,28 +237,28 @@ def shutdown(self):
return CustomHandler


def run(root_path: str, public_dir: str, build_handler: Callable[[], None]):
def run(root_path: str, public_dir: str, build_site_handler: Callable[[], None]):
"""
Runs the HTTP server with the custom request handler.
Args:
- root_path (str): The root directory path to monitor.
- public_dir (str): The directory from which to serve public files.
- build_handler (Callable[[], None]): The handler function to execute for build.
- build_site_handler (Callable[[], None]): The handler function to execute for build.
"""
global HOSTNAME, PORT, tracked_files, tracked_filestamps

# Initialize tracked files and timestamps
tracked_files, tracked_filestamps = get_updated_tracked_lists(root_path)

# Execute the build handler function
build_handler()
build_site_handler()

# Create TCP server with custom handler
TCPHandler = create_handler(
root_path=root_path,
public_dir=public_dir,
build_handler=build_handler,
build_site_handler=build_site_handler,
tracked_files=tracked_files,
tracked_filestamps=tracked_filestamps,
)
Expand Down
8 changes: 6 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
CONTENT_DIR = os.path.join(ROOT_PATH, "content")
TEMPLATE_PATH = os.path.join(ROOT_PATH, "template.html")

build_handler = build_site(
build_site_handler = build_site(
static_dir=STATIC_DIR,
content_dir=CONTENT_DIR,
template_path=TEMPLATE_PATH,
dest_path=PUBLIC_DIR,
)

if __name__ == "__main__":
run(root_path=ROOT_PATH, public_dir=PUBLIC_DIR, build_handler=build_handler)
run(
root_path=ROOT_PATH,
public_dir=PUBLIC_DIR,
build_site_handler=build_site_handler,
)

0 comments on commit f670777

Please sign in to comment.