Skip to content

Commit

Permalink
Update spoolman.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeanon committed Jan 21, 2024
1 parent c392c20 commit 9af83ca
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions moonraker/components/spoolman.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, config: ConfigHelper):
self.server = config.get_server()
self.eventloop = self.server.get_event_loop()
self._get_spoolman_urls(config)
self._get_website_urls(config)
self.sync_rate_seconds = config.getint("sync_rate", default=5, minval=1)
self.report_timer = self.eventloop.register_timer(self.report_extrusion)
self.pending_reports: Dict[int, float] = {}
Expand Down Expand Up @@ -67,25 +68,27 @@ def __init__(self, config: ConfigHelper):
def _get_spoolman_urls(self, config: ConfigHelper) -> None:
orig_url = config.get('server')
url_match = re.match(r"(?i:(?P<scheme>https?)://)?(?P<host>.+)", orig_url)
orig_website = config.get('website')
website_match = re.match(r"(?i:(?P<scheme>https?)://)?(?P<host>.+)", orig_website)
if url_match is None:
raise config.error(
f"Section [spoolman], Option server: {orig_url}: Invalid URL format"
)
if website_match is None:
raise config.error(
f"Section [spoolman], Option website: {orig_website}: Invalid URL format"
)
scheme = url_match["scheme"] or "http"
host = url_match["host"].rstrip("/")
ws_scheme = "wss" if scheme == "https" else "ws"
website_scheme = website_match["scheme"] or "http"
website_host = website_match["host"].rstrip("/")
ws_website_scheme = "wss" if website_scheme == "https" else "ws"
self.spoolman_url = f"{scheme}://{host}/api"
self.ws_url = f"{ws_scheme}://{host}/api/v1/spool"
self.website = f"{ws_website_scheme}://{website_host}/spool"

def _get_website_urls(self, config: ConfigHelper):
orig_website_url = config.get('website', self.spoolman_url)
website_url_match = re.match(r"(?i:(?P<scheme>https?)://)?(?P<host>.+)", orig_website_url)

Check warning on line 83 in moonraker/components/spoolman.py

View workflow job for this annotation

GitHub Actions / lint-python-code

line too long (98 > 88 characters)
if website_url_match is None:
raise config.error(
f"Section [spoolman], Option website: {orig_website_url}: Invalid URL format"

Check warning on line 86 in moonraker/components/spoolman.py

View workflow job for this annotation

GitHub Actions / lint-python-code

line too long (93 > 88 characters)
)
website_scheme = website_url_match["scheme"] or "http"
website_host = website_url_match["host"].rstrip("/")
self.website_url = f"{website_scheme}://{website_host}/spool"
self.website = f"{website_scheme}://{website_host}/spool"

def _register_notifications(self):
self.server.register_notification("spoolman:active_spool_set")
Expand Down

0 comments on commit 9af83ca

Please sign in to comment.