(driver = None)
| 12 | # DO NOT store a reference to the result of printerManager in any persistant object. |
| 13 | |
| 14 | def printerManager(driver = None): |
| 15 | global _instance |
| 16 | |
| 17 | if driver is not None and _instance is not None and _instance.driverName != driver: |
| 18 | _instance.rampdown() |
| 19 | _instance = None |
| 20 | |
| 21 | if _instance is None and driver: |
| 22 | if driver.startswith('plugin:'): |
| 23 | from astroprint.printer.plugin import PrinterWithPlugin, NoPluginException |
| 24 | |
| 25 | try: |
| 26 | _instance = PrinterWithPlugin(driver[7:]) |
| 27 | |
| 28 | except NoPluginException: |
| 29 | #The plugin is gone. Pick the default |
| 30 | from astroprint.printerprofile import printerProfileManager |
| 31 | ppm = printerProfileManager() |
| 32 | ppm.set({'driver': DEFAULT_MANAGER}) |
| 33 | ppm.save() |
| 34 | |
| 35 | else: |
| 36 | import importlib |
| 37 | |
| 38 | try: |
| 39 | # driver name to class map. format is (module, classname) |
| 40 | classInfo = { |
| 41 | 'marlin': ('.marlin', 'PrinterMarlin'), |
| 42 | 's3g': ('.s3g', 'PrinterS3g') |
| 43 | }[driver] |
| 44 | |
| 45 | except KeyError: |
| 46 | classInfo = ('.marlin', 'PrinterMarlin') |
| 47 | |
| 48 | module = importlib.import_module(classInfo[0], 'astroprint.printer') |
| 49 | _instance = getattr(module, classInfo[1])() |
| 50 | |
| 51 | return _instance |
no test coverage detected