Example #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
Example #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
Example #3
0
def main(args: Optional[List[str]] = None) -> int:  # pragma: no cover
    parser = create_parser()
    autocomplete(parser, always_complete_options='long')
    options = dict(parser.parse_args(args=args).__dict__)
    del parser
    if options.pop('debug', False):
        _logging_init(logging.DEBUG)
        _message('DEBUG ENABLED :)', 'cyan')
    command = options.pop('command')
    return getattr(Commands, command)(**options)  # type: ignore
Example #4
0
 def config_dump_file(config_file: str) -> int:
     from os.path import abspath, isfile
     from nichtparasoup._internals import _confirm
     from nichtparasoup.config import dump_defaults
     config_file = abspath(config_file)
     if isfile(config_file):
         overwrite = _confirm('File already exists, overwrite?')
         if overwrite is not True:
             _message('Abort.')
             return 1
     try:
         dump_defaults(config_file)
         return 0
     except Exception as e:
         _message_exception(e)
         return 255
Example #5
0
 def info_version(_: Optional[Any] = None) -> int:
     from nichtparasoup import VERSION
     _message(VERSION)
     return 0