6,566
edits
m (→Script: Pipe fix.) |
(→Script: Newest version of the script.) |
||
Line 86: | Line 86: | ||
# Find the subsystem and subsystem group implementation files. | # Find the subsystem and subsystem group implementation files. | ||
self.find_implementations() | self.find_implementations() | ||
# Text search. | |||
if self.search_flag: | |||
self.search() | |||
# Final summary. | # Final summary. | ||
Line 215: | Line 219: | ||
# 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, simgear=True): | ||
if class_name in skip: | if class_name in skip: | ||
continue | continue | ||
Line 242: | 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): | for file_name, derived_class in self.grep(path=path, base_name=subsystem.name, simgear=self.is_simgear(subsystem.declaration_file_rel)): | ||
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), xml=self.output_xml)) | ||
Line 267: | 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): | for file_name, derived_class in self.grep(path=path, base_name=subsystem.name, simgear=self.is_simgear(subsystem.declaration_file_rel)): | ||
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), xml=self.output_xml)) | ||
Line 292: | 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): | for file_name, derived_class in self.grep(path=path, base_name=subsystem.name, simgear=self.is_simgear(subsystem.declaration_file_rel)): | ||
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), xml=self.output_xml)) | ||
Line 299: | Line 303: | ||
def grep(self, path=None, base_name=None): | def grep(self, path=None, base_name=None, simgear=False): | ||
"""Generator method for finding all classes derived from the given base name and repository. | """Generator method for finding all classes derived from the given base name and repository. | ||
Line 306: | Line 310: | ||
@keyword base_name: The name of the base class. | @keyword base_name: The name of the base class. | ||
@type base_name: str | @type base_name: str | ||
@keyword simgear: A flag specifying if the base class belongs to Simgear or not. | |||
@type simgear: bool | |||
@return: The source file and the name of the derived class. | @return: The source file and the name of the derived class. | ||
@rtype: str, str | @rtype: str, str | ||
Line 311: | Line 317: | ||
# The Unix grep command to run. | # The Unix grep command to run. | ||
cmd = 'cd %s; grep -rI %s "public \<%s\>" {{!}} grep -v "%s::"' % (path, self.grep_exclude_dir, base_name, base_name) | if simgear: | ||
cmd = 'cd %s; grep -rI %s "public \<%s\>\{{!}}public simgear.*::\<%s\>" {{!}} grep -v "%s::"' % (path, self.grep_exclude_dir, base_name, base_name, base_name) | |||
else: | |||
cmd = 'cd %s; grep -rI %s "public \<%s\>" {{!}} grep -v "%s::"' % (path, self.grep_exclude_dir, base_name, base_name) | |||
pipe = Popen(cmd, shell=True, stdout=PIPE) | pipe = Popen(cmd, shell=True, stdout=PIPE) | ||
Line 370: | Line 379: | ||
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.") | group.add_argument("-p", "--full-path", default=False, action="store_true", help="For file listings, include the SIMGEAR or FLIGHTGEAR absolute path.") | ||
# The text search arguments. | |||
group = parser.add_argument_group("text search arguments", "Search for certain text in the files.") | |||
group.add_argument("--search", metavar="TEXT", help="Search for the given text in the declaration and implementation files.") | |||
group.add_argument("--get-subsystem", default=False, action="store_true", help="Search for all get_subsystems() function calls.") | |||
group.add_argument("-c", "--includes", default=False, action="store_true", help="Extend the search to include included files.") | |||
# Code base selection. | # Code base selection. | ||
Line 398: | Line 413: | ||
self.output_format = "implementation files" | self.output_format = "implementation files" | ||
self.output_full_path = args.full_path | self.output_full_path = args.full_path | ||
# The text search arguments. | |||
self.search_flag = False | |||
if args.search or args.get_subsystem: | |||
self.search_flag = True | |||
self.search_text = args.search | |||
self.search_get_subsystem = args.get_subsystem | |||
self.search_includes = args.includes | |||
# The code base arguments. | # The code base arguments. | ||
Line 435: | Line 458: | ||
# Return the root. | # Return the root. | ||
return root_path | return root_path | ||
def search(self): | |||
"""Search for certain text in the declaration and implementation files (and includes).""" | |||
# The search text. | |||
search_text = self.search_text | |||
if self.search_get_subsystem: | |||
search_text = "get_subsystem" | |||
# Loop over all subsystems and groups. | |||
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. | |||
if self.is_simgear(subsystem.declaration_file_rel): | |||
path = SIMGEAR_PATH | |||
else: | |||
path = FLIGHTGEAR_PATH | |||
# The files to search through. | |||
root = "" | |||
if not subsystem.root_path: | |||
root = path + sep | |||
files = [root+subsystem.declaration_file] | |||
if subsystem.implementation_file: | |||
files.append(root+subsystem.implementation_file) | |||
# Loop over each file. | |||
print(files) | |||
for file_name in files: | |||
# Extract the contents. | |||
file = open(file_name) | |||
lines = file.readlines() | |||
file.close() | |||
# Search. | |||
for line in lines: | |||
if search(search_text, line): | |||
print("%s: %s" % (file_name, line)) | |||