Debian Codegraph @

brother_ql/backends/__init__.py

raw
1
2 from .generic import BrotherQLBackendGeneric
3
4
5 available_backends = [
6 'pyusb',
7 'network',
8 'linux_kernel',
9 ]
10
11 def guess_backend(identifier):
12 """ guess the backend from a given identifier string for the device """
13 if identifier.startswith('usb://') or identifier.startswith('0x'):
14 return 'pyusb'
15 elif identifier.startswith('file://') or identifier.startswith('/dev/usb/') or identifier.startswith('lp'):
16 return 'linux_kernel'
17 elif identifier.startswith('tcp://'):
18 return 'network'
19 else:
20 raise ValueError('Cannot guess backend for given identifier: %s' % identifier)
21
22
23 def backend_factory(backend_name):
24
25 if backend_name == 'pyusb':
26 from . import pyusb as pyusb_backend
27 list_available_devices = pyusb_backend.list_available_devices
28 backend_class = pyusb_backend.BrotherQLBackendPyUSB
29 elif backend_name == 'linux_kernel':
30 from . import linux_kernel as linux_kernel_backend
31 list_available_devices = linux_kernel_backend.list_available_devices
32 backend_class = linux_kernel_backend.BrotherQLBackendLinuxKernel
33 elif backend_name == 'network':
34 from . import network as network_backend
35 list_available_devices = network_backend.list_available_devices
36 backend_class = network_backend.BrotherQLBackendNetwork
37 else:
38 raise NotImplementedError('Backend %s not implemented.' % backend_name)
39
40 return {'list_available_devices': list_available_devices, 'backend_class': backend_class}