Skip to content

Instantly share code, notes, and snippets.

@mleinart
Created October 15, 2012 20:33
Show Gist options
  • Save mleinart/3895245 to your computer and use it in GitHub Desktop.
Save mleinart/3895245 to your computer and use it in GitHub Desktop.
Walking with symlinks
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