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 57: Line 57:
         # Add some problematic non-parsable classes.
         # Add some problematic non-parsable classes.
         if self.category_subsystems:
         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", root_path=self.root_path("src/FDM/SP/AISim.hpp"), xml=self.output_xml))
             self.subsystems[1].append(Subsystem("FGAISim", base_class=Subsystem("FGInterface", base_class=Subsystem("SGSubsystem")), declaration_file="src/FDM/SP/AISim.hpp", root_path=self.root_path("src/FDM/SP/AISim.hpp"), full_path=self.output_full_path, xml=self.output_xml))


         # Find all SGSubsystem and SGSubsystemGroup derived classes.
         # Find all SGSubsystem and SGSubsystemGroup derived classes.
Line 123: Line 123:
         for subsystem in self.subsystems[0] + self.subsystems[1] + self.subsystems[2] + self.subsystems[3] + self.groups[0] + self.groups[1] + self.groups[2] + self.groups[3]:
         for subsystem in self.subsystems[0] + self.subsystems[1] + self.subsystems[2] + self.subsystems[3] + self.groups[0] + self.groups[1] + self.groups[2] + self.groups[3]:
             # The repository location.
             # The repository location.
             if self.is_simgear(subsystem.declaration_file_rel):
             if self.is_simgear(subsystem.declaration_file):
                 path = SIMGEAR_PATH
                 path = SIMGEAR_PATH
             else:
             else:
Line 222: Line 222:
             if class_name in skip:
             if class_name in skip:
                 continue
                 continue
             primary.append(Subsystem(class_name, base_class=base, declaration_file=file_name, root_path=self.root_path(file_name), xml=self.output_xml))
             primary.append(Subsystem(class_name, base_class=base, declaration_file=file_name, root_path=self.root_path(file_name), full_path=self.output_full_path, xml=self.output_xml))


         # Sort the subsystems by name.
         # Sort the subsystems by name.
Line 246: Line 246:
         # Loop over all primary subsystems.
         # Loop over all primary subsystems.
         for subsystem in primary:
         for subsystem in primary:
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name, simgear=self.is_simgear(subsystem.declaration_file_rel)):
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name, simgear=self.is_simgear(subsystem.declaration_file)):
                 secondary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, root_path=self.root_path(file_name), xml=self.output_xml))
                 secondary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, root_path=self.root_path(file_name), full_path=self.output_full_path, xml=self.output_xml))


         # Sort the subsystems by name.
         # Sort the subsystems by name.
Line 271: Line 271:
         # Loop over all secondary subsystems.
         # Loop over all secondary subsystems.
         for subsystem in secondary:
         for subsystem in secondary:
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name, simgear=self.is_simgear(subsystem.declaration_file_rel)):
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name, simgear=self.is_simgear(subsystem.declaration_file)):
                 tertiary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, root_path=self.root_path(file_name), xml=self.output_xml))
                 tertiary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, root_path=self.root_path(file_name), full_path=self.output_full_path, xml=self.output_xml))


         # Sort all subsystems by name.
         # Sort all subsystems by name.
Line 296: Line 296:
         # Loop over all tertiary subsystems.
         # Loop over all tertiary subsystems.
         for subsystem in tertiary:
         for subsystem in tertiary:
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name, simgear=self.is_simgear(subsystem.declaration_file_rel)):
             for file_name, derived_class in self.grep(path=path, base_name=subsystem.name, simgear=self.is_simgear(subsystem.declaration_file)):
                 quaternary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, root_path=self.root_path(file_name), xml=self.output_xml))
                 quaternary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, root_path=self.root_path(file_name), full_path=self.output_full_path, xml=self.output_xml))


         # Sort all subsystems by name.
         # Sort all subsystems by name.
Line 445: Line 445:
         @type file_name:    str
         @type file_name:    str
         @return:            The root path.
         @return:            The root path.
         @rtype:            None or str
         @rtype:            str
         """
         """


         # The relative or absolute path.
         # The relative or absolute path.
        root_path = None
         if self.is_simgear(file_name):
         if self.output_full_path:
            return SIMGEAR_PATH
            if self.is_simgear(file_name):
        else:
                root_path = SIMGEAR_PATH
            return FLIGHTGEAR_PATH
            else:
                root_path = FLIGHTGEAR_PATH
 
        # Return the root.
        return root_path




Line 471: Line 466:
         for subsystem in self.subsystems[0] + self.subsystems[1] + self.subsystems[2] + self.subsystems[3] + self.groups[0] + self.groups[1] + self.groups[2] + self.groups[3]:
         for subsystem in self.subsystems[0] + self.subsystems[1] + self.subsystems[2] + self.subsystems[3] + self.groups[0] + self.groups[1] + self.groups[2] + self.groups[3]:
             # The repository location.
             # The repository location.
             if self.is_simgear(subsystem.declaration_file_rel):
             if self.is_simgear(subsystem.declaration_file):
                 path = SIMGEAR_PATH
                 path = SIMGEAR_PATH
             else:
             else:
Line 485: Line 480:


             # Loop over each file.
             # Loop over each file.
            print(files)
             for file_name in files:
             for file_name in files:
                 # Extract the contents.
                 # Extract the contents.
Line 513: Line 507:
             for subsystem in subsystem_list:
             for subsystem in subsystem_list:
                 # Code base selections.
                 # Code base selections.
                 if self.is_simgear(subsystem.declaration_file_rel) and not self.output_simgear:
                 if self.is_simgear(subsystem.declaration_file) and not self.output_simgear:
                     continue
                     continue
                 if not self.is_simgear(subsystem.declaration_file_rel) and not self.output_flightgear:
                 if not self.is_simgear(subsystem.declaration_file) and not self.output_flightgear:
                     continue
                     continue


Line 577: Line 571:
         subsystem_groups_flightgear = 0
         subsystem_groups_flightgear = 0
         for subsystem in self.subsystems[0] + self.subsystems[1] + self.subsystems[2] + self.subsystems[3]:
         for subsystem in self.subsystems[0] + self.subsystems[1] + self.subsystems[2] + self.subsystems[3]:
             if self.is_simgear(subsystem.declaration_file_rel):
             if self.is_simgear(subsystem.declaration_file):
                 subsystem_classes_simgear += 1
                 subsystem_classes_simgear += 1
             else:
             else:
                 subsystem_classes_flightgear += 1
                 subsystem_classes_flightgear += 1
         for group in self.groups[0] + self.groups[1] + self.groups[2] + self.groups[3]:
         for group in self.groups[0] + self.groups[1] + self.groups[2] + self.groups[3]:
             if self.is_simgear(group.declaration_file_rel):
             if self.is_simgear(group.declaration_file):
                 subsystem_groups_simgear += 1
                 subsystem_groups_simgear += 1
             else:
             else:
Line 631: Line 625:
     """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, declaration_file=None, implementation_file=None, root_path=None, xml=False):
     def __init__(self, name, base_class=None, declaration_file=None, implementation_file=None, root_path=None, full_path=False, xml=False):
         """Set up the object.
         """Set up the object.


Line 644: Line 638:
         @keyword root_path:            The root path to the files.
         @keyword root_path:            The root path to the files.
         @type root_path:                str
         @type root_path:                str
        @keyword full_path:            A flag which if True will cause the full paths to be shown.
        @type full_path:                bool
         @keyword xml:                  Produce a valid XML representation of the object.
         @keyword xml:                  Produce a valid XML representation of the object.
         @type xml:                      bool
         @type xml:                      bool
         """
         """
        # Initialisation.
        self.staticSubsystemClassId = None


         # Store the data.
         # Store the data.
         self.name = name
         self.name = name
         self.base_class = base_class
         self.base_class = base_class
        self.declaration_file_rel = declaration_file
         self.implementation_file = implementation_file
         self.implementation_file = implementation_file
         if root_path:
         self.declaration_file = declaration_file
            self.declaration_file = root_path + sep + declaration_file
            if implementation_file:
                self.implementation_file = root_path + sep + implementation_file
        else:
            self.declaration_file = declaration_file
         self.root_path = root_path
         self.root_path = root_path
        self.full_path = full_path
         self.xml = xml
         self.xml = xml
        # Data extraction.
        self.info_extraction()




Line 689: Line 686:
         # The subsystem name and inheritance chain.
         # The subsystem name and inheritance chain.
         string = "<%s : %s" % (self.name, inheritance)
         string = "<%s : %s" % (self.name, inheritance)
        # Add the static class ID.
        if self.staticSubsystemClassId:
            string += " staticSubsystemClassId is \"%s\"" % self.staticSubsystemClassId


         # Add the declaration file name.
         # Add the declaration file name.
         string += " declared in \"%s\"" % self.declaration_file
        file = self.declaration_file
        if self.full_path:
            file = self.root_path + sep + self.declaration_file
         string += " declared in \"%s\"" % file


         # Add the implementation file name.
         # Add the implementation file name.
         if self.implementation_file:
         if self.implementation_file:
             string += ", implemented in \"%s\"" % self.implementation_file
            file = self.implementation_file
            if self.full_path:
                file = self.root_path + sep + self.implementation_file
             string += ", implemented in \"%s\"" % file


         # Closure.
         # Closure.
Line 718: Line 725:
         # The inheritance chain.
         # The inheritance chain.
         string += "  <inheritance>%s</inheritance>\n" % inheritance
         string += "  <inheritance>%s</inheritance>\n" % inheritance
        # Add the static class ID.
        if self.staticSubsystemClassId:
            string += "  <staticSubsystemClassId>%s</staticSubsystemClassId>\n" % self.staticSubsystemClassId


         # Add the declaration file name.
         # Add the declaration file name.
         string += "  <declaration>%s</declaration>\n" % self.declaration_file
        file = self.declaration_file
        if self.full_path:
            file = self.root_path + sep + self.declaration_file
         string += "  <declaration>%s</declaration>\n" % file


         # Add the implementation file name.
         # Add the implementation file name.
         if self.implementation_file:
         if self.implementation_file:
             string += "  <implementation>%s</implementation>\n" % self.implementation_file
            file = self.implementation_file
            if self.full_path:
                file = self.root_path + sep + self.implementation_file
             string += "  <implementation>%s</implementation>\n" % file


         # End.
         # End.
Line 742: Line 759:
         # Store the file.
         # Store the file.
         self.implementation_file = implementation_file
         self.implementation_file = implementation_file
    def info_extraction(self):
        """Extract subsystem information from the source files."""
        # No declaration.
        if not self.declaration_file:
            return
        # Open the declaration file.
        file = open(self.root_path + sep + self.declaration_file)
        lines = file.readlines()
        file.close()
        # Loop over the file contents.
        for i in range(len(lines)):
            # The static subsystem class ID.
            if search("static const char\* staticSubsystemClassId()", lines[i]):
                id = lines[i].split("return \"")[1]
                id = id.split("\"")[0]
                self.staticSubsystemClassId = id





Revision as of 21:16, 4 May 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: