Created
December 18, 2013 19:26
-
-
Save lwf/8028253 to your computer and use it in GitHub Desktop.
whisper-clean.py
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
import os | |
import os.path | |
import sys | |
from carbon.hashing import ConsistentHashRing | |
instances = [] | |
unwelcome_instances = [] | |
for arg in sys.argv[1:]: | |
unwelcome = False | |
if arg.startswith('-'): | |
arg = arg[1:] | |
unwelcome = True | |
instance = tuple(arg.split(':', 2) + [None]) | |
print(instance) | |
instances.append(instance) | |
if unwelcome: | |
unwelcome_instances.append(instance) | |
if 0 == len(instances): | |
print('Usage: python whisper-clean.py [-]<address>:<instance>[...]') | |
sys.exit(1) | |
ring = ConsistentHashRing(instances) | |
for dirname, dirnames, filenames in os.walk('/mnt/graphite/whisper'): | |
for filename in filenames: | |
pathname = os.path.join(dirname, filename) | |
basename, ext = os.path.splitext(filename) | |
if '.wsp' != ext: | |
print('skipping %s' % os.path.relpath(pathname, | |
'/mnt/graphite/whisper')) | |
if ring.get_node(os.path.relpath(os.path.join(dirname, basename), | |
'/mnt/graphite/whisper'). | |
replace('/', '.')) in unwelcome_instances: | |
print('unlinking %s' % pathname) | |
os.unlink(pathname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment