Created
July 31, 2014 10:19
-
-
Save koemu/73c359f21c6305791d38 to your computer and use it in GitHub Desktop.
Replace hash value for Cacti template xml file.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import re | |
import sys | |
import hashlib | |
source = open( sys.argv[1] ).read() | |
result = re.finditer( r'hash\_([0-9]{6})(\w{32})', source ) | |
for match in result: | |
before = "hash_%s%s" % ( match.group(1), match.group(2) ) | |
after = "hash_%s%s" % ( match.group(1), hashlib.md5( match.group(2) ).hexdigest() ) | |
sys.stderr.write( "before: %s, after: %s\n" % ( before, after ) ) | |
source = source.replace( before, after ) | |
print source |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment