Skip to content

Commit 679c46b

Browse files
Add missing changes from #140 (#141)
* add dev printer flag; add hold to virtual prints * error checking for status; some other misc changes * remove dev printer flag * fix tests * new completion marking stuff * SILENCE * no more >>> * SLEEP_TIME * remove no_dev_printer --------- Co-authored-by: thebeninator <xccr123@gmail.com>
1 parent 7143a22 commit 679c46b

4 files changed

Lines changed: 13 additions & 37 deletions

File tree

printer/modules/gerard.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def create_print_job(
4444
printer_name,
4545
file_path,
4646
is_development_mode=False,
47-
# no_dev_printer=False
4847
):
4948
hold_time = "immediate"
5049
if is_development_mode:

printer/modules/lpstat_helpers.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
from modules import sqlite_helpers
66

7-
LPSTAT_CMD = "lpstat -o HP_LaserJet_p2015dn_Right"
8-
SLEEP_TIME = 2
97

10-
jobs_seen_last = set()
8+
LPSTAT_CMD = "lpstat -o -W completed HP_LaserJet_p2015dn_Right"
9+
POLL_LPSTAT_INTERVAL_SECONDS = 2
1110

1211
logging.basicConfig(
1312
# in mondo we trust
@@ -18,8 +17,14 @@
1817

1918

2019
def query_lpstat():
21-
global jobs_seen_last
2220
global current_jobs
21+
"""
22+
the output of this command looks like
23+
ben@ben:/app# lpstat -W completed -o HP_LaserJet_p2015dn_Right
24+
HP_LaserJet_p2015dn_Right-3 ben 5120 Mon Dec 22 21:43:54 2025
25+
HP_LaserJet_p2015dn_Right-2 ben 8192 Mon Dec 22 21:43:23 2025
26+
HP_LaserJet_p2015dn_Right-1 ben 8192 Mon Dec 22 21:41:08 2025
27+
"""
2328
p = subprocess.Popen(
2429
LPSTAT_CMD,
2530
shell=True,
@@ -52,22 +57,13 @@ def query_lpstat():
5257

5358

5459
def poll_lpstat(sqlite_file):
55-
global jobs_seen_last
5660
while True:
5761
try:
58-
current_jobs = set(query_lpstat())
59-
completed_jobs = jobs_seen_last - current_jobs
60-
62+
completed_jobs = set(query_lpstat())
6163
sqlite_helpers.mark_jobs_completed(
6264
sqlite_file, [job for job in completed_jobs]
6365
)
64-
sqlite_helpers.mark_jobs_acknowledged(
65-
sqlite_file, [job for job in current_jobs]
66-
)
67-
68-
jobs_seen_last.clear()
69-
jobs_seen_last.update(current_jobs)
7066

7167
except Exception:
7268
logging.exception("what happened to query_lpstat?")
73-
time.sleep(SLEEP_TIME)
69+
time.sleep(POLL_LPSTAT_INTERVAL_SECONDS)

printer/modules/sqlite_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def mark_jobs_with_status(sqlite_file, jobs, status):
5656
job_ids = [(job_id,) for job_id in jobs]
5757
if not job_ids:
5858
return
59-
logging.info(f"marking {job_ids} as {status} in sqlite")
59+
logging.debug(f"marking {job_ids} as {status} in sqlite")
6060

6161
sql_update = (
6262
f"UPDATE logs SET status = '{status}' WHERE job_id = ?"

printer/test/test_lpstat.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ class TestLpStatSqlite(unittest.TestCase):
2020
"HP_LaserJet_p2015dn_Right-53 root 5120 Sat May 31 18:19:38 2025"
2121
)
2222

23-
def setUp(self):
24-
lpstat_helpers.jobs_seen_last.clear()
25-
2623
# returns a single line result
2724
@mock.patch("modules.lpstat_helpers.subprocess.Popen")
2825
def test_query_lpstat(self, mock_popen):
@@ -77,9 +74,6 @@ def test_query_lpstat_nonzero(self, mock_popen):
7774
def test_poll_lpstat(
7875
self, mock_sleep, mock_query_lpstat, mock_mark_acknowledged, mock_mark_completed
7976
):
80-
# Set initial seen job
81-
lpstat_helpers.jobs_seen_last = {"HP_LaserJet_p2015dn_Right-52"}
82-
8377
# Simulate current jobs reported by lpstat
8478
mock_query_lpstat.return_value = [
8579
"HP_LaserJet_p2015dn_Right-53",
@@ -94,20 +88,7 @@ def test_poll_lpstat(
9488

9589
# Check correct jobs marked as completed and acknowledged
9690
mock_mark_completed.assert_called_once_with(
97-
"dummy.db", ["HP_LaserJet_p2015dn_Right-52"]
98-
)
99-
mock_mark_acknowledged.assert_called_once()
100-
database_name, acknowledged_jobs = mock_mark_acknowledged.call_args_list[0].args
101-
self.assertEqual(database_name, "dummy.db")
102-
self.assertCountEqual(
103-
acknowledged_jobs,
104-
["HP_LaserJet_p2015dn_Right-53", "HP_LaserJet_p2015dn_Right-54"],
105-
)
106-
107-
# Ensure state was cleared and updated
108-
self.assertEqual(
109-
lpstat_helpers.jobs_seen_last,
110-
{"HP_LaserJet_p2015dn_Right-53", "HP_LaserJet_p2015dn_Right-54"},
91+
"dummy.db", ["HP_LaserJet_p2015dn_Right-54", "HP_LaserJet_p2015dn_Right-53"],
11192
)
11293

11394

0 commit comments

Comments
 (0)