コード例 #1
0
    def test_multiple_verbose(self):
        verbosity_argument = '-'

        for verbosity_level in range(1, 10):
            verbosity_argument += 'v'
            arguments = argument_helper.get_arguments([verbosity_argument])
            self.assertEqual(arguments.verbose, verbosity_level)
コード例 #2
0
    def test_short_option(self):
        arguments = argument_helper.get_arguments([
            '-v', '-c', './myconfig.yml', '-d', './mymangas', '-f', 'myformat'
        ])

        self.assertEqual(arguments.verbose, 1)
        self.assertEqual(arguments.config_file, './myconfig.yml')
        self.assertEqual(arguments.destination_path, './mymangas')
        self.assertEqual(arguments.format, 'myformat')
コード例 #3
0
    def test_long_option(self):
        arguments = argument_helper.get_arguments([
            '--verbose', '--config_file', './myconfig.yml',
            '--destination_path', './mymangas', '--format', 'myformat'
        ])

        self.assertEqual(arguments.verbose, 1)
        self.assertEqual(arguments.config_file, './myconfig.yml')
        self.assertEqual(arguments.destination_path, './mymangas')
        self.assertEqual(arguments.format, 'myformat')
コード例 #4
0
ファイル: settings.py プロジェクト: Harkame/AnimeDownloader
def init_arguments(arguments):
    global logger

    global config_file
    global destination_path

    global mangas

    global browser

    arguments = get_arguments(arguments)

    if arguments.verbose:
        logger.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s :: %(levelname)s :: %(module)s :: %(lineno)s :: %(funcName)s :: %(message)s'
        )
        stream_handler = logging.StreamHandler()
        stream_handler.setFormatter(formatter)

        if arguments.verbose == 0:
            logger.setLevel(logging.NOTSET)
        elif arguments.verbose == 1:
            logger.setLevel(logging.DEBUG)
        elif arguments.verbose == 2:
            logger.setLevel(logging.INFO)
        elif arguments.verbose == 3:
            logger.setLevel(logging.WARNING)
        elif arguments.verbose == 4:
            logger.setLevel(logging.ERROR)
        elif arguments.verbose == 5:
            logger.setLevel(logging.CRITICAL)

        logger.addHandler(stream_handler)

    if arguments.config_file:
        config_file = arguments.config_file

    if arguments.destination_path:
        destination_path = arguments.destination_path

    if arguments.chrome:
        chrome_opt = webdriver.ChromeOptions()
        chrome_opt.add_argument('--headless')
        browser = webdriver.Chrome(chrome_options=chrome_opt)
    else:
        fox_opt = webdriver.FirefoxOptions()
        fox_opt.add_argument('--headless')
        browser = webdriver.Firefox(firefox_options=fox_opt)
コード例 #5
0
def main():
    settings.init()

    settings.config_file = DEFAULT_CONFIG_FILE

    arguments = get_arguments(sys.argv[1:])

    if arguments.verbose:
        settings.logger.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(module)s :: %(lineno)s :: %(funcName)s :: %(message)s')
        stream_handler = logging.StreamHandler()
        stream_handler.setFormatter(formatter)

        if arguments.verbose == 0:
            settings.logger.setLevel(logging.NOTSET)
        elif arguments.verbose == 1:
            settings.logger.setLevel(logging.DEBUG)
        elif arguments.verbose == 2:
            settings.logger.setLevel(logging.INFO)
        elif arguments.verbose == 3:
            settings.logger.setLevel(logging.WARNING)
        elif arguments.verbose == 4:
            settings.logger.setLevel(logging.ERROR)
        elif arguments.verbose == 5:
            settings.logger.setLevel(logging.CRITICAL)

        settings.logger.addHandler(stream_handler)

    if arguments.config_file:
        settings.config_file = arguments.config_file

    if arguments.destination_path:
        settings.destination_path = arguments.destination_path

    if arguments.format:
        settings.manga_format = arguments.format

    if arguments.remove:
        remove = arguments.remove

    config = get_config(settings.config_file)

    mangas = []

    if config['mangas'] is not None:
        mangas = config['mangas']

    if settings.destination_path is None:
        if config['destinationPath'] is not None:
            settings.destination_path = config['destinationPath']
        else:
            settings.destination_path = DEFAULT_DESTINATION_PATH

    if settings.manga_format is None:
        if config['mangaFormat'] is not None:
            settings.manga_format = config['mangaFormat']
        else:
            settings.manga_format = DEFAULT_MANGA_FORMAT

    settings.logger.debug('mangas : %s', mangas)
    settings.logger.debug('settings : %s', settings)
    settings.logger.debug('settings.manga_format : %s', settings.manga_format)
    settings.logger.debug('remove : %s', remove)

    scraper = cfscrape.create_scraper()

    for manga in mangas:
        download_manga(scraper, manga)