Created
January 7, 2014 22:39
-
-
Save apetro/8308265 to your computer and use it in GitHub Desktop.
List the titles of portlets extracted from the portlet-definition.xml files in a specified directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import sys | |
''' | |
Given the path to a directory containing uPortal portlet-definition.xml entity files, prints the title element from each. | |
Assumes . if target directory not specified. | |
Example of running: | |
$ python list_portlets.py /Users/apetro/code/code_doit/MUM-overlay/my-prod-overlay/entities/tags/entities-51/src/main/resources/portlet-definition | |
Academic Advisors List of Advisees - with Notes | |
Academic Planning and Analysis | |
Academic Resources | |
Access Denied Records | |
Activate Services | |
Advisee Lookup - with Notes | |
Advisee Lookup | |
... | |
''' | |
def main(): | |
# Get the directory of portlets from the command line, using '.' as a fallback. | |
target_directory = "." | |
if len(sys.argv) >= 2: | |
target_directory = sys.argv[1] | |
if target_directory == "-h": | |
print("usage: [path to target directory]") | |
sys.exit(1) | |
# TODO: filter down to portlet-definition.xml files | |
# TODO: limit file size so as to not open illegitimately large files | |
portlet_definition_file_names = [name for name in os.listdir(target_directory) if os.path.isfile(os.path.join(target_directory, name))] | |
for portlet_definition_file_name in portlet_definition_file_names: | |
full_path_file_name = os.path.join(target_directory, portlet_definition_file_name) | |
with open(full_path_file_name, 'rt') as f: | |
file_contents = f.read() | |
match = re.search('(<title>)(.*)(</title>)', file_contents) | |
if match: | |
print match.group(2) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment