Example #1
0
    def __init__(self, include_dir_paths=None):
        object.__init__(self)

        if include_dir_paths is None:
            include_dir_paths = []
        elif isinstance(include_dir_paths, (list, tuple)):
            include_dir_paths = list(include_dir_paths)
        else:
            include_dir_paths = [include_dir_paths]
        if len(include_dir_paths) == 0:
            include_dir_paths.append(os.getcwd())
        my_dir_path = os.path.dirname(os.path.realpath(__file__))
        lib_thrift_src_dir_path = \
            os.path.abspath(os.path.join(
                my_dir_path,
                '..', '..', '..', '..',
                'lib', 'thrift', 'src'
            ))
        if lib_thrift_src_dir_path not in include_dir_paths:
            include_dir_paths.append(lib_thrift_src_dir_path)
        self.__include_dir_paths = []
        for include_dir_path in include_dir_paths:
            if include_dir_path not in self.__include_dir_paths:
                self.__include_dir_paths.append(include_dir_path)
        self.__include_dir_paths = tuple(self.__include_dir_paths)

        self.__parsed_thrift_files_by_path = {}
        self.__scanner = Scanner()
        self.__parser = Parser()
Example #2
0
 def _runTest(self, thrift_file_path):
     #        import logging
     #        logging.basicConfig(level=logging.DEBUG)
     #        import os.path
     #        if os.path.split(thrift_file_path)[1] != 'struct_type.thrift':
     #            return
     tokens = []
     try:
         tokens = Scanner().tokenize(thrift_file_path)
         ast = Parser().parse(tokens)  # @UnusedVariable
         # import pprint; pprint.pprint(ast.to_dict())
     except:
         print >> sys.stderr, 'Error parsing', thrift_file_path
         traceback.print_exc()
         for token in tokens:
             print >> sys.stderr, token.index, token.type, ':', len(
                 token.text), ':', token.text
         print >> sys.stderr
         raise