Skip to content

Commit

Permalink
Merge pull request #1040 from sbrunner/status
Browse files Browse the repository at this point in the history
Add global status and generated date
  • Loading branch information
sbrunner authored Jun 6, 2023
2 parents 1db9544 + 9d6b944 commit d8778fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion scan_to_paperless/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,7 @@ def main() -> None:
for config_file_name in glob.glob(
os.path.join(os.environ.get("SCAN_SOURCE_FOLDER", "/source"), "*/config.yaml")
):
status.set_global_status(f"Processing '{os.path.basename(os.path.dirname(config_file_name))}'...")
dirty, print_waiting = _process(config_file_name, status, dirty, print_waiting)
if not dirty:
process_code()
Expand All @@ -1803,7 +1804,7 @@ def main() -> None:
if not dirty:
if print_waiting:
print_waiting = False
print("Waiting...")
status.set_global_status("Waiting...")
time.sleep(30)


Expand Down
16 changes: 15 additions & 1 deletion scan_to_paperless/status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Manage the status file of the progress."""

import datetime
import glob
import os.path
from typing import Dict, NamedTuple
Expand All @@ -19,6 +20,13 @@ def __init__(self, no_write: bool = False) -> None:
self.no_write = no_write
self._file = os.path.join(os.environ.get("SCAN_SOURCE_FOLDER", "status.html"))
self._status: Dict[str, _Folder] = {}
self._global_status = "Starting..."

def set_global_status(self, status: str) -> None:
"""Set the global status."""

self._global_status = status
self.update()

def set_status(self, name: str, status: str, details: str = "") -> None:
"""Set the status of a folder."""
Expand Down Expand Up @@ -60,7 +68,7 @@ def write(self) -> None:

with open(self._file, "w", encoding="utf-8") as status_file:
status_file.write(
"""<!doctype html>
f"""<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -90,6 +98,12 @@ def write(self) -> None:
/>
</head>
<body>
<h1>Scan to Paperless status</h1>
<p>{self._global_status}</p>
<p>Generated at: <script>
window.document.write(new Date('{datetime.datetime.utcnow().replace(microsecond=0).isoformat()}Z').toLocaleString());
</script></p>
<h2>Jobs</h2>
<table data-toggle="table">
<thead>
<tr>
Expand Down

0 comments on commit d8778fb

Please sign in to comment.