# Path: stoqdrivers/serialbase.py
# class SerialPort(Serial):
# 
#     def __init__(self, device, baudrate=9600):
#         # WARNING: Never change these default options, some drivers are based
#         # on this to work. Maybe we should change this and make all the driver
#         # specify its options, but right now I think that's ok, since these
#         # options are common to most of the drivers.
#         Serial.__init__(self, device, baudrate=baudrate, bytesize=EIGHTBITS,
#                         parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=3,
#                         write_timeout=3)
#         self.setDTR(True)
#         self.flushInput()
#         self.flushOutput()
# 
# Path: stoqdrivers/utils.py
# def get_obj_from_module(module_name, obj_name):
#     module = import_module(module_name)
#     try:
#         return getattr(module, obj_name)
#     except AttributeError:
#         raise ImportError("Can't find class %s for module %s" % (module_name, module_name))


import optparse
import sys
        import pprint
from stoqdrivers.serialbase import SerialPort
from stoqdrivers.utils import get_obj_from_module


def main(args):
    usage = "usage: %prog [options] command [args]"
    parser = optparse.OptionParser(usage=usage)
    parser.add_option('-t', '--type',
                      action="store",
                      dest="type",
                      default="printers",
                      help='Device type')
    parser.add_option('-b', '--brand',
                      action="store",
                      dest="brand",
                      help='Device brand')
    parser.add_option('-m', '--model',
                      action="store",
                      dest="model",
                      help='Device model')
    parser.add_option('-p', '--port',
                      action="store",
                      dest="port",
                      default="/dev/ttyS0",
                      help='Device port')

    options, args = parser.parse_args(args)
    if len(args) < 2:
        raise SystemExit("Need a command")

    module_name = 'stoqdrivers.%s.%s.%s' % (options.type, options.brand, options.model)
    driver = get_obj_from_module(module_name, obj_name=options.model)

# Path: stoqdrivers/serialbase.py
# class SerialPort(Serial):
# 
#     def __init__(self, device, baudrate=9600):
#         # WARNING: Never change these default options, some drivers are based
#         # on this to work. Maybe we should change this and make all the driver
#         # specify its options, but right now I think that's ok, since these
#         # options are common to most of the drivers.
#         Serial.__init__(self, device, baudrate=baudrate, bytesize=EIGHTBITS,
#                         parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=3,
#                         write_timeout=3)
#         self.setDTR(True)
#         self.flushInput()
#         self.flushOutput()
# 
# Path: stoqdrivers/utils.py
# def get_obj_from_module(module_name, obj_name):
#     module = import_module(module_name)
#     try:
#         return getattr(module, obj_name)
#     except AttributeError:
#         raise ImportError("Can't find class %s for module %s" % (module_name, module_name))


# Path: tools/testdriver.py
import optparse
import sys
        import pprint
from stoqdrivers.serialbase import SerialPort
from stoqdrivers.utils import get_obj_from_module



def main(args):
    usage = "usage: %prog [options] command [args]"
    parser = optparse.OptionParser(usage=usage)
    parser.add_option('-t', '--type',
                      action="store",
                      dest="type",
                      default="printers",
                      help='Device type')
    parser.add_option('-b', '--brand',
                      action="store",
                      dest="brand",
                      help='Device brand')
    parser.add_option('-m', '--model',
                      action="store",
                      dest="model",
                      help='Device model')
    parser.add_option('-p', '--port',
                      action="store",
                      dest="port",
                      default="/dev/ttyS0",
                      help='Device port')

    options, args = parser.parse_args(args)
    if len(args) < 2:
        raise SystemExit("Need a command")

    module_name = 'stoqdrivers.%s.%s.%s' % (options.type, options.brand, options.model)
    driver = get_obj_from_module(module_name, obj_name=options.model)

    device = driver(port=SerialPort(options.port))