Exemple #1
0
def _get_scanner(config, devid, preferred_sources=None):
    logger.info("Will scan using %s", devid)
    resolution = config['scanner_resolution'].value
    logger.info("Will scan at a resolution of %d", resolution)

    dev = pyinsane.Scanner(name=devid)

    config_source = config['scanner_source'].value
    use_config_source = False

    if 'source' not in dev.options:
        logger.warning("Can't set the source on this scanner. Option not found")
    else:
        if preferred_sources:
            use_config_source = False
            regexs = [
                re.compile(x, flags=re.IGNORECASE)
                for x in preferred_sources
            ]
            for regex in regexs:
                if regex.match(config_source):
                    use_config_source = True
                    break

        if not use_config_source and preferred_sources:
            try:
                set_scanner_opt('source', dev.options['source'],
                                preferred_sources)
            except (KeyError, pyinsane.SaneException), exc:
                config_source = config['scanner_source'].value
                logger.error("Warning: Unable to set scanner source to '%s': %s",
                             preferred_sources, exc)
                if dev.options['source'].capabilities.is_active():
                    dev.options['source'].value = config_source
        else:
Exemple #2
0
def get_scanner(config, preferred_sources=None):
    devid = config['scanner_devid'].value
    logger.info("Will scan using %s" % str(devid))
    resolution = config['scanner_resolution'].value
    logger.info("Will scan at a resolution of %d" % resolution)

    dev = pyinsane.Scanner(name=devid)

    config_source = config['scanner_source'].value
    use_config_source = False

    if preferred_sources:
        use_config_source = False
        regexs = [
            re.compile(x, flags=re.IGNORECASE) for x in preferred_sources
        ]
        for regex in regexs:
            if regex.match(config_source):
                use_config_source = True
                break

    if not use_config_source and preferred_sources:
        try:
            set_scanner_opt('source', dev.options['source'], preferred_sources)
        except (KeyError, pyinsane.SaneException), exc:
            config_source = config['scanner_source'].value
            logger.error("Warning: Unable to set scanner source to '%s': %s" %
                         (preferred_sources, exc))
            if dev.options['source'].capabilities.is_active():
                dev.options['source'].value = config_source
Exemple #3
0
def _get_scanner(config, devid, preferred_sources=None):
    logger.info("Will scan using %s" % str(devid))
    resolution = config['scanner_resolution'].value
    logger.info("Will scan at a resolution of %d" % resolution)

    dev = pyinsane.Scanner(name=devid)

    config_source = config['scanner_source'].value
    use_config_source = False

    if 'source' not in dev.options:
        logger.warning(
            "Can't set the source on this scanner. Option not found")
    else:
        if preferred_sources:
            use_config_source = False
            regexs = [
                re.compile(x, flags=re.IGNORECASE) for x in preferred_sources
            ]
            for regex in regexs:
                if regex.match(config_source):
                    use_config_source = True
                    break

        if not use_config_source and preferred_sources:
            try:
                set_scanner_opt('source', dev.options['source'],
                                preferred_sources)
            except (KeyError, pyinsane.SaneException) as exc:
                config_source = config['scanner_source'].value
                logger.error(
                    "Warning: Unable to set scanner source to '%s': %s" %
                    (preferred_sources, exc))
                if dev.options['source'].capabilities.is_active():
                    dev.options['source'].value = config_source
        else:
            if dev.options['source'].capabilities.is_active():
                dev.options['source'].value = config_source
            logger.info("Will scan using source %s" % str(config_source))

    if 'resolution' not in dev.options:
        logger.warning("Can't set the resolution on this scanner."
                       " Option not found")
    else:
        try:
            dev.options['resolution'].value = resolution
        except pyinsane.SaneException:
            logger.warning("Unable to set scanner resolution to %d: %s" %
                           (resolution, exc))

    if 'mode' not in dev.options:
        logger.warning("Can't set the mode on this scanner. Option not found")
    else:
        if dev.options['mode'].capabilities.is_active():
            if "Color" in dev.options['mode'].constraint:
                dev.options['mode'].value = "Color"
                logger.info("Scanner mode set to 'Color'")
            elif "24bit Color" in dev.options['mode'].constraint:
                # Brother MVC-J410 support ... (@$*#@#!!)
                dev.options['mode'].value = "24bit Color"
                logger.info("Scanner mode set to '24bit Color'")
            elif "Gray" in dev.options['mode'].constraint:
                dev.options['mode'].value = "Gray"
                logger.info("Scanner mode set to 'Gray'")
            else:
                logger.warning("Unable to set scanner mode ! May be 'Lineart'")

    maximize_scan_area(dev)
    return (dev, resolution)