Esempio n. 1
0
    def test_bad_tnsnames_file(self):
        tnsnames_file = '{0}/testFiles/tnsnames_false.ora'.format(self._script_path)
        input_file_stream = FileStream(tnsnames_file)

        lexer = tnsnamesLexer(input_file_stream)
        stream = CommonTokenStream(lexer)
        parser = TnsNamesParserWithException(stream)
        with self.assertRaisesRegexp(Exception, "Syntax error") as cm:
            tree = parser.tnsnames()
Esempio n. 2
0
    def test_bad_tnsnames_file(self):
        tnsnames_file = '{0}/testFiles/tnsnames_false.ora'.format(
            self._script_path)
        input_file_stream = FileStream(tnsnames_file)

        lexer = tnsnamesLexer(input_file_stream)
        stream = CommonTokenStream(lexer)
        parser = TnsNamesParserWithException(stream)
        with self.assertRaisesRegexp(Exception, "Syntax error") as cm:
            tree = parser.tnsnames()
Esempio n. 3
0
def main(argv):
    input_file_stream = FileStream(argv[1])
    lexer = tnsnamesLexer(input_file_stream)
    stream = CommonTokenStream(lexer)
    parser = tnsnamesParser(stream)
    tree = parser.tnsnames()

    listener = AliasFinder()
    walker = ParseTreeWalker()
    walker.walk(listener, tree)
    for alias in listener.get_aliases:
        print(alias)
Esempio n. 4
0
    def test_format_orastyle(self):
        input_file_stream = FileStream(self._tnsnames_file)

        lexer = tnsnamesLexer(input_file_stream)
        stream = CommonTokenStream(lexer)
        parser = TnsNamesParserWithException(stream)
        tree = parser.tnsnames()

        listener = TnsnameOraStyleFormatter()
        walker = ParseTreeWalker()
        walker.walk(listener, tree)
        assert len(listener.get_lines) == 51
Esempio n. 5
0
    def test_format_single_line(self):
        input_file_stream = FileStream(self._tnsnames_file)

        lexer = tnsnamesLexer(input_file_stream)
        stream = CommonTokenStream(lexer)
        parser = TnsNamesParserWithException(stream)
        tree = parser.tnsnames()

        listener = TnsnameLineFormatter()
        walker = ParseTreeWalker()
        walker.walk(listener, tree)
        assert len(listener.get_lines) == 6
    def test_format_single_line(self):
        input_file_stream = FileStream(self._tnsnames_file)

        lexer = tnsnamesLexer(input_file_stream)
        stream = CommonTokenStream(lexer)
        parser = tnsnamesParser(stream)
        tree = parser.tnsnames()

        listener = TnsnameLineFormatter()
        walker = ParseTreeWalker()
        walker.walk(listener, tree)
        assert len(listener.get_lines) == 6
Esempio n. 7
0
    def test_get_aliases(self):
        input_file_stream = FileStream(self._tnsnames_file)

        lexer = tnsnamesLexer(input_file_stream)
        stream = CommonTokenStream(lexer)
        parser = tnsnamesParser(stream)
        tree = parser.tnsnames()

        listener = AliasFinder()
        walker = ParseTreeWalker()
        walker.walk(listener, tree)
        expected_aliases = ['LSNR_FRED', 'LSNR_WILMA', 'lsnr_barney', 'alias_1', 'alias_2.world',
                            'alias3.dunbar-it.co.uk', 'someother_alias', 'someother_alias2']
        self.assertListEqual(listener.get_aliases, expected_aliases)
Esempio n. 8
0
    def test_get_aliases(self):
        input_file_stream = FileStream(self._tnsnames_file)

        lexer = tnsnamesLexer(input_file_stream)
        stream = CommonTokenStream(lexer)
        parser = tnsnamesParser(stream)
        tree = parser.tnsnames()

        listener = AliasFinder()
        walker = ParseTreeWalker()
        walker.walk(listener, tree)
        expected_aliases = [
            'LSNR_FRED', 'LSNR_WILMA', 'lsnr_barney', 'alias_1',
            'alias_2.world', 'alias3.dunbar-it.co.uk', 'someother_alias',
            'someother_alias2'
        ]
        self.assertListEqual(listener.get_aliases, expected_aliases)
Esempio n. 9
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("tnsnamesFile", type=str, help="the filename of the tnsnames file to be formatted")
    parser.add_argument("-f", "--format", type=str, help="format to be applied",
                        default=Format.oracle.name)
    args = parser.parse_args()
    if args.format == Format.oracle.name:
        _listener = TnsnameOraStyleFormatter()
    else:
        _listener = TnsnameLineFormatter()

    input_file_stream = FileStream(args.tnsnamesFile)
    lexer = tnsnamesLexer(input_file_stream)
    stream = CommonTokenStream(lexer)
    parser = tnsnamesParser(stream)
    tree = parser.tnsnames()

    walker = ParseTreeWalker()
    walker.walk(_listener, tree)

    for line in _listener.get_lines:
        print(line)
Esempio n. 10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("tnsnamesFile", type=str, help="the filename of the tnsnames file to be formatted")
    parser.add_argument("-f", "--format", choices=[Format.oneLine.name, Format.oracle.name],
                        help="format to be applied",
                        default=Format.oracle.name)
    parser.add_argument("--lowerkeys", action='store_true',
                        help="lowercase keys (case handling for keys must be activated!)",
                        default=False)
    parser.add_argument("--lowervalues", action='store_true',
                        help="lowercase keys (case handling for values must be activated!)",
                        default=False)
    parser.add_argument("--handlekeycase", action='store_true', help="activate case handling for keys",
                        default=False)
    parser.add_argument("--handlevaluecase", action='store_true', help="activate case handling for values",
                        default=False)

    args = parser.parse_args()

    listener_ora_style = TnsnameOraStyleFormatter()
    listener_ora_style.set_uppercase_keywords(not args.lowerkeys)
    listener_ora_style.set_uppercase_value(not args.lowervalues)
    listener_ora_style.set_ignore_keyword_case(not args.handlekeycase)
    listener_ora_style.set_ignore_value_case(not args.handlevaluecase)

    try:
        input_file_stream = FileStream(args.tnsnamesFile)
    except FileNotFoundError:
        print(args.tnsnamesFile + " not found!")
        exit(1)

    lexer = tnsnamesLexer(input_file_stream)
    ora_stream = CommonTokenStream(lexer)
    tns_parser = TnsNamesParserWithException(ora_stream)
    try:
        tree = tns_parser.tnsnames()
    except Exception as ex:
        print("Error while parsing: " + ex.__str__())
        exit(1)

    walker = ParseTreeWalker()
    walker.walk(listener_ora_style, tree)

    buf = StringIO()

    if args.format == Format.oracle.name:
        for line in listener_ora_style.get_lines:
            print(line)
        exit(0)

    for line in listener_ora_style.get_lines:
        buf.write(line)

    listener_line_style = TnsnameLineFormatter()
    input_text_stream = InputStream(buf.getvalue())
    line_lexer = tnsnamesLexer(input_text_stream)
    line_stream = CommonTokenStream(line_lexer)
    line_parser = TnsNamesParserWithException(line_stream)
    try:
        tree = line_parser.tnsnames()
    except Exception as ex:
        print("Error while parsing: " + ex.__str__())
        exit(1)

    walker.walk(listener_line_style, tree)

    for line2 in listener_line_style.get_lines:
        print(line2)
Esempio n. 11
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "tnsnamesFile",
        type=str,
        help="the filename of the tnsnames file to be formatted")
    parser.add_argument("-f",
                        "--format",
                        choices=[Format.oneLine.name, Format.oracle.name],
                        help="format to be applied",
                        default=Format.oracle.name)
    parser.add_argument(
        "--lowerkeys",
        action='store_true',
        help="lowercase keys (case handling for keys must be activated!)",
        default=False)
    parser.add_argument(
        "--lowervalues",
        action='store_true',
        help="lowercase keys (case handling for values must be activated!)",
        default=False)
    parser.add_argument("--handlekeycase",
                        action='store_true',
                        help="activate case handling for keys",
                        default=False)
    parser.add_argument("--handlevaluecase",
                        action='store_true',
                        help="activate case handling for values",
                        default=False)

    args = parser.parse_args()

    listener_ora_style = TnsnameOraStyleFormatter()
    listener_ora_style.set_uppercase_keywords(not args.lowerkeys)
    listener_ora_style.set_uppercase_value(not args.lowervalues)
    listener_ora_style.set_ignore_keyword_case(not args.handlekeycase)
    listener_ora_style.set_ignore_value_case(not args.handlevaluecase)

    try:
        input_file_stream = FileStream(args.tnsnamesFile)
    except FileNotFoundError:
        print(args.tnsnamesFile + " not found!")
        exit(1)

    lexer = tnsnamesLexer(input_file_stream)
    ora_stream = CommonTokenStream(lexer)
    tns_parser = TnsNamesParserWithException(ora_stream)
    try:
        tree = tns_parser.tnsnames()
    except Exception as ex:
        print("Error while parsing: " + ex.__str__())
        exit(1)

    walker = ParseTreeWalker()
    walker.walk(listener_ora_style, tree)

    buf = StringIO()

    if args.format == Format.oracle.name:
        for line in listener_ora_style.get_lines:
            print(line)
        exit(0)

    for line in listener_ora_style.get_lines:
        buf.write(line)

    listener_line_style = TnsnameLineFormatter()
    input_text_stream = InputStream(buf.getvalue())
    line_lexer = tnsnamesLexer(input_text_stream)
    line_stream = CommonTokenStream(line_lexer)
    line_parser = TnsNamesParserWithException(line_stream)
    try:
        tree = line_parser.tnsnames()
    except Exception as ex:
        print("Error while parsing: " + ex.__str__())
        exit(1)

    walker.walk(listener_line_style, tree)

    for line2 in listener_line_style.get_lines:
        print(line2)