User:Bugman/subsystems: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(→‎All subsystems: Converted to the XML output.)
(→‎Script: Update of the script to include XML output.)
Line 30: Line 30:
     def __init__(self):
     def __init__(self):
         """Find all subsystems and subsystem groups."""
         """Find all subsystems and subsystem groups."""
        # Command line options.
        self.xml = False
        if len(sys.argv) == 2 and sys.argv[1] == "--xml":
            self.xml = True


         # SGSubsystem storage lists.
         # SGSubsystem storage lists.
Line 36: Line 41:


         # The base objects.
         # The base objects.
         subsystem_base = Subsystem("SGSubsystem")
         subsystem_base = Subsystem("SGSubsystem", xml=self.xml)
         group_base = Subsystem("SGSubsystemGroup", base_class=Subsystem("SGSubsystem"))
         group_base = Subsystem("SGSubsystemGroup", base_class=Subsystem("SGSubsystem"), xml=self.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")), file_name="src/FDM/SP/AISim.hpp"))
         self.subsystems[1].append(Subsystem("FGAISim", base_class=Subsystem("FGInterface", base_class=Subsystem("SGSubsystem")), file_name="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.
Line 59: Line 68:


         # Final summary.
         # Final summary.
         print("\nTotal: %i subsystem classes." % len(self.subsystems[0] + self.subsystems[1] + self.subsystems[2] + self.subsystems[3]))
         if self.xml:
        print("Total: %i subsystem groups." % len(self.groups[0] + self.groups[1] + self.groups[2] + self.groups[3]))
            print("<total subsystem_classes=\"%i\" subsystem_groups=\"%i\"/>" % (len(self.subsystems[0] + self.subsystems[1] + self.subsystems[2] + self.subsystems[3]), len(self.groups[0] + self.groups[1] + self.groups[2] + self.groups[3])))
        else:
            print("\nTotal: %i subsystem classes." % len(self.subsystems[0] + self.subsystems[1] + self.subsystems[2] + self.subsystems[3]))
            print("Total: %i subsystem groups." % len(self.groups[0] + self.groups[1] + self.groups[2] + self.groups[3]))
 
        # XML end.
        if self.xml:
            print("</subsystems>")




Line 108: Line 124:
             if class_name in skip:
             if class_name in skip:
                 continue
                 continue
             primary.append(Subsystem(class_name, base_class=base, file_name=file_name))
             primary.append(Subsystem(class_name, base_class=base, file_name=file_name, xml=self.xml))


         # Sort the subsystems by name.
         # Sort the subsystems by name.
Line 116: Line 132:
         if printout:
         if printout:
             counts = self.count(primary)
             counts = self.count(primary)
             print("\nPrimary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
             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:
             for subsystem in primary:
                 print("    %s" % subsystem)
                 print("    %s" % subsystem)
            if self.xml:
                print("  </primary_%s>" % text)




Line 139: Line 160:
         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, file_name=file_name))
                 secondary.append(Subsystem(derived_class, base_class=subsystem, file_name=file_name, xml=self.xml))


         # Sort the subsystems by name.
         # Sort the subsystems by name.
Line 147: Line 168:
         if printout and secondary:
         if printout and secondary:
             counts = self.count(secondary)
             counts = self.count(secondary)
             print("\nSecondary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
             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:
             for subsystem in secondary:
                 print("    %s" % subsystem)
                 print("    %s" % subsystem)
            if self.xml:
                print("  </secondary_%s>" % text)




Line 170: Line 196:
         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, file_name=file_name))
                 tertiary.append(Subsystem(derived_class, base_class=subsystem, file_name=file_name, xml=self.xml))


         # Sort all subsystems by name.
         # Sort all subsystems by name.
Line 178: Line 204:
         if printout and tertiary:
         if printout and tertiary:
             counts = self.count(tertiary)
             counts = self.count(tertiary)
             print("\nTertiary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
             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:
             for subsystem in tertiary:
                 print("    %s" % subsystem)
                 print("    %s" % subsystem)
            if self.xml:
                print("  </tertiary_%s>" % text)




Line 201: Line 232:
         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, file_name=file_name))
                 quaternary.append(Subsystem(derived_class, base_class=subsystem, file_name=file_name, xml=self.xml))


         # Sort all subsystems by name.
         # Sort all subsystems by name.
Line 209: Line 240:
         if printout and quaternary:
         if printout and quaternary:
             counts = self.count(quaternary)
             counts = self.count(quaternary)
             print("\nQuaternary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
             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:
             for subsystem in quaternary:
                 print("    %s" % subsystem)
                 print("    %s" % subsystem)
            if self.xml:
                print("  </quaternary_%s>" % text)




Line 226: Line 262:


         # The Unix grep command to run.
         # The Unix grep command to run.
         cmd = 'cd %s; grep -rI "public \<%s\>" {{!}} grep -v "%s::"' % (path, base_name, base_name)
         cmd = 'cd %s; grep -rI "public \<%s\>" | grep -v "%s::"' % (path, base_name, base_name)
         pipe = Popen(cmd, shell=True, stdout=PIPE)
         pipe = Popen(cmd, shell=True, stdout=PIPE)


Line 260: Line 296:
     """Object for storing the information for a specific subsystem."""
     """Object for storing the information for a specific subsystem."""


     def __init__(self, name, base_class=None, file_name=None):
     def __init__(self, name, base_class=None, file_name=None, xml=False):
         """Set up the object.
         """Set up the object.


Line 269: Line 305:
         @keyword file_name:    The name of the file containing the subsystem declaration.
         @keyword file_name:    The name of the file containing the subsystem declaration.
         @type file_name:        str
         @type file_name:        str
        @keyword xml:          Produce a valid XML representation of the object.
        @type xml:              bool
         """
         """


Line 275: Line 313:
         self.base_class = base_class
         self.base_class = base_class
         self.file_name = file_name
         self.file_name = file_name
        self.xml = xml




Line 289: Line 328:
         # The inheritance chain.
         # The inheritance chain.
         if self.base_class:
         if self.base_class:
             string += " : %s" % self.base_class.name
             if self.xml:
                string += " from=\""
            else:
                string += " : "
            string += "%s" % self.base_class.name
             if self.base_class.base_class:
             if self.base_class.base_class:
                 string += " : %s" % self.base_class.base_class.name
                 string += " : %s" % self.base_class.base_class.name
Line 298: Line 341:
                         if self.base_class.base_class.base_class.base_class.base_class:
                         if self.base_class.base_class.base_class.base_class.base_class:
                             string += " : %s" % self.base_class.base_class.base_class.base_class.base_class.name
                             string += " : %s" % self.base_class.base_class.base_class.base_class.base_class.name
            if self.xml:
                string += "\""


         # Add the source file name.
         # Add the source file name.
         string += " in %s" % repr(self.file_name)
         if self.xml:
            string += " in="
        else:
            string += " in "
        string += "\"%s\"" % self.file_name


         # Closure.
         # Closure.
        if self.xml:
            string += "/"
         string += ">"
         string += ">"



Revision as of 12:29, 18 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: