User:Bugman/subsystems: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(→‎All subsystems: Updated the output to match the newest script.)
(→‎Script: Newest version of the script.)
Line 14: Line 14:


# Python module imports.
# Python module imports.
from argparse import ArgumentParser
import operator
import operator
from os import access, F_OK, sep
from os import access, F_OK, sep
Line 39: Line 40:


         # Command line options.
         # Command line options.
         self.xml = False
         self.parse_arguments()
        if len(sys.argv) == 2 and sys.argv[1] == "--xml":
            self.xml = True


         # SGSubsystem storage lists.
         # SGSubsystem storage lists.
Line 53: Line 52:


         # The base objects.
         # The base objects.
         subsystem_base = Subsystem("SGSubsystem", xml=self.xml)
         subsystem_base = Subsystem("SGSubsystem", xml=self.output_xml)
         group_base = Subsystem("SGSubsystemGroup", base_class=Subsystem("SGSubsystem"), xml=self.xml)
         group_base = Subsystem("SGSubsystemGroup", base_class=Subsystem("SGSubsystem"), xml=self.output_xml)


         # Add some problematic non-parsable classes.
         # Add some problematic non-parsable classes.
         self.subsystems[1].append(Subsystem("FGAISim", base_class=Subsystem("FGInterface", base_class=Subsystem("SGSubsystem")), declaration_file="src/FDM/SP/AISim.hpp", xml=self.xml))
         if self.category_subsystems:
            self.subsystems[1].append(Subsystem("FGAISim", base_class=Subsystem("FGInterface", base_class=Subsystem("SGSubsystem")), declaration_file="src/FDM/SP/AISim.hpp", xml=self.output_xml))


         # Find all SGSubsystem and SGSubsystemGroup derived classes.
         # Find all SGSubsystem and SGSubsystemGroup derived classes.
         paths = [SIMGEAR_PATH, FLIGHTGEAR_PATH]
         paths = [SIMGEAR_PATH, FLIGHTGEAR_PATH]
         for path in paths:
         for path in paths:
             self.find_primary(path=path, text="classes", primary=self.subsystems[0], base_name="SGSubsystem", base=subsystem_base, skip=["SGSubsystemGroup"])
             if self.category_subsystems:
             self.find_primary(path=path, text="groups", primary=self.groups[0], base_name="SGSubsystemGroup", base=group_base)
                self.find_primary(path=path, text="classes", primary=self.subsystems[0], base_name="SGSubsystem", base=subsystem_base, skip=["SGSubsystemGroup"])
             if self.category_groups:
                self.find_primary(path=path, text="groups", primary=self.groups[0], base_name="SGSubsystemGroup", base=group_base)


             self.find_secondary(path=path, text="classes", primary=self.subsystems[0], secondary=self.subsystems[1])
             if self.category_subsystems:
             self.find_secondary(path=path, text="groups", primary=self.groups[0], secondary=self.groups[1])
                self.find_secondary(path=path, text="classes", primary=self.subsystems[0], secondary=self.subsystems[1])
             if self.category_groups:
                self.find_secondary(path=path, text="groups", primary=self.groups[0], secondary=self.groups[1])


             self.find_tertiary(path=path, text="classes", secondary=self.subsystems[1], tertiary=self.subsystems[2])
             if self.category_subsystems:
             self.find_tertiary(path=path, text="groups", secondary=self.groups[1], tertiary=self.groups[2])
                self.find_tertiary(path=path, text="classes", secondary=self.subsystems[1], tertiary=self.subsystems[2])
             if self.category_groups:
                self.find_tertiary(path=path, text="groups", secondary=self.groups[1], tertiary=self.groups[2])


             self.find_quaternary(path=path, text="classes", tertiary=self.subsystems[2], quaternary=self.subsystems[3])
             if self.category_subsystems:
             self.find_quaternary(path=path, text="groups", tertiary=self.groups[2], quaternary=self.groups[3])
                self.find_quaternary(path=path, text="classes", tertiary=self.subsystems[2], quaternary=self.subsystems[3])
             if self.category_groups:
                self.find_quaternary(path=path, text="groups", tertiary=self.groups[2], quaternary=self.groups[3])


         # Find the subsystem and subsystem group implementation files.
         # Find the subsystem and subsystem group implementation files.
Line 127: Line 135:
                 file_name = subsystem.declaration_file[:-3] + "cxx"
                 file_name = subsystem.declaration_file[:-3] + "cxx"
                 full_path = path + sep + file_name
                 full_path = path + sep + file_name
                 if access(full_path, F_OK):  
                 if access(full_path, F_OK):
                     # The Unix grep commands to run.
                     # The Unix grep commands to run.
                     cmds = [
                     cmds = [
Line 200: Line 208:
             if class_name in skip:
             if class_name in skip:
                 continue
                 continue
             primary.append(Subsystem(class_name, base_class=base, declaration_file=file_name, xml=self.xml))
             primary.append(Subsystem(class_name, base_class=base, declaration_file=file_name, xml=self.output_xml))


         # Sort the subsystems by name.
         # Sort the subsystems by name.
Line 225: Line 233:
         for subsystem in primary:
         for subsystem in primary:
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name):
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name):
                 secondary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, xml=self.xml))
                 secondary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, xml=self.output_xml))


         # Sort the subsystems by name.
         # Sort the subsystems by name.
Line 250: Line 258:
         for subsystem in secondary:
         for subsystem in secondary:
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name):
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name):
                 tertiary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, xml=self.xml))
                 tertiary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, xml=self.output_xml))


         # Sort all subsystems by name.
         # Sort all subsystems by name.
Line 275: Line 283:
         for subsystem in tertiary:
         for subsystem in tertiary:
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name):
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name):
                 quaternary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, xml=self.xml))
                 quaternary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, xml=self.output_xml))


         # Sort all subsystems by name.
         # Sort all subsystems by name.
Line 321: Line 329:
             # Generator method.
             # Generator method.
             yield file_name, class_name
             yield file_name, class_name
    def parse_arguments(self):
        """Parse the command line arguments."""
        # The argument parser.
        parser = ArgumentParser()
        # The output arguments.
        group = parser.add_mutually_exclusive_group()
        group.add_argument("-t", "--text", default=False, action="store_true", help="Output in plain text format (the default).")
        group.add_argument("-x", "--xml", default=False, action="store_true", help="Output in XML format.")
        group.add_argument("-f", "--files", default=False, action="store_true", help="List all declaration and/or implementation files.")
        group.add_argument("-d", "--declaration-files", default=False, action="store_true", help="List the files where subsystems and subsystem groups are declared.")
        group.add_argument("-i", "--implementation-files", default=False, action="store_true", help="List the files where subsystems and subsystem groups are implemented.")
        # Category selection.
        group = parser.add_argument_group("category selections", "Choose between subsystems and subsystem groups.")
        group.add_argument("-n", "--no-groups", default=False, action="store_true", help="Skip subsystem groups.")
        group.add_argument("-g", "--groups", default=False, action="store_true", help="Only process subsystem groups.")
        # Parse the arguments.
        args = parser.parse_args()
        # The output arguments.
        self.output_xml = args.xml
        self.output_format = "text"
        if args.text:
            self.output_format = "text"
        elif args.xml:
            self.output_format = "xml"
        elif args.files:
            self.output_format = "files"
        elif args.declaration_files:
            self.output_format = "declaration files"
        elif args.implementation_files:
            self.output_format = "implementation files"
        # The category arguments.
        self.category_subsystems = True
        self.category_groups = True
        if args.groups:
            self.category_subsystems = False
        if args.no_groups:
            self.category_groups = False




     def summarise(self):
     def summarise(self):
         """Print out a summary of all found subsystems and subsystem groups."""
         """Print out a summary of all found subsystems and subsystem groups."""
        # Basic file listings.
        if self.output_format in ["files", "declaration files", "implementation files"]:
            # Concatenate the lists.
            subsystem_list = []
            if self.category_subsystems:
                subsystem_list += self.subsystems[0] + self.subsystems[1] + self.subsystems[2] + self.subsystems[3]
            if self.category_groups:
                subsystem_list += self.groups[0] + self.groups[1] + self.groups[2] + self.groups[3]
            # Loop over each subsystem, printing out the source files.
            for subsystem in subsystem_list:
                if self.output_format in ["files", "declaration files"]:
                    print(subsystem.declaration_file)
                if self.output_format in ["files", "implementation files"]:
                    if subsystem.implementation_file:
                        print(subsystem.implementation_file)
            # Skip the rest of the function.
            return


         # XML start.
         # XML start.
         if self.xml:
         if self.output_xml:
             print("<?xml version=\"1.0\"?>")
             print("<?xml version=\"1.0\"?>")
             print("<subsystems>")
             print("<subsystems>")
Line 350: Line 423:


                 # Start.
                 # Start.
                 if self.xml:
                 if self.output_xml:
                     print("  <%s_%s count=\"%i\">" % (labels[i], classes[j], counts[j]))
                     print("  <%s_%s count=\"%i\">" % (labels[i], classes[j], counts[j]))
                 else:
                 else:
Line 361: Line 434:


                 # End.
                 # End.
                 if self.xml:
                 if self.output_xml:
                     print("  </%s_%s>" % (labels[i], classes[j]))
                     print("  </%s_%s>" % (labels[i], classes[j]))


Line 388: Line 461:
         simgear_total = subsystem_classes_simgear + subsystem_groups_simgear
         simgear_total = subsystem_classes_simgear + subsystem_groups_simgear
         flightgear_total = subsystem_classes_flightgear + subsystem_groups_flightgear
         flightgear_total = subsystem_classes_flightgear + subsystem_groups_flightgear
         if self.xml:
         if self.output_xml:
             print("  <counts>")
             print("  <counts>")
             print("    <simgear>")
             print("    <simgear>")
             print("      <subsystem_classes>%i</subsystem_classes>" % subsystem_classes_simgear)
             if self.category_subsystems:
             print("      <subsystem_groups>%i</subsystem_groups>" % subsystem_groups_simgear)
                print("      <subsystem_classes>%i</subsystem_classes>" % subsystem_classes_simgear)
             print("      <total>%i</total>" % simgear_total)
             if self.category_groups:
                print("      <subsystem_groups>%i</subsystem_groups>" % subsystem_groups_simgear)
             if self.category_subsystems and self.category_groups:
                print("      <total>%i</total>" % simgear_total)
             print("    </simgear>")
             print("    </simgear>")
             print("    <flightgear>")
             print("    <flightgear>")
             print("      <subsystem_classes>%i</subsystem_classes>" % subsystem_classes_flightgear)
             if self.category_subsystems:
             print("      <subsystem_groups>%i</subsystem_groups>" % subsystem_groups_flightgear)
                print("      <subsystem_classes>%i</subsystem_classes>" % subsystem_classes_flightgear)
             print("      <total>%i</total>" % flightgear_total)
             if self.category_groups:
                print("      <subsystem_groups>%i</subsystem_groups>" % subsystem_groups_flightgear)
             if self.category_subsystems and self.category_groups:
                print("      <total>%i</total>" % flightgear_total)
             print("    </flightgear>")
             print("    </flightgear>")
             print("    <combined>")
             print("    <combined>")
             print("      <subsystem_classes>%i</subsystem_classes>" % subsystem_classes)
             if self.category_subsystems:
             print("      <subsystem_groups>%i</subsystem_groups>" % subsystem_groups)
                print("      <subsystem_classes>%i</subsystem_classes>" % subsystem_classes)
             print("      <total>%i</total>" % subsystem_total)
             if self.category_groups:
                print("      <subsystem_groups>%i</subsystem_groups>" % subsystem_groups)
             if self.category_subsystems and self.category_groups:
                print("      <total>%i</total>" % subsystem_total)
             print("    </combined>")
             print("    </combined>")
             print("  </counts>")
             print("  </counts>")
Line 412: Line 494:


         # XML end.
         # XML end.
         if self.xml:
         if self.output_xml:
             print("</subsystems>")
             print("</subsystems>")



Revision as of 07:46, 20 April 2018

Tracking down subsystems

Script

The following script is for finding all FlightGear dependencies:

All subsystems

The result is:

Refactoring

To check that all subsystems on a branch have been updated or refactored: