Created
October 15, 2012 20:33
-
-
Save mleinart/3895245 to your computer and use it in GitHub Desktop.
Walking with symlinks
This file contains hidden or 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
def do_some_walkin(start_path, matches=None): | |
if matches == None: | |
matches = [] | |
for root, dirs, files in os.walk(start_path, followlinks=True): | |
for dir in dirs: | |
if os.path.islink(os.path.join(root,dir)): | |
do_some_walkin(os.path.join(root,dir), matches) | |
root = root.replace(settings.RRD_DIR, '') | |
for basename in files: | |
if fnmatch.fnmatch(basename, '*.rrd'): | |
absolute_path = os.path.join(settings.RRD_DIR, root, basename) | |
(basename,extension) = os.path.splitext(basename) | |
metric_path = os.path.join(root, basename) | |
rrd = RRDFile(absolute_path, metric_path) | |
for datasource_name in rrd.getDataSources(): | |
matches.append(os.path.join(metric_path, datasource_name.name)) | |
return matches |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment