User:Bugman/subsystems
From FlightGear wiki
< User:Bugman
Jump to navigation
Jump to search
Revision as of 10:10, 18 April 2018 by Bugman (talk | contribs) (→All subsystems: Updated the output to match the newest script.)
Tracking down subsystems
Script
The following script is for finding all FlightGear dependencies:
Python script: Python script for finding all subsystems within the flightgear and simgear C++ code bases.
This script requires the grep Unix command, which can be installed on any OS. And it must be run with Python3.
#! /usr/bin/env python3
# Python module imports.
import operator
from re import search, split
from subprocess import PIPE, Popen
import sys
# Source code repository paths.
SIMGEAR_PATH = "/flightgear/src/flightgear-simgear"
FLIGHTGEAR_PATH = "/flightgear/src/flightgear-flightgear"
class FindSubsystems:
"""Class for finding all subsystems and subsystem groups."""
def __init__(self):
"""Find all subsystems and subsystem groups."""
# SGSubsystem storage lists.
self.subsystems = [[], [], [], []]
self.groups = [[], [], [], []]
# The base objects.
subsystem_base = Subsystem("SGSubsystem")
group_base = Subsystem("SGSubsystemGroup", base_class=Subsystem("SGSubsystem"))
# 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"))
# Find all SGSubsystem and SGSubsystemGroup derived classes.
paths = [SIMGEAR_PATH, FLIGHTGEAR_PATH]
printout = [False, True]
for i in range(len(paths)):
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=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=paths[i], text="groups", primary=self.groups[0], secondary=self.groups[1], printout=printout[i])
self.find_tertiary(path=paths[i], text="classes", secondary=self.subsystems[1], tertiary=self.subsystems[2], printout=printout[i])
self.find_tertiary(path=paths[i], text="groups", secondary=self.groups[1], tertiary=self.groups[2], printout=printout[i])
self.find_quaternary(path=paths[i], text="classes", tertiary=self.subsystems[2], quaternary=self.subsystems[3], printout=printout[i])
self.find_quaternary(path=paths[i], text="groups", tertiary=self.groups[2], quaternary=self.groups[3], printout=printout[i])
# Final summary.
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]))
def count(self, storage_list):
"""Count the number of subsystems and subsystem groups.
@param storage_list: The data structure to count.
@type storage_list: list of Subsystem instances
@return: The number of subsystems and number of groups.
@rtype: int, int
"""
# Init.
subsystems = 0
groups = 0
for element in storage_list:
if element.is_group():
groups += 1
else:
subsystems += 1
# Return the counts.
return subsystems, groups
def find_primary(self, path=None, text=None, primary=None, base_name=None, base=None, skip=[], printout=False):
"""Find all primary subsystems and groups
@keyword path: The path to the repository to search through.
@type path: str
@keyword text: Text identifying subsystems vs. subsystem groups.
@type text: str
@keyword primary: The primary list of subsystems or groups.
@type primary: list of Subsystem instances
@keyword base_name: The name of the base class.
@type base_name: str
@keyword base: The base class object.
@type base: Subsystem instance
@keyword skip: A list of class names to skip.
@type skip: list of str
@keyword printout: A flag which if True will activate the printout of subsystems.
@type printout: bool
"""
# Find all subsystems or groups.
for file_name, class_name in self.grep(path=path, base_name=base_name):
if class_name in skip:
continue
primary.append(Subsystem(class_name, base_class=base, file_name=file_name))
# Sort the subsystems by name.
primary.sort(key=operator.attrgetter('name'))
# Printout.
if printout:
counts = self.count(primary)
print("\nPrimary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
for subsystem in primary:
print(" %s" % subsystem)
def find_secondary(self, path=None, text=None, primary=None, secondary=None, printout=False):
"""Find all secondary subsystems and groups
@keyword path: The path to the repository to search through.
@type path: str
@keyword text: Text identifying subsystems vs. subsystem groups.
@type text: str
@keyword primary: The primary list of subsystems or groups.
@type primary: list of Subsystem instances
@keyword secondary: The secondary list of subsystems or groups.
@type secondary: list of Subsystem instances
@keyword printout: A flag which if True will activate the printout of subsystems.
@type printout: bool
"""
# Loop over all primary subsystems.
for subsystem in primary:
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))
# Sort the subsystems by name.
secondary.sort(key=operator.attrgetter('name'))
# Printout.
if printout and secondary:
counts = self.count(secondary)
print("\nSecondary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
for subsystem in secondary:
print(" %s" % subsystem)
def find_tertiary(self, path=None, text=None, secondary=None, tertiary=None, printout=False):
"""Find all tertiary subsystems and groups
@keyword path: The path to the repository to search through.
@type path: str
@keyword text: Text identifying subsystems vs. subsystem groups.
@type text: str
@keyword secondary: The secondary list of subsystems or groups.
@type secondary: list of Subsystem instances
@keyword tertiary: The tertiary list of subsystems or groups.
@type tertiary: list of Subsystem instances
@keyword printout: A flag which if True will activate the printout of subsystems.
@type printout: bool
"""
# Loop over all secondary subsystems.
for subsystem in secondary:
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))
# Sort all subsystems by name.
tertiary.sort(key=operator.attrgetter('name'))
# Printout.
if printout and tertiary:
counts = self.count(tertiary)
print("\nTertiary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
for subsystem in tertiary:
print(" %s" % subsystem)
def find_quaternary(self, path=None, text=None, tertiary=None, quaternary=None, printout=False):
"""Find all tertiary subsystems and groups
@keyword path: The path to the repository to search through.
@type path: str
@keyword text: Text identifying subsystems vs. subsystem groups.
@type text: str
@keyword tertiary: The tertiary list of subsystems or groups.
@type tertiary: list of Subsystem instances
@keyword quaternary: The quaternary list of subsystems or groups.
@type quaternary: list of Subsystem instances
@keyword printout: A flag which if True will activate the printout of subsystems.
@type printout: bool
"""
# Loop over all tertiary subsystems.
for subsystem in tertiary:
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))
# Sort all subsystems by name.
quaternary.sort(key=operator.attrgetter('name'))
# Printout.
if printout and quaternary:
counts = self.count(quaternary)
print("\nQuaternary %s (%i subsystems, %i groups):" % (text, counts[0], counts[1]))
for subsystem in quaternary:
print(" %s" % subsystem)
def grep(self, path=None, base_name=None):
"""Generator method for finding all classes derived from the given base name and repository.
@keyword path: The path to the repository to search through.
@type path: str
@keyword base_name: The name of the base class.
@type base_name: str
@return: The source file and the name of the derived class.
@rtype: str, str
"""
# The Unix grep command to run.
cmd = 'cd %s; grep -rI "public \<%s\>"
All subsystems
The result is:
Text output: A listing of all flightgear and simgear subsystems and subsystem groups.
Output from the Python script for finding all subsystems within the flightgear and simgear C++ code bases. The error output from the script was redirected and hence not shown below.
Primary classes (92 subsystems, 0 groups):
<ADF : SGSubsystem in 'src/Instrumentation/adf.hxx'>
<AirportDynamicsManager : SGSubsystem in 'src/Airports/airportdynamicsmanager.hxx'>
<AirspeedIndicator : SGSubsystem in 'src/Instrumentation/airspeed_indicator.hxx'>
<Altimeter : SGSubsystem in 'src/Instrumentation/altimeter.hxx'>
<AreaSampler : SGSubsystem in 'src/Environment/terrainsampler.cxx'>
<AttitudeIndicator : SGSubsystem in 'src/Instrumentation/attitude_indicator.hxx'>
<Clock : SGSubsystem in 'src/Instrumentation/clock.hxx'>
<CommRadio : SGSubsystem in 'src/Instrumentation/commradio.hxx'>
<Component : SGSubsystem in 'src/Autopilot/component.hxx'>
<DCLGPS : SGSubsystem in 'src/Instrumentation/dclgps.hxx'>
<DME : SGSubsystem in 'src/Instrumentation/dme.hxx'>
<Ephemeris : SGSubsystem in 'src/Environment/ephemeris.hxx'>
<FDMShell : SGSubsystem in 'src/FDM/fdm_shell.hxx'>
<FGAIManager : SGSubsystem in 'src/AIModel/AIManager.hxx'>
<FGATCManager : SGSubsystem in 'src/ATC/atc_mgr.hxx'>
<FGAircraftModel : SGSubsystem in 'src/Model/acmodel.hxx'>
<FGCom : SGSubsystem in 'src/Network/fgcom.hxx'>
<FGControls : SGSubsystem in 'src/Aircraft/controls.hxx'>
<FGDNSClient : SGSubsystem in 'src/Network/DNSClient.hxx'>
<FGElectricalSystem : SGSubsystem in 'src/Systems/electrical.hxx'>
<FGEventInput : SGSubsystem in 'src/Input/FGEventInput.hxx'>
<FGFX : SGSubsystem in 'docs-mini/README.introduction'>
<FGFlightHistory : SGSubsystem in 'src/Aircraft/FlightHistory.hxx'>
<FGHTTPClient : SGSubsystem in 'src/Network/HTTPClient.hxx'>
<FGHttpd : SGSubsystem in 'src/Network/http/httpd.hxx'>
<FGIO : SGSubsystem in 'src/Main/fg_io.hxx'>
<FGInterface : SGSubsystem in 'src/FDM/flight.hxx'>
<FGJoystickInput : SGSubsystem in 'src/Input/FGJoystickInput.hxx'>
<FGKR_87 : SGSubsystem in 'src/Instrumentation/kr_87.hxx'>
<FGKeyboardInput : SGSubsystem in 'src/Input/FGKeyboardInput.hxx'>
<FGLight : SGSubsystem in 'src/Time/light.hxx'>
<FGLogger : SGSubsystem in 'src/Main/logger.hxx'>
<FGMagVarManager : SGSubsystem in 'src/Environment/magvarmanager.hxx'>
<FGMarkerBeacon : SGSubsystem in 'src/Instrumentation/marker_beacon.hxx'>
<FGModelMgr : SGSubsystem in 'src/Model/modelmgr.hxx'>
<FGMouseInput : SGSubsystem in 'src/Input/FGMouseInput.hxx'>
<FGMultiplayMgr : SGSubsystem in 'src/MultiPlayer/multiplaymgr.hxx'>
<FGNasalSys : SGSubsystem in 'src/Scripting/NasalSys.hxx'>
<FGNavRadio : SGSubsystem in 'src/Instrumentation/navradio.hxx'>
<FGPanel : SGSubsystem in 'utils/fgpanel/FGPanel.hxx'>
<FGPanelProtocol : SGSubsystem in 'utils/fgpanel/FGPanelProtocol.hxx'>
<FGPrecipitationMgr : SGSubsystem in 'src/Environment/precipitation_mgr.hxx'>
<FGProperties : SGSubsystem in 'src/Main/fg_props.hxx'>
<FGReplay : SGSubsystem in 'src/Aircraft/replay.hxx'>
<FGRidgeLift : SGSubsystem in 'src/Environment/ridge_lift.hxx'>
<FGRouteMgr : SGSubsystem in 'src/Autopilot/route_mgr.hxx'>
<FGScenery : SGSubsystem in 'src/Scenery/scenery.hxx'>
<FGSoundManager : SGSubsystem in 'src/Sound/soundmanager.hxx'>
<FGSubmodelMgr : SGSubsystem in 'src/AIModel/submodel.hxx'>
<FGTrafficManager : SGSubsystem in 'src/Traffic/TrafficMgr.hxx'>
<FGViewMgr : SGSubsystem in 'src/Viewer/viewmgr.hxx'>
<FGVoiceMgr : SGSubsystem in 'src/Sound/voice.hxx'>
<GPS : SGSubsystem in 'src/Instrumentation/gps.hxx'>
<GSDI : SGSubsystem in 'src/Instrumentation/gsdi.hxx'>
<GUIMgr : SGSubsystem in 'src/Canvas/gui_mgr.hxx'>
<GroundRadar : SGSubsystem in 'src/Cockpit/groundradar.hxx'>
<HUD : SGSubsystem in 'src/Instrumentation/HUD/HUD.hxx'>
<HeadingIndicator : SGSubsystem in 'src/Instrumentation/heading_indicator.hxx'>
<HeadingIndicatorDG : SGSubsystem in 'src/Instrumentation/heading_indicator_dg.hxx'>
<HeadingIndicatorFG : SGSubsystem in 'src/Instrumentation/heading_indicator_fg.hxx'>
<InstVerticalSpeedIndicator : SGSubsystem in 'src/Instrumentation/inst_vertical_speed_indicator.hxx'>
<LayerInterpolateController : SGSubsystem in 'src/Environment/environment_ctrl.hxx'>
<MK_VIII : SGSubsystem in 'src/Instrumentation/mk_viii.hxx'>
<MagCompass : SGSubsystem in 'src/Instrumentation/mag_compass.hxx'>
<MasterReferenceGyro : SGSubsystem in 'src/Instrumentation/mrg.hxx'>
<NavDisplay : SGSubsystem in 'src/Cockpit/NavDisplay.hxx'>
<NavRadio : SGSubsystem in 'src/Instrumentation/newnavradio.hxx'>
<NewGUI : SGSubsystem in 'src/GUI/new_gui.hxx'>
<PerformanceDB : SGSubsystem in 'src/AIModel/performancedb.hxx'>
<PitotSystem : SGSubsystem in 'src/Systems/pitot.hxx'>
<PropertyBasedMgr : SGSubsystem in 'simgear/props/PropertyBasedMgr.hxx'>
<PropertyInterpolationMgr : SGSubsystem in 'simgear/props/PropertyInterpolationMgr.hxx'>
<RadarAltimeter : SGSubsystem in 'src/Instrumentation/rad_alt.hxx'>
<RealWxController : SGSubsystem in 'src/Environment/realwx_ctrl.hxx'>
<SGEventMgr : SGSubsystem in 'simgear/structure/event_mgr_orig.hxx'>
<SGEventMgr : SGSubsystem in 'simgear/structure/event_mgr.hxx'>
<SGInterpolator : SGSubsystem in 'simgear/misc/interpolator.hxx'>
<SGPerformanceMonitor : SGSubsystem in 'simgear/structure/SGPerfMon.hxx'>
<SGSoundMgr : SGSubsystem in 'simgear/sound/soundmgr.hxx'>
<SGSubsystemMgr : SGSubsystem in 'simgear/structure/subsystem_mgr.hxx'>
<SGTerraSync : SGSubsystem in 'simgear/scene/tsync/terrasync.hxx'>
<SlipSkidBall : SGSubsystem in 'src/Instrumentation/slip_skid_ball.hxx'>
<StaticSystem : SGSubsystem in 'src/Systems/static.hxx'>
<TACAN : SGSubsystem in 'src/Instrumentation/tacan.hxx'>
<TCAS : SGSubsystem in 'src/Instrumentation/tcas.hxx'>
<TimeManager : SGSubsystem in 'src/Time/TimeManager.hxx'>
<Transponder : SGSubsystem in 'src/Instrumentation/transponder.hxx'>
<TurnIndicator : SGSubsystem in 'src/Instrumentation/turn_indicator.hxx'>
<VacuumSystem : SGSubsystem in 'src/Systems/vacuum.hxx'>
<VerticalSpeedIndicator : SGSubsystem in 'src/Instrumentation/vertical_speed_indicator.hxx'>
<View : SGSubsystem in 'src/Viewer/view.hxx'>
<wxRadarBg : SGSubsystem in 'src/Cockpit/wxradar.hxx'>
Primary groups (0 subsystems, 8 groups):
<Autopilot : SGSubsystemGroup : SGSubsystem in 'src/Autopilot/autopilot.hxx'>
<CockpitDisplayManager : SGSubsystemGroup : SGSubsystem in 'src/Cockpit/cockpitDisplayManager.hxx'>
<FGEnvironmentMgr : SGSubsystemGroup : SGSubsystem in 'src/Environment/environment_mgr.hxx'>
<FGInput : SGSubsystemGroup : SGSubsystem in 'src/Input/input.hxx'>
<FGInstrumentMgr : SGSubsystemGroup : SGSubsystem in 'src/Instrumentation/instrument_mgr.hxx'>
<FGSystemMgr : SGSubsystemGroup : SGSubsystem in 'src/Systems/system_mgr.hxx'>
<FGXMLAutopilotGroup : SGSubsystemGroup : SGSubsystem in 'src/Autopilot/autopilotgroup.hxx'>
<TerrainSampler : SGSubsystemGroup : SGSubsystem in 'src/Environment/terrainsampler.hxx'>
Secondary classes (28 subsystems, 0 groups):
<AnalogComponent : Component : SGSubsystem in 'src/Autopilot/analogcomponent.hxx'>
<BasicRealWxController : RealWxController : SGSubsystem in 'src/Environment/realwx_ctrl.cxx'>
<CanvasMgr : PropertyBasedMgr : SGSubsystem in 'simgear/canvas/CanvasMgr.hxx'>
<CommRadioImpl : CommRadio : SGSubsystem in 'src/Instrumentation/commradio.cxx'>
<DigitalComponent : Component : SGSubsystem in 'src/Autopilot/digitalcomponent.hxx'>
<FGACMS : FGInterface : SGSubsystem in 'src/FDM/SP/ACMS.hxx'>
<FGADA : FGInterface : SGSubsystem in 'src/FDM/SP/ADA.hxx'>
<FGAISim : FGInterface : SGSubsystem in 'src/FDM/SP/AISim.hpp'>
<FGBalloonSim : FGInterface : SGSubsystem in 'src/FDM/SP/Balloon.h'>
<FGExternalNet : FGInterface : SGSubsystem in 'src/FDM/ExternalNet/ExternalNet.hxx'>
<FGExternalPipe : FGInterface : SGSubsystem in 'src/FDM/ExternalPipe/ExternalPipe.hxx'>
<FGHIDEventInput : FGEventInput : SGSubsystem in 'src/Input/FGHIDEventInput.hxx'>
<FGJSBsim : FGInterface : SGSubsystem in 'src/FDM/JSBSim/JSBSim.hxx'>
<FGLaRCsim : FGInterface : SGSubsystem in 'src/FDM/LaRCsim/LaRCsim.hxx'>
<FGLinuxEventInput : FGEventInput : SGSubsystem in 'src/Input/FGLinuxEventInput.hxx'>
<FGMacOSXEventInput : FGEventInput : SGSubsystem in 'src/Input/FGMacOSXEventInput.hxx'>
<FGMagicCarpet : FGInterface : SGSubsystem in 'src/FDM/SP/MagicCarpet.hxx'>
<FGNullFDM : FGInterface : SGSubsystem in 'src/FDM/NullFDM.hxx'>
<FGReadablePanel : FGPanel : SGSubsystem in 'utils/fgpanel/panel_io.hxx'>
<FGSoundManager : SGSoundMgr : SGSubsystem in 'src/Sound/soundmanager.hxx'>
<FGUFO : FGInterface : SGSubsystem in 'src/FDM/UFO.hxx'>
<KLN89 : DCLGPS : SGSubsystem in 'src/Instrumentation/KLN89/kln89.hxx'>
<LayerInterpolateControllerImplementation : LayerInterpolateController : SGSubsystem in 'src/Environment/environment_ctrl.cxx'>
<MongooseHttpd : FGHttpd : SGSubsystem in 'src/Network/http/httpd.cxx'>
<NavRadioImpl : NavRadio : SGSubsystem in 'src/Instrumentation/newnavradio.cxx'>
<StateMachineComponent : Component : SGSubsystem in 'src/Autopilot/autopilot.cxx'>
<YASim : FGInterface : SGSubsystem in 'src/FDM/YASim/YASim.hxx'>
<agRadar : wxRadarBg : SGSubsystem in 'src/Cockpit/agradar.hxx'>
Secondary groups (0 subsystems, 2 groups):
<FGXMLAutopilotGroupImplementation : FGXMLAutopilotGroup : SGSubsystemGroup : SGSubsystem in 'src/Autopilot/autopilotgroup.cxx'>
<TerrainSamplerImplementation : TerrainSampler : SGSubsystemGroup : SGSubsystem in 'src/Environment/terrainsampler.cxx'>
Tertiary classes (6 subsystems, 0 groups):
<DigitalFilter : AnalogComponent : Component : SGSubsystem in 'src/Autopilot/digitalfilter.hxx'>
<Logic : DigitalComponent : Component : SGSubsystem in 'src/Autopilot/logic.hxx'>
<NoaaMetarRealWxController : BasicRealWxController : RealWxController : SGSubsystem in 'src/Environment/realwx_ctrl.cxx'>
<PIDController : AnalogComponent : Component : SGSubsystem in 'src/Autopilot/pidcontroller.hxx'>
<PISimpleController : AnalogComponent : Component : SGSubsystem in 'src/Autopilot/pisimplecontroller.hxx'>
<Predictor : AnalogComponent : Component : SGSubsystem in 'src/Autopilot/predictor.hxx'>
Quaternary classes (1 subsystems, 0 groups):
<FlipFlop : Logic : DigitalComponent : Component : SGSubsystem in 'src/Autopilot/flipflop.hxx'>
Total: 127 subsystem classes.
Total: 10 subsystem groups.
Refactoring
To check that all subsystems on a branch have been updated or refactored:
Python script: Python script verifying if all subsystems have been updated.
#! /usr/bin/env python3
from find_subsystems import FindSubsystems
from subprocess import PIPE, Popen
class ToUpdate:
def __init__(self):
subsystems = FindSubsystems()
pipe = Popen("git diff --name-only ..next", shell=True, stdout=PIPE)
blacklist = []
for line in pipe.stdout.readlines():
file_name = line.decode()
file_name = file_name.strip()
blacklist.append(file_name)
# Loop over all derived classes.
print("\nStill to be updated:")
for subsystem in subsystems.classes_primary + subsystems.classes_secondary + subsystems.classes_tertiary + subsystems.classes_quaternary:
if subsystem.file_name in blacklist:
continue
print(" %s: %s" % (subsystem.file_name, subsystem))
if __name__ == "__main__":
ToUpdate()