-
-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added initial draft for machines * refactor: isPluginRegistryLoaded check into own ready function * Added suggestions from codereview * Refactor: base_drivers -> machine_types * Use new BaseInvenTreeSetting unique interface * Fix Django not ready error * Added get_machines function to driver - get_machines function on driver - get_machine function on driver - initialized attribute on machine * Added error handeling for driver and machine type * Extended get_machines functionality * Export everything from plugin module * Fix spelling mistakes * Better states handeling, BaseMachineType is now used instead of Machine Model * Use uuid as pk * WIP: machine termination hook * Remove termination hook as this does not work with gunicorn * Remove machine from registry after delete * Added ClassProviderMixin * Check for slug dupplication * Added config_type to MachineSettings to define machine/driver settings * Refactor helper mixins into own file in InvenTree app * Fixed typing and added required_attributes for BaseDriver * fix: generic status import * Added first draft for machine states * Added convention for status codes * Added update_machine hook * Removed unnecessary _key suffix from machine config model * Initil draft for machine API * Refactored BaseInvenTreeSetting all_items and allValues method * Added required to InvenTreeBaseSetting and check_settings method * check if all required machine settings are defined and refactor: use getattr * Fix: comment * Fix initialize error and python 3.9 compability * Make machine states available through the global states api * Added basic PUI machine admin implementation that is still in dev * Added basic machine setting UI to PUI * Added machine detail view to PUI admin center * Fix merge issues * Fix style issues * Added machine type,machine driver,error stack tables * Fix style in machine/serializers.py * Added pui link from machine to machine type/driver drawer * Removed only partially working django admin in favor of the PUI admin center implementation * Added required field to settings item * Added machine restart function * Added restart requird badge to machine table/drawer * Added driver init function * handle error functions for machines and registry * Added driver errors * Added machine table to driver drawer * Added back button to detail drawer component * Fix auto formatable pre-commit * fix: style * Fix deepsource * Removed slug field from table, added more links between drawers, remove detail drawer blur * Added initial docs * Removed description from driver/machine type select and fixed disabled driver select if no machine type is selected * Added basic label printing implementation * Remove translated column names because they are now retrieved from the api * Added printer location setting * Save last 10 used printer machine per user and sort them in the printing dialog * Added BasePrintingOptionsSerializer for common options * Fix not printing_options are not properly casted to its internal value * Fix type * Improved machine docs * Fix docs * Added UNKNOWN status code to label printer status * Skip machine loading when running migrations * Fix testing? * Fix: tests? * Fix: tests? * Disable docs check precommit * Disable docs check precommit * First draft for tests * fix test * Add type ignore * Added API tests * Test ci? * Add more tests * Added more tests * Bump api version * Changed driver/base driver naming schema * Added more tests * Fix tests * Added setting choice with kwargs and get_machines with initialized=None * Refetch table after deleting machine * Fix test --------- Co-authored-by: Matthias Mair <code@mjmair.com>
- Loading branch information
Showing
50 changed files
with
4,243 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
"""Provides helper mixins that are used throughout the InvenTree project.""" | ||
|
||
import inspect | ||
from pathlib import Path | ||
|
||
from django.conf import settings | ||
|
||
from plugin import registry as plg_registry | ||
|
||
|
||
class ClassValidationMixin: | ||
"""Mixin to validate class attributes and overrides. | ||
Class attributes: | ||
required_attributes: List of class attributes that need to be defined | ||
required_overrides: List of functions that need override, a nested list mean either one of them needs an override | ||
Example: | ||
```py | ||
class Parent(ClassValidationMixin): | ||
NAME: str | ||
def test(self): | ||
pass | ||
required_attributes = ["NAME"] | ||
required_overrides = [test] | ||
class MyClass(Parent): | ||
pass | ||
myClass = MyClass() | ||
myClass.validate() # raises NotImplementedError | ||
``` | ||
""" | ||
|
||
required_attributes = [] | ||
required_overrides = [] | ||
|
||
@classmethod | ||
def validate(cls): | ||
"""Validate the class against the required attributes/overrides.""" | ||
|
||
def attribute_missing(key): | ||
"""Check if attribute is missing.""" | ||
return not hasattr(cls, key) or getattr(cls, key) == '' | ||
|
||
def override_missing(base_implementation): | ||
"""Check if override is missing.""" | ||
if isinstance(base_implementation, list): | ||
return all(override_missing(x) for x in base_implementation) | ||
|
||
return base_implementation == getattr( | ||
cls, base_implementation.__name__, None | ||
) | ||
|
||
missing_attributes = list(filter(attribute_missing, cls.required_attributes)) | ||
missing_overrides = list(filter(override_missing, cls.required_overrides)) | ||
|
||
errors = [] | ||
|
||
if len(missing_attributes) > 0: | ||
errors.append( | ||
f"did not provide the following attributes: {', '.join(missing_attributes)}" | ||
) | ||
if len(missing_overrides) > 0: | ||
missing_overrides_list = [] | ||
for base_implementation in missing_overrides: | ||
if isinstance(base_implementation, list): | ||
missing_overrides_list.append( | ||
'one of ' | ||
+ ' or '.join(attr.__name__ for attr in base_implementation) | ||
) | ||
else: | ||
missing_overrides_list.append(base_implementation.__name__) | ||
errors.append( | ||
f"did not override the required attributes: {', '.join(missing_overrides_list)}" | ||
) | ||
|
||
if len(errors) > 0: | ||
raise NotImplementedError(f"'{cls}' " + ' and '.join(errors)) | ||
|
||
|
||
class ClassProviderMixin: | ||
"""Mixin to get metadata about a class itself, e.g. the plugin that provided that class.""" | ||
|
||
@classmethod | ||
def get_provider_file(cls): | ||
"""File that contains the Class definition.""" | ||
return inspect.getfile(cls) | ||
|
||
@classmethod | ||
def get_provider_plugin(cls): | ||
"""Plugin that contains the Class definition, otherwise None.""" | ||
for plg in plg_registry.plugins.values(): | ||
if plg.package_path == cls.__module__: | ||
return plg | ||
|
||
@classmethod | ||
def get_is_builtin(cls): | ||
"""Is this Class build in the Inventree source code?""" | ||
try: | ||
Path(cls.get_provider_file()).relative_to(settings.BASE_DIR) | ||
return True | ||
except ValueError: | ||
# Path(...).relative_to throws an ValueError if its not relative to the InvenTree source base dir | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from machine.machine_type import BaseDriver, BaseMachineType, MachineStatus | ||
from machine.registry import registry | ||
|
||
__all__ = ['registry', 'BaseMachineType', 'BaseDriver', 'MachineStatus'] |
Oops, something went wrong.