User:Bugman/subsystems: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(→‎Script: Yet another script update.)
(→‎Script: Another version.)
Line 58: Line 58:
         # 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))
         self.subsystems[1].append(Subsystem("FGAISim", base_class=Subsystem("FGInterface", base_class=Subsystem("SGSubsystem")), declaration_file="src/FDM/SP/AISim.hpp", xml=self.xml))
        # XML start.
        if self.xml:
            print("<subsystems>")


         # Find all SGSubsystem and SGSubsystemGroup derived classes.
         # Find all SGSubsystem and SGSubsystemGroup derived classes.
         paths = [SIMGEAR_PATH, FLIGHTGEAR_PATH]
         paths = [SIMGEAR_PATH, FLIGHTGEAR_PATH]
        printout = [False, True]
         for path in paths:
         for i in range(len(paths)):
             self.find_primary(path=path, text="classes", primary=self.subsystems[0], base_name="SGSubsystem", base=subsystem_base, skip=["SGSubsystemGroup"])
             self.find_primary(path=paths[i], text="classes", primary=self.subsystems[0], base_name="SGSubsystem", base=subsystem_base, skip=["SGSubsystemGroup"], printout=printout[i])
             self.find_primary(path=path, text="groups", primary=self.groups[0], base_name="SGSubsystemGroup", base=group_base)
             self.find_primary(path=paths[i], text="groups", primary=self.groups[0], base_name="SGSubsystemGroup", base=group_base, printout=printout[i])


             self.find_secondary(path=paths[i], text="classes", primary=self.subsystems[0], secondary=self.subsystems[1], printout=printout[i])
             self.find_secondary(path=path, text="classes", primary=self.subsystems[0], secondary=self.subsystems[1])
             self.find_secondary(path=paths[i], text="groups", primary=self.groups[0], secondary=self.groups[1], printout=printout[i])
             self.find_secondary(path=path, text="groups", primary=self.groups[0], secondary=self.groups[1])


             self.find_tertiary(path=paths[i], text="classes", secondary=self.subsystems[1], tertiary=self.subsystems[2], printout=printout[i])
             self.find_tertiary(path=path, text="classes", secondary=self.subsystems[1], tertiary=self.subsystems[2])
             self.find_tertiary(path=paths[i], text="groups", secondary=self.groups[1], tertiary=self.groups[2], printout=printout[i])
             self.find_tertiary(path=path, text="groups", secondary=self.groups[1], tertiary=self.groups[2])


             self.find_quaternary(path=paths[i], text="classes", tertiary=self.subsystems[2], quaternary=self.subsystems[3], printout=printout[i])
             self.find_quaternary(path=path, text="classes", tertiary=self.subsystems[2], quaternary=self.subsystems[3])
             self.find_quaternary(path=paths[i], text="groups", tertiary=self.groups[2], quaternary=self.groups[3], printout=printout[i])
             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 84: Line 79:
         # Final summary.
         # Final summary.
         self.summarise()
         self.summarise()
        # XML end.
        if self.xml:
            print("</subsystems>")




Line 145: Line 136:
                     # Search.
                     # Search.
                     for cmd in cmds:
                     for cmd in cmds:
                        print(cmd)
                         pipe = Popen(cmd, shell=True, stdout=PIPE)
                         pipe = Popen(cmd, shell=True, stdout=PIPE)
                         lines = pipe.stdout.readlines()
                         lines = pipe.stdout.readlines()
Line 162: Line 152:
                 # Search.
                 # Search.
                 for cmd in cmds:
                 for cmd in cmds:
                    print(cmd)
                     pipe = Popen(cmd, shell=True, stdout=PIPE)
                     pipe = Popen(cmd, shell=True, stdout=PIPE)


Line 187: Line 176:




     def find_primary(self, path=None, text=None, primary=None, base_name=None, base=None, skip=[], printout=False):
     def find_primary(self, path=None, text=None, primary=None, base_name=None, base=None, skip=[]):
         """Find all primary subsystems and groups
         """Find all primary subsystems and groups


Line 202: Line 191:
         @keyword skip:      A list of class names to skip.
         @keyword skip:      A list of class names to skip.
         @type skip:        list of str
         @type skip:        list of str
        @keyword printout:  A flag which if True will activate the printout of subsystems.
        @type printout:    bool
         """
         """


         # Printout.
         # Printout.
        sys.stderr.write("Finding all primary %s in: %s\n" % (text, path))
         # Find all subsystems or groups.
         # Find all subsystems or groups.
         for file_name, class_name in self.grep(path=path, base_name=base_name):
         for file_name, class_name in self.grep(path=path, base_name=base_name):
Line 215: Line 204:
         # Sort the subsystems by name.
         # Sort the subsystems by name.
         primary.sort(key=operator.attrgetter('name'))
         primary.sort(key=operator.attrgetter('name'))
        # Printout.
        if printout:
            counts = self.count(primary)
            if self.xml:
                print("  <primary_%s subsystems=\"%i\" groups=\"%i\">" % (text, counts[0], counts[1]))
            else:
                print("\nPrimary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
            for subsystem in primary:
                print("    %s" % subsystem)
            if self.xml:
                print("  </primary_%s>" % text)




     def find_secondary(self, path=None, text=None, primary=None, secondary=None, printout=False):
     def find_secondary(self, path=None, text=None, primary=None, secondary=None):
         """Find all secondary subsystems and groups
         """Find all secondary subsystems and groups


Line 240: Line 217:
         @keyword secondary: The secondary list of subsystems or groups.
         @keyword secondary: The secondary list of subsystems or groups.
         @type secondary:    list of Subsystem instances
         @type secondary:    list of Subsystem instances
        @keyword printout:  A flag which if True will activate the printout of subsystems.
        @type printout:    bool
         """
         """
        # Printout.
        sys.stderr.write("Finding all secondary %s in: %s\n" % (text, path))


         # Loop over all primary subsystems.
         # Loop over all primary subsystems.
Line 252: Line 230:
         secondary.sort(key=operator.attrgetter('name'))
         secondary.sort(key=operator.attrgetter('name'))


        # Printout.
        if printout and secondary:
            counts = self.count(secondary)
            if self.xml:
                print("  <secondary_%s subsystems=\"%i\" groups=\"%i\">" % (text, counts[0], counts[1]))
            else:
                print("\nSecondary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
            for subsystem in secondary:
                print("    %s" % subsystem)
            if self.xml:
                print("  </secondary_%s>" % text)


 
     def find_tertiary(self, path=None, text=None, secondary=None, tertiary=None):
     def find_tertiary(self, path=None, text=None, secondary=None, tertiary=None, printout=False):
         """Find all tertiary subsystems and groups
         """Find all tertiary subsystems and groups


Line 276: Line 242:
         @keyword tertiary:  The tertiary list of subsystems or groups.
         @keyword tertiary:  The tertiary list of subsystems or groups.
         @type tertiary:    list of Subsystem instances
         @type tertiary:    list of Subsystem instances
        @keyword printout:  A flag which if True will activate the printout of subsystems.
        @type printout:    bool
         """
         """
        # Printout.
        sys.stderr.write("Finding all tertiary %s in: %s\n" % (text, path))


         # Loop over all secondary subsystems.
         # Loop over all secondary subsystems.
Line 287: Line 254:
         # Sort all subsystems by name.
         # Sort all subsystems by name.
         tertiary.sort(key=operator.attrgetter('name'))
         tertiary.sort(key=operator.attrgetter('name'))
        # Printout.
        if printout and tertiary:
            counts = self.count(tertiary)
            if self.xml:
                print("  <tertiary_%s subsystems=\"%i\" groups=\"%i\">" % (text, counts[0], counts[1]))
            else:
                print("\nTertiary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
            for subsystem in tertiary:
                print("    %s" % subsystem)
            if self.xml:
                print("  </tertiary_%s>" % text)




     def find_quaternary(self, path=None, text=None, tertiary=None, quaternary=None, printout=False):
     def find_quaternary(self, path=None, text=None, tertiary=None, quaternary=None):
         """Find all tertiary subsystems and groups
         """Find all quaternary subsystems and groups


         @keyword path:          The path to the repository to search through.
         @keyword path:          The path to the repository to search through.
Line 312: Line 267:
         @keyword quaternary:    The quaternary list of subsystems or groups.
         @keyword quaternary:    The quaternary list of subsystems or groups.
         @type quaternary:      list of Subsystem instances
         @type quaternary:      list of Subsystem instances
        @keyword printout:      A flag which if True will activate the printout of subsystems.
        @type printout:        bool
         """
         """
        # Printout.
        sys.stderr.write("Finding all quaternary %s in: %s\n" % (text, path))


         # Loop over all tertiary subsystems.
         # Loop over all tertiary subsystems.
Line 323: Line 279:
         # Sort all subsystems by name.
         # Sort all subsystems by name.
         quaternary.sort(key=operator.attrgetter('name'))
         quaternary.sort(key=operator.attrgetter('name'))
        # Printout.
        if printout and quaternary:
            counts = self.count(quaternary)
            if self.xml:
                print("  <quaternary_%s subsystems=\"%i\" groups=\"%i\">" % (text, counts[0], counts[1]))
            else:
                print("\nQuaternary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
            for subsystem in quaternary:
                print("    %s" % subsystem)
            if self.xml:
                print("  </quaternary_%s>" % text)




Line 363: Line 307:
             # Cannot handle this line!
             # Cannot handle this line!
             if not search("class ", line):
             if not search("class ", line):
                 sys.stderr.write("\nSkipping: %s\n" % repr(line[:-1]))
                 sys.stderr.write("Skipping: %s\n" % repr(line[:-1]))
                 continue
                 continue


Line 381: Line 325:
     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."""
        # XML start.
        if self.xml:
            print("<subsystems>")
        # Subsystem and group printouts.
        labels = ["primary", "secondary", "tertiary", "quaternary"]
        labels2 = ["Primary", "Secondary", "Tertiary", "Quaternary"]
        classes = ["subsystems", "groups"]
        for i in range(len(self.subsystems)):
            for j in range(len(classes)):
                if classes[j] == "subsystems":
                    subsystem_list = self.subsystems[i]
                else:
                    subsystem_list = self.groups[i]
                # Nothing in the list.
                if not len(subsystem_list):
                    continue
                # Count all.
                counts = self.count(subsystem_list)
                # Start.
                if self.xml:
                    print("  <%s_%s count=\"%i\">" % (labels[i], classes[j], counts[j]))
                else:
                    print("\n%s %s (%i):" % (labels2[i], classes[j], counts[j]))
                # Subsystems.
                for subsystem in subsystem_list:
                    print("    %s" % (subsystem))
                # End.
                if self.xml:
                    print("  </%s_%s>" % (labels[i], classes[j]))


         # Counts.
         # Counts.
Line 406: Line 386:
         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
        # Printout.
         if self.xml:
         if self.xml:
             print("  <counts>")
             print("  <counts>")
Line 430: Line 408:
             print("Counts: %i subsystem groups (%i flightgear, %i simgear)." % (subsystem_groups, subsystem_groups_flightgear, subsystem_groups_simgear))
             print("Counts: %i subsystem groups (%i flightgear, %i simgear)." % (subsystem_groups, subsystem_groups_flightgear, subsystem_groups_simgear))
             print("Counts: %i subsystem classes and groups (%i flightgear, %i simgear)." % (subsystem_total, flightgear_total, simgear_total))
             print("Counts: %i subsystem classes and groups (%i flightgear, %i simgear)." % (subsystem_total, flightgear_total, simgear_total))
        # XML end.
        if self.xml:
            print("</subsystems>")





Revision as of 18:58, 19 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: