Exemplo n.º 1
0
 def info_imagecrawler_desc(imagecrawler: str) -> int:
     from nichtparasoup._internals import _log
     from nichtparasoup.core.server import type_module_name_str
     from nichtparasoup.imagecrawler import get_imagecrawlers
     imagecrawler_class = get_imagecrawlers().get_class(imagecrawler)
     if not imagecrawler_class:
         _message_exception(ValueError('unknown ImageCrawler {!r}'.format(imagecrawler)))
         return 1
     info = []
     info_linebreak = '\r\n'
     imagecrawler_info = imagecrawler_class.info()
     info.append(imagecrawler_info.description)
     if imagecrawler_info.long_description:
         info.append(imagecrawler_info.long_description)
     if imagecrawler_info.config:
         info_bull = info_linebreak + ' * '
         mlen = max(len(k) for k in imagecrawler_info.config.keys())
         info.append('Config: ' + info_bull + info_bull.join([
             '{key:{mlen}}: {desc}'.format(mlen=mlen, key=key, desc=desc)
             for key, desc in imagecrawler_info.config.items()]))
     _message((info_linebreak * 2).join(info))
     _log('debug', info_linebreak.join(
         [
             info_linebreak,
             'DEBUG INFO',
             'Icon : {!r}'.format(imagecrawler_info.icon_url),
             'Class: {!r}'.format(type_module_name_str(imagecrawler_class)),
         ]))
     return 0
Exemplo n.º 2
0
 def info_imagecrawler_list(_: Optional[Any] = None) -> int:
     from nichtparasoup.imagecrawler import get_imagecrawlers
     imagecrawlers = get_imagecrawlers().names()
     if not imagecrawlers:
         _message_exception(Warning('no ImageCrawler found'))
     else:
         _message("\r\n".join(sorted(imagecrawlers)))
     return 0
Exemplo n.º 3
0
def get_imagecrawler(config_crawler: Dict[str, Any]) -> BaseImageCrawler:
    from nichtparasoup.imagecrawler import get_imagecrawlers
    imagecrawler_name = config_crawler['name']
    imagecrawler_class = get_imagecrawlers().get_class(imagecrawler_name)
    if not imagecrawler_class:
        raise ValueError('unknown crawler name {!r}'.format(imagecrawler_name))
    imagecrawler_config = config_crawler['config']
    try:
        return imagecrawler_class(**imagecrawler_config)
    except Exception as e:
        raise ImageCrawlerSetupError(imagecrawler_name, imagecrawler_class,
                                     imagecrawler_config) from e
Exemplo n.º 4
0
def imagecrawler_completion(*args: Any, **kwargs: Any) -> Set[str]:
    return set(get_imagecrawlers().names())
Exemplo n.º 5
0
 def check_get_imagecrawler_name(self) -> None:
     # act
     imagecrawler_name = get_imagecrawlers().get_name(self.ic_class)
     # assert
     self.assertEqual(imagecrawler_name, self.ic_name)
Exemplo n.º 6
0
 def check_get_imagecrawler_class(self) -> None:
     # act
     imagecrawler_class = get_imagecrawlers().get_class(self.ic_name)
     # assert
     self.assertIs(imagecrawler_class, self.ic_class)