Преглед на файлове

Switch action modules from print() to logger

local_sync, local_refresh, and _scripts were using print() for progress
output, which is invisible when called from periodic tasks or background
threads. Summary lines → INFO, per-item detail lines → DEBUG.
_cli.py and store/__main__.py (intentional terminal output) left as-is.
ZiB преди 4 месеца
родител
ревизия
8511a99640
променени са 3 файла, в които са добавени 22 реда и са изтрити 17 реда
  1. 13 10
      room_cal/actions/local_refresh.py
  2. 8 5
      room_cal/actions/local_sync.py
  3. 1 2
      room_cal/service_api/_scripts.py

+ 13 - 10
room_cal/actions/local_refresh.py

@@ -1,6 +1,9 @@
+import logging
 from datetime import date
 from datetime import date
 
 
 from room_cal.pricing import CalPrice
 from room_cal.pricing import CalPrice
+
+_log = logging.getLogger(__name__)
 from room_cal.closed import Closed, ClosedData
 from room_cal.closed import Closed, ClosedData
 from room_cal.discount import Discount, DiscountData, DiscountType
 from room_cal.discount import Discount, DiscountData, DiscountType
 from room_cal.reservations import Reservation
 from room_cal.reservations import Reservation
@@ -22,9 +25,9 @@ async def refresh_prices(start: date, end: date) -> None:
     if base is None:
     if base is None:
       continue
       continue
     await cal.set(d, base, existing=e, discount_rec=discount_by_date.get(d))
     await cal.set(d, base, existing=e, discount_rec=discount_by_date.get(d))
-    print(f"  price {d}: ${base}")
+    _log.debug("price %s: $%s", d, base)
     found += 1
     found += 1
-  print(f"  {found} price event(s) refreshed")
+  _log.info("%d price event(s) refreshed", found)
 
 
 
 
 async def refresh_closed(start: date, end: date) -> None:
 async def refresh_closed(start: date, end: date) -> None:
@@ -43,9 +46,9 @@ async def refresh_closed(start: date, end: date) -> None:
     if not services:
     if not services:
       continue
       continue
     await closed.set(d, ClosedData(services=services, source=source), existing=e)
     await closed.set(d, ClosedData(services=services, source=source), existing=e)
-    print(f"  closed {d}: {', '.join(services)}")
+    _log.debug("closed %s: %s", d, ', '.join(services))
     found += 1
     found += 1
-  print(f"  {found} closed event(s) refreshed")
+  _log.info("%d closed event(s) refreshed", found)
 
 
 
 
 async def refresh_discounts(start: date, end: date) -> None:
 async def refresh_discounts(start: date, end: date) -> None:
@@ -65,9 +68,9 @@ async def refresh_discounts(start: date, end: date) -> None:
     if dtype is None or value is None:
     if dtype is None or value is None:
       continue
       continue
     await discount.set(d, DiscountData(type=DiscountType(dtype), value=value, source=source), existing=e)
     await discount.set(d, DiscountData(type=DiscountType(dtype), value=value, source=source), existing=e)
-    print(f"  discount {d}: {dtype} {value}")
+    _log.debug("discount %s: %s %s", d, dtype, value)
     found += 1
     found += 1
-  print(f"  {found} discount event(s) refreshed")
+  _log.info("%d discount event(s) refreshed", found)
 
 
 
 
 async def refresh_reservations(start: date, end: date) -> None:
 async def refresh_reservations(start: date, end: date) -> None:
@@ -86,9 +89,9 @@ async def refresh_reservations(start: date, end: date) -> None:
       **xd,
       **xd,
     }
     }
     await reservations.set(data)
     await reservations.set(data)
-    print(f"  reservation {checkin_date} – {checkout_date}: {xd.get('guest_name', '')}")
+    _log.debug("reservation %s – %s: %s", checkin_date, checkout_date, xd.get('guest_name', ''))
     found += 1
     found += 1
-  print(f"  {found} reservation(s) refreshed")
+  _log.info("%d reservation(s) refreshed", found)
 
 
 
 
 async def refresh_rules(start: date, end: date) -> None:
 async def refresh_rules(start: date, end: date) -> None:
@@ -96,9 +99,9 @@ async def refresh_rules(start: date, end: date) -> None:
   results = await apply_rules(start, end)
   results = await apply_rules(start, end)
   for name, dates in results.items():
   for name, dates in results.items():
     for d in dates:
     for d in dates:
-      print(f"  rule {name}: {d}")
+      _log.debug("rule %s: %s", name, d)
   total = sum(len(v) for v in results.values())
   total = sum(len(v) for v in results.values())
-  print(f"  {total} rule event(s) refreshed")
+  _log.info("%d rule event(s) refreshed", total)
 
 
 
 
 async def local_refresh(start: date, end: date) -> None:
 async def local_refresh(start: date, end: date) -> None:

+ 8 - 5
room_cal/actions/local_sync.py

@@ -1,9 +1,12 @@
+import logging
 from datetime import date
 from datetime import date
 
 
 from room_cal._utils import get_config
 from room_cal._utils import get_config
 
 
 ACTION_SPEC = ('local-sync', [])
 ACTION_SPEC = ('local-sync', [])
 
 
+_log = logging.getLogger(__name__)
+
 
 
 async def local_sync(start_date: date, end_date: date) -> None:
 async def local_sync(start_date: date, end_date: date) -> None:
   """Run all local-only sync operations in dependency order.
   """Run all local-only sync operations in dependency order.
@@ -23,17 +26,17 @@ async def local_sync(start_date: date, end_date: date) -> None:
 
 
   for entry in get_config().calendars:
   for entry in get_config().calendars:
     result = await fetch_feed(start_date, end_date, feed_name=entry.name)
     result = await fetch_feed(start_date, end_date, feed_name=entry.name)
-    print(f"  feed {entry.name!r}: {len(result.data)} date(s) closed" + (" (changed)" if result.changed else ""))
+    _log.info("feed %r: %d date(s) closed%s", entry.name, len(result.data), " (changed)" if result.changed else "")
 
 
   uc_result = await fetch_user_cal(start_date, end_date)
   uc_result = await fetch_user_cal(start_date, end_date)
-  print(f"  user_cal: {len(uc_result.data['closed'])} date(s) closed" + (" (changed)" if uc_result.changed else ""))
+  _log.info("user_cal: %d date(s) closed%s", len(uc_result.data['closed']), " (changed)" if uc_result.changed else "")
 
 
   filled = await fill_prices(start_date, end_date)
   filled = await fill_prices(start_date, end_date)
-  print(f"  fill-prices: {len(filled)} price(s) created")
+  _log.info("fill-prices: %d price(s) created", len(filled))
 
 
   rule_results = await apply_rules(start_date, end_date)
   rule_results = await apply_rules(start_date, end_date)
   total = sum(len(v) for v in rule_results.values())
   total = sum(len(v) for v in rule_results.values())
-  print(f"  rules: {total} event(s) synced")
+  _log.info("rules: %d event(s) synced", total)
 
 
   busy_result = await push_busy(start_date, end_date)
   busy_result = await push_busy(start_date, end_date)
-  print(f"  push-busy: {len(busy_result.data['busy'])} date(s) busy" + (" (changed)" if busy_result.changed else ""))
+  _log.info("push-busy: %d date(s) busy%s", len(busy_result.data['busy']), " (changed)" if busy_result.changed else "")

+ 1 - 2
room_cal/service_api/_scripts.py

@@ -33,9 +33,8 @@ def _npm_env() -> dict:
 
 
 def _ensure_installed(ts_dir: Path) -> None:
 def _ensure_installed(ts_dir: Path) -> None:
   if not (ts_dir / 'node_modules').exists():
   if not (ts_dir / 'node_modules').exists():
-    print('=== npm install (service-api) ===')
+    _log.info('npm install (service-api)')
     subprocess.run(['npm', 'install'], cwd=ts_dir, check=True)
     subprocess.run(['npm', 'install'], cwd=ts_dir, check=True)
-    print()
 
 
 
 
 def _assert_not_async(fn_name: str) -> None:
 def _assert_not_async(fn_name: str) -> None: