예제 #1
0
    def check(self, string, expected):
        negates, global_, string = self.parse_token_options(string)

        options = expected.get('options')
        if options is None:
            options = {}
        if not isinstance(options, dict):
            options = parse_options(options)
        if 'implicit' not in options:
            options['implicit'] = True
        try:
            result = guessit(string, options)
        except Exception as exc:
            logger.error('[' + string + '] Exception: ' + str(exc))
            raise exc

        entry = EntryResult(string, negates)

        if global_:
            self.check_global(string, result, entry)

        self.check_expected(result, expected, entry)

        return entry
예제 #2
0
    def check(self, string, expected):
        negates, global_, string = self.parse_token_options(string)

        options = expected.get('options')
        if options is None:
            options = {}
        if not isinstance(options, dict):
            options = parse_options(options)
        if 'implicit' not in options:
            options['implicit'] = True
        try:
            result = guessit(string, options)
        except Exception as exc:
            logger.error('[' + string + '] Exception: ' + str(exc))
            raise exc

        entry = EntryResult(string, negates)

        if global_:
            self.check_global(string, result, entry)

        self.check_expected(result, expected, entry)

        return entry
예제 #3
0
def main(args=None):  # pylint:disable=too-many-branches
    """
    Main function for entry point
    """
    if six.PY2 and os.name == 'nt':  # pragma: no cover
        # see http://bugs.python.org/issue2128
        import locale

        for i, j in enumerate(sys.argv):
            sys.argv[i] = j.decode(locale.getpreferredencoding())

    if args is None:  # pragma: no cover
        options = parse_options()
    else:
        options = parse_options(args)
    options = load_config(options)
    if options.get('verbose'):
        logging.basicConfig(stream=sys.stdout, format='%(message)s')
        logging.getLogger().setLevel(logging.DEBUG)

    help_required = True

    if options.get('version'):
        print('+-------------------------------------------------------+')
        print('+                   GuessIt ' + __version__ + (28 - len(__version__)) * ' ' + '+')
        print('+-------------------------------------------------------+')
        print('+                   Rebulk ' + __rebulk_version__ + (29 - len(__rebulk_version__)) * ' ' + '+')
        print('+-------------------------------------------------------+')
        print('|      Please report any bug or feature request at      |')
        print('|     https://github.com/guessit-io/guessit/issues.     |')
        print('+-------------------------------------------------------+')
        help_required = False

    if options.get('yaml'):
        try:
            import yaml  # pylint:disable=unused-variable
        except ImportError:  # pragma: no cover
            del options['yaml']
            print('PyYAML is not installed. \'--yaml\' option will be ignored ...', file=sys.stderr)

    if options.get('properties') or options.get('values'):
        display_properties(options)
        help_required = False

    filenames = []
    if options.get('filename'):
        for filename in options.get('filename'):
            filenames.append(filename)
    if options.get('input_file'):
        if six.PY2:
            input_file = open(options.get('input_file'), 'r')
        else:
            input_file = open(options.get('input_file'), 'r', encoding='utf-8')
        try:
            filenames.extend([line.strip() for line in input_file.readlines()])
        finally:
            input_file.close()

    filenames = list(filter(lambda f: f, filenames))

    if filenames:
        for filename in filenames:
            help_required = False
            guess_filename(filename, options)

    if help_required:  # pragma: no cover
        argument_parser.print_help()
예제 #4
0
파일: __main__.py 프로젝트: zwcdp/bazarr
def main(args=None):  # pylint:disable=too-many-branches
    """
    Main function for entry point
    """
    if six.PY2 and os.name == 'nt':  # pragma: no cover
        # see http://bugs.python.org/issue2128
        import locale

        for i, j in enumerate(sys.argv):
            sys.argv[i] = j.decode(locale.getpreferredencoding())

    if args is None:  # pragma: no cover
        options = parse_options()
    else:
        options = parse_options(args)
    options = load_config(options)
    if options.get('verbose'):
        logging.basicConfig(stream=sys.stdout, format='%(message)s')
        logging.getLogger().setLevel(logging.DEBUG)

    help_required = True

    if options.get('version'):
        print('+-------------------------------------------------------+')
        print('+                   GuessIt ' + __version__ +
              (28 - len(__version__)) * ' ' + '+')
        print('+-------------------------------------------------------+')
        print('+                   Rebulk ' + __rebulk_version__ +
              (29 - len(__rebulk_version__)) * ' ' + '+')
        print('+-------------------------------------------------------+')
        print('|      Please report any bug or feature request at      |')
        print('|     https://github.com/guessit-io/guessit/issues.     |')
        print('+-------------------------------------------------------+')
        help_required = False

    if options.get('yaml'):
        try:
            import yaml  # pylint:disable=unused-variable
        except ImportError:  # pragma: no cover
            del options['yaml']
            print(
                'PyYAML is not installed. \'--yaml\' option will be ignored ...',
                file=sys.stderr)

    if options.get('properties') or options.get('values'):
        display_properties(options)
        help_required = False

    filenames = []
    if options.get('filename'):
        for filename in options.get('filename'):
            filenames.append(filename)
    if options.get('input_file'):
        if six.PY2:
            input_file = open(options.get('input_file'), 'r')
        else:
            input_file = open(options.get('input_file'), 'r', encoding='utf-8')
        try:
            filenames.extend([line.strip() for line in input_file.readlines()])
        finally:
            input_file.close()

    filenames = list(filter(lambda f: f, filenames))

    if filenames:
        for filename in filenames:
            help_required = False
            guess_filename(filename, options)

    if help_required:  # pragma: no cover
        argument_parser.print_help()
예제 #5
0
파일: __main__.py 프로젝트: plotski/guessit
def main(args=None):  # pylint:disable=too-many-branches
    """
    Main function for entry point
    """
    if args is None:  # pragma: no cover
        options = parse_options()
    else:
        options = parse_options(args)

    config = load_config(options)
    options = merge_options(config, options)

    if options.get('verbose'):
        logging.basicConfig(stream=sys.stdout, format='%(message)s')
        logging.getLogger().setLevel(logging.DEBUG)

    help_required = True

    if options.get('version'):
        print('+-------------------------------------------------------+')
        print('+                   GuessIt ' + __version__ +
              (28 - len(__version__)) * ' ' + '+')
        print('+-------------------------------------------------------+')
        print('+                   Rebulk ' + __rebulk_version__ +
              (29 - len(__rebulk_version__)) * ' ' + '+')
        print('+-------------------------------------------------------+')
        print('|      Please report any bug or feature request at      |')
        print('|     https://github.com/guessit-io/guessit/issues.     |')
        print('+-------------------------------------------------------+')
        help_required = False

    if options.get('yaml'):
        try:
            import yaml  # pylint:disable=unused-variable,unused-import,import-outside-toplevel
        except ImportError:  # pragma: no cover
            del options['yaml']
            print(
                'PyYAML is not installed. \'--yaml\' option will be ignored ...',
                file=sys.stderr)

    if options.get('properties') or options.get('values'):
        display_properties(options)
        help_required = False

    filenames = []
    if options.get('filename'):
        for filename in options.get('filename'):
            filenames.append(filename)
    if options.get('input_file'):
        with open(options.get('input_file'), 'r',
                  encoding='utf-8') as input_file:
            filenames.extend([line.strip() for line in input_file.readlines()])

    filenames = list(filter(lambda f: f, filenames))

    if filenames:
        for filename in filenames:
            help_required = False
            guess_filename(filename, options)

    if help_required:  # pragma: no cover
        argument_parser.print_help()