File: __init__.py

package info (click to toggle)
python-brother-ql 0.9.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: python: 1,640; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 1,567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

from .generic import BrotherQLBackendGeneric


available_backends = [
  'pyusb',
  'network',
  'linux_kernel',
]

def guess_backend(identifier):
    """ guess the backend from a given identifier string for the device """
    if identifier.startswith('usb://') or identifier.startswith('0x'):
        return 'pyusb'
    elif identifier.startswith('file://') or identifier.startswith('/dev/usb/') or identifier.startswith('lp'):
        return 'linux_kernel'
    elif identifier.startswith('tcp://'):
        return 'network'
    else:
        raise ValueError('Cannot guess backend for given identifier: %s' % identifier)
    

def backend_factory(backend_name):

    if backend_name == 'pyusb':
        from . import pyusb        as pyusb_backend
        list_available_devices = pyusb_backend.list_available_devices
        backend_class          = pyusb_backend.BrotherQLBackendPyUSB
    elif backend_name == 'linux_kernel':
        from . import linux_kernel as linux_kernel_backend
        list_available_devices = linux_kernel_backend.list_available_devices
        backend_class          = linux_kernel_backend.BrotherQLBackendLinuxKernel
    elif backend_name == 'network':
        from . import network      as network_backend
        list_available_devices = network_backend.list_available_devices
        backend_class          = network_backend.BrotherQLBackendNetwork
    else:
        raise NotImplementedError('Backend %s not implemented.' % backend_name)

    return {'list_available_devices': list_available_devices, 'backend_class': backend_class}