def _test_parser_with_nodes(xml): """Build an InterfaceParser for the XML snippet and parse it.""" tmpfile = _create_temp_xml_file(xml) parser = InterfaceParser(tmpfile) root_node = parser.parse_with_nodes() os.unlink(tmpfile) return parser, root_node, tmpfile
def _test_parser(xml): """Build an InterfaceParser for the XML snippet and parse it.""" tmpfile = _create_temp_xml_file(xml) parser = InterfaceParser(tmpfile) interfaces = parser.parse() os.unlink(tmpfile) return parser, interfaces, tmpfile
def __init__(self, doc_repo, ext, sources): self.__current_filename = None self.symbols = {} self.doc_repo = doc_repo self.__ext = ext self.__raw_comment_parser = GtkDocParser(self.doc_repo) for filename in sources: self.__current_filename = filename ip = InterfaceParser(filename) for name, interface in ip.parse().iteritems(): self.__create_class_symbol (interface) for mname, method in interface.methods.iteritems(): self.__create_function_symbol (method) for pname, prop in interface.properties.iteritems(): self.__create_property_symbol (prop) for sname, signal in interface.signals.iteritems(): self.__create_signal_symbol (signal)
def __init__(self, app, project, ext, sources): self.__current_filename = None self.symbols = {} self.project = project self.app = app self.__ext = ext self.__raw_comment_parser = GtkDocParser(self.project) for filename in sources: self.__current_filename = filename ip = InterfaceParser(filename) for name, interface in ip.parse().items(): self.__create_class_symbol(interface) for mname, method in interface.methods.items(): self.__create_function_symbol(method) for pname, prop in interface.properties.items(): self.__create_property_symbol(prop) for sname, signal in interface.signals.items(): self.__create_signal_symbol(signal)
def _test_comparator(self, old_xml, new_xml): """Build an InterfaceComparator for the two parsed XML snippets.""" old_tmpfile = _create_temp_xml_file(old_xml) new_tmpfile = _create_temp_xml_file(new_xml) old_parser = InterfaceParser(old_tmpfile) new_parser = InterfaceParser(new_tmpfile) old_interfaces = old_parser.parse() new_interfaces = new_parser.parse() os.unlink(new_tmpfile) os.unlink(old_tmpfile) self.assertEqual(old_parser.get_output(), []) self.assertEqual(new_parser.get_output(), []) self.assertNotEqual(old_interfaces, None) self.assertNotEqual(new_interfaces, None) return InterfaceComparator(old_interfaces, new_interfaces)
def main(): """Main utility implementation.""" codes = InterfaceComparator.get_output_codes() codes += InterfaceParser.get_output_codes() # Parse command line arguments. parser = argparse.ArgumentParser(description="Comparing D-Bus interface definitions") parser.add_argument("old_file", type=str, help="Old interface XML file") parser.add_argument("new_file", type=str, help="New interface XML file") parser.add_argument( "--file-display-name", dest="file_display_name", type=str, help="Human-readable name for new interface XML file " "(if --new-file is a pipe, for example)", ) parser.add_argument( "--fatal-warnings", action="store_const", const=True, default=False, help="Treat all warnings as fatal" ) parser.add_argument( "--warnings", dest="warnings", metavar="CATEGORY,…", type=str, help="Warning categories (%s; %s)" % (", ".join(WARNING_CATEGORIES), ", ".join(codes)), ) args = parser.parse_args() if not args.old_file or not args.new_file: parser.print_help() sys.exit(1) if args.warnings is None or args.warnings == "all": # Enable all warnings by default warnings_args = WARNING_CATEGORIES elif args.warnings == "none": warnings_args = [] else: warnings_args = args.warnings.split(",") for warning_arg in warnings_args: if warning_arg[:3] == "no-": warning_arg = warning_arg[3:] if warning_arg not in WARNING_CATEGORIES and warning_arg not in codes: sys.stderr.write("%s: Unrecognized warning ‘%s’.\n" % (sys.argv[0], warning_arg)) parser.print_help() sys.exit(1) enabled_warnings = [arg for arg in warnings_args if arg[:3] != "no-"] disabled_warnings = [arg[3:] for arg in warnings_args if arg[:3] == "no-"] # Parse the two files. old_parser = InterfaceParser(args.old_file) new_parser = InterfaceParser(args.new_file) old_interfaces = _parse_file(args.old_file, old_parser) new_interfaces = _parse_file(args.new_file, new_parser) # Work out the human-readable name of the new XML filename. if args.file_display_name is not None: new_filename = args.file_display_name else: new_filename = args.new_file # Compare the interfaces. comparator = InterfaceComparator(old_interfaces, new_interfaces, enabled_warnings, disabled_warnings, new_filename) out = comparator.compare() _print_output(out) sys.exit(_calculate_exit_status(args, out))
def test_non_empty(self): codes = InterfaceParser.get_output_codes() self.assertNotEqual(codes, [])
def test_unique(self): codes = InterfaceParser.get_output_codes() self.assertEqual(len(codes), len(set(codes)))
def main(): """Main utility implementation.""" codes = InterfaceComparator.get_output_codes() codes += InterfaceParser.get_output_codes() # Parse command line arguments. parser = argparse.ArgumentParser( description='Comparing D-Bus interface definitions') parser.add_argument('old_file', type=str, help='Old interface XML file') parser.add_argument('new_file', type=str, help='New interface XML file') parser.add_argument('--file-display-name', dest='file_display_name', type=str, help='Human-readable name for new interface XML file ' '(if --new-file is a pipe, for example)') parser.add_argument('--fatal-warnings', action='store_const', const=True, default=False, help='Treat all warnings as fatal') parser.add_argument('--warnings', dest='warnings', metavar='CATEGORY,…', type=str, help='Warning categories (%s; %s)' % (', '.join(WARNING_CATEGORIES), ', '.join(codes))) args = parser.parse_args() if not args.old_file or not args.new_file: parser.print_help() sys.exit(1) if args.warnings is None or args.warnings == 'all': # Enable all warnings by default warnings_args = WARNING_CATEGORIES elif args.warnings == 'none': warnings_args = [] else: warnings_args = args.warnings.split(',') for warning_arg in warnings_args: if warning_arg[:3] == 'no-': warning_arg = warning_arg[3:] if warning_arg not in WARNING_CATEGORIES and warning_arg not in codes: sys.stderr.write('%s: Unrecognized warning ‘%s’.\n' % (sys.argv[0], warning_arg)) parser.print_help() sys.exit(1) enabled_warnings = [arg for arg in warnings_args if arg[:3] != 'no-'] disabled_warnings = [arg[3:] for arg in warnings_args if arg[:3] == 'no-'] # Parse the two files. old_parser = InterfaceParser(args.old_file) new_parser = InterfaceParser(args.new_file) old_interfaces = _parse_file(args.old_file, old_parser) new_interfaces = _parse_file(args.new_file, new_parser) # Work out the human-readable name of the new XML filename. if args.file_display_name is not None: new_filename = args.file_display_name else: new_filename = args.new_file # Compare the interfaces. comparator = InterfaceComparator(old_interfaces, new_interfaces, enabled_warnings, disabled_warnings, new_filename) out = comparator.compare() _print_output(out) sys.exit(_calculate_exit_status(args, out))