Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint --disable W0511 $(git ls-files '*.py')
pylint --disable W0511 $(git ls-files '*.py' | grep -v '^open_print_tag/')
12 changes: 12 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2025 Sebastian Andersson <sebastian@bittr.nu>
#
# SPDX-License-Identifier: GPL-3.0-or-later

[MASTER]
# Ignore open_print_tag directory (external dependency from PRUSA RESEARCH A.S.)
ignore=open_print_tag
init-hook='import sys; sys.path.append("open_print_tag/utils")'

[MESSAGES CONTROL]
# Disable TODO warnings
disable=W0511
7 changes: 7 additions & 0 deletions LICENSES/LicenseRef-prusa.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2025 PRUSA RESEARCH A.S.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 changes: 6 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ path = [
precedence = "aggregate"
SPDX-FileCopyrightText = "$YEAR $NAME <$CONTACT>"
SPDX-License-Identifier = "CC0-1.0"

[[annotations]]
path = "open_print_tag/**"
precedence = "aggregate"
SPDX-FileCopyrightText = "2025 PRUSA RESEARCH A.S."
SPDX-License-Identifier = "LicenseRef-prusa"
88 changes: 88 additions & 0 deletions lib/mock_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,94 @@ def set_nfc_id_for_spool(self, spool_id: int, nfc_id: str) -> bool:
return True
return False

def create_vendor(self, name: str) -> Dict[str, Any]:
"""Create a vendor in mock data"""
logger.info("MockSpoolmanClient: create_vendor called with name=%s", name)
# In mock, just return a vendor dict
return {"id": 99, "name": name}

def get_vendor_by_name(self, name: str) -> Optional[Dict[str, Any]]:
"""Get vendor by name from mock data"""
logger.info("MockSpoolmanClient: get_vendor_by_name called with name=%s", name)
# Return mock vendor if it matches existing data
for spool in self.spools:
vendor_name = spool.get("filament", {}).get("vendor", {}).get("name", "")
if vendor_name.lower() == name.lower():
return {"id": 99, "name": vendor_name}
return None

def get_or_create_vendor(self, name: str) -> Dict[str, Any]:
"""Get or create a vendor by name"""
logger.info("MockSpoolmanClient: get_or_create_vendor called with name=%s", name)
vendor = self.get_vendor_by_name(name)
if vendor:
return vendor
return self.create_vendor(name)

def find_filament_by_vendor_material_and_name(
self, vendor_id: int, material: str, name: str
) -> Optional[Dict[str, Any]]:
"""Find a filament by vendor ID, material, and name"""
logger.info(
"MockSpoolmanClient: find_filament_by_vendor_material_and_name called"
)
# Search through existing spools for matching filament
for spool in self.spools:
filament = spool.get("filament", {})
if (
filament.get("name", "").lower() == name.lower()
and str(material).lower() in filament.get("name", "").lower()
):
return filament
return None

def get_or_create_filament(
self, vendor_id: int, material: str, name: str, filament_data: Dict[str, Any]
) -> Dict[str, Any]:
"""Get existing filament or create a new one"""
logger.info(
"MockSpoolmanClient: get_or_create_filament called with name=%s, material=%s",
name,
material,
)
# Try to find existing filament
existing = self.find_filament_by_vendor_material_and_name(
vendor_id, material, name
)
if existing:
logger.info(
"MockSpoolmanClient: Found existing filament id=%s", existing.get("id")
)
return existing
# Create new filament if not found
return self.create_filament(filament_data)

def create_filament(self, data: Dict[str, Any]) -> Dict[str, Any]:
"""Create a filament in mock data"""
logger.info(
"MockSpoolmanClient: create_filament called with name=%s",
data.get("name"),
)
# Return mock filament
return {
"id": 100,
"name": data.get("name", "Mock Filament"),
"vendor_id": data.get("vendor_id", 99),
}

def create_spool(self, data: Dict[str, Any]) -> Dict[str, Any]:
"""Create a spool in mock data"""
logger.info(
"MockSpoolmanClient: create_spool called with filament_id=%s",
data.get("filament_id"),
)
# Return mock spool
return {
"id": 200,
"filament_id": data.get("filament_id"),
"extra": data.get("extra", {}),
}


class MockMoonrakerWebClient: # pylint: disable=R0903
"""Mock Moonraker Web Client for testing"""
Expand Down
Loading
Loading