User:Bugman/subsystems: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(→‎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", 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"), xml=self.output_xml))


         # Find all SGSubsystem and SGSubsystemGroup derived classes.
         # Find all SGSubsystem and SGSubsystemGroup derived classes.
Line 119: Line 119:
         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 subsystem.declaration_file[:7] == "simgear":
             if self.is_simgear(subsystem.declaration_file):
                 path = SIMGEAR_PATH
                 path = SIMGEAR_PATH
             else:
             else:
Line 149: Line 149:
                         lines = pipe.stdout.readlines()
                         lines = pipe.stdout.readlines()
                         if len(lines):
                         if len(lines):
                             subsystem.implementation_file = file_name
                             subsystem.add_implementation_file(file_name)
                             break
                             break


Line 182: Line 182:
                     # Store the implementation file.
                     # Store the implementation file.
                     elif len(files):
                     elif len(files):
                         subsystem.implementation_file = files[0]
                         subsystem.add_implementation_file(files[0])
                         break
                         break


Line 210: Line 210:
             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.output_xml))
             primary.append(Subsystem(class_name, base_class=base, declaration_file=file_name, root_path=self.root_path(file_name), xml=self.output_xml))


         # Sort the subsystems by name.
         # Sort the subsystems by name.
Line 235: Line 235:
         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.output_xml))
                 secondary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, root_path=self.root_path(file_name), xml=self.output_xml))


         # Sort the subsystems by name.
         # Sort the subsystems by name.
Line 260: Line 260:
         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.output_xml))
                 tertiary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, root_path=self.root_path(file_name), xml=self.output_xml))


         # Sort all subsystems by name.
         # Sort all subsystems by name.
Line 285: Line 285:
         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.output_xml))
                 quaternary.append(Subsystem(derived_class, base_class=subsystem, declaration_file=file_name, root_path=self.root_path(file_name), xml=self.output_xml))


         # Sort all subsystems by name.
         # Sort all subsystems by name.
Line 331: Line 331:
             # Generator method.
             # Generator method.
             yield file_name, class_name
             yield file_name, class_name
    def is_simgear(self, file_name):
        """Determine if the file is from simgear.
        @param file_name:  The name of the file.
        @type file_name:    str
        @return:            True if the file is from simgear, False otherwise.
        @rtype:            bool
        """
        # Basic path check.
        if file_name[:7] == "simgear":
            return True
        return False




Line 340: Line 355:


         # The output arguments.
         # The output arguments.
         group = parser.add_mutually_exclusive_group()
         group = parser.add_argument_group("output arguments", "Change the output format.")
         group.add_argument("-t", "--text", default=False, action="store_true", help="Output in plain text format (the default).")
         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("-x", "--xml", default=False, action="store_true", help="Output in XML format.")
Line 346: Line 361:
         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("-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.")
         group.add_argument("-i", "--implementation-files", default=False, action="store_true", help="List the files where subsystems and subsystem groups are implemented.")
        group.add_argument("-p", "--full-path", default=False, action="store_true", help="For file listings, include the SIMGEAR or FLIGHTGEAR absolute path.")


         # Code base selection.
         # Code base selection.
Line 373: Line 389:
         elif args.implementation_files:
         elif args.implementation_files:
             self.output_format = "implementation files"
             self.output_format = "implementation files"
        self.output_full_path = args.full_path


         # The code base arguments.
         # The code base arguments.
Line 389: Line 406:
         if args.no_groups:
         if args.no_groups:
             self.category_groups = False
             self.category_groups = False
    def root_path(self, file_name):
        """Determine the root for the given file.
        @param file_name:  The name of the file.
        @type file_name:    str
        @return:            The root path.
        @rtype:            None or str
        """
        # The relative or absolute path.
        root_path = None
        if self.output_full_path:
            if self.is_simgear(file_name):
                root_path = SIMGEAR_PATH
            else:
                root_path = FLIGHTGEAR_PATH
        # Return the root.
        return root_path




Line 406: Line 444:
             for subsystem in subsystem_list:
             for subsystem in subsystem_list:
                 # Code base selections.
                 # Code base selections.
                 if subsystem.declaration_file[:7] == "simgear" and not self.output_simgear:
                 if self.is_simgear(subsystem.declaration_file) and not self.output_simgear:
                     continue
                     continue
                 if subsystem.declaration_file[:7] != "simgear" and not self.output_flightgear:
                 if not self.is_simgear(subsystem.declaration_file) and not self.output_flightgear:
                     continue
                     continue


                 # Output the source files.
                 # Output the source files.
                 if self.output_format in ["files", "declaration files"]:
                 if self.output_format in ["files", "declaration files"]:
                     print(subsystem.declaration_file)
                     print("%s" % subsystem.declaration_file)
                 if self.output_format in ["files", "implementation files"]:
                 if self.output_format in ["files", "implementation files"]:
                     if subsystem.implementation_file:
                     if subsystem.implementation_file:
                         print(subsystem.implementation_file)
                         print("%s" % subsystem.implementation_file)


             # Skip the rest of the function.
             # Skip the rest of the function.
Line 470: Line 508:
         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 subsystem.declaration_file[:7] == "simgear":
             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 group.declaration_file[:7] == "simgear":
             if self.is_simgear(group.declaration_file):
                 subsystem_groups_simgear += 1
                 subsystem_groups_simgear += 1
             else:
             else:
Line 524: Line 562:
     """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, xml=False):
     def __init__(self, name, base_class=None, declaration_file=None, implementation_file=None, root_path=None, xml=False):
         """Set up the object.
         """Set up the object.


         @param name:               The name of the subsystem.
         @param name:                   The name of the subsystem.
         @type name:                 str
         @type name:                     str
         @keyword base_class:       The name of the base class.
         @keyword base_class:           The name of the base class.
         @type base_class:           str
         @type base_class:               str
         @keyword declaration_file: The name of the file containing the subsystem declaration.
         @keyword declaration_file:     The name of the file containing the subsystem declaration.
         @type declaration_file:     str
         @type declaration_file:         str
         @keyword implementation_file: The name of the file containing the subsystem declaration.
         @keyword implementation_file:   The name of the file containing the subsystem declaration.
         @type implementation_file:     str
         @type implementation_file:     str or None
         @keyword xml:               Produce a valid XML representation of the object.
        @keyword root_path:            The root path to the files.
         @type xml:                 bool
        @type root_path:                str
         @keyword xml:                   Produce a valid XML representation of the object.
         @type xml:                     bool
         """
         """


Line 542: Line 582:
         self.name = name
         self.name = name
         self.base_class = base_class
         self.base_class = base_class
        self.declaration_file = declaration_file
         self.implementation_file = implementation_file
         self.implementation_file = implementation_file
        if root_path:
            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.xml = xml
         self.xml = xml


Line 615: Line 661:
         # Return the string.
         # Return the string.
         return string
         return string
    def add_implementation_file(self, implementation_file=None):
        """Set up the object.
        @keyword implementation_file:  The name of the file containing the subsystem declaration.
        @type implementation_file:      str or None
        """
        # Store the file.
        if self.root_path:
            self.implementation_file = self.root_path + sep + implementation_file
        else:
            self.implementation_file = implementation_file





Revision as of 08:44, 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: