Advertisement
Guest User

traffic-debugtags.py

a guest
Nov 9th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import subprocess
  4. import re
  5.  
  6. trafficserver_source_dir = "/Users/danielxu/dev/trafficserver"
  7.  
  8. def main():
  9.  
  10.         # Run the unix `grep` command
  11.         try:
  12.                 output = subprocess.check_output("grep -Ihr 'Debug(\"' {0}".format(trafficserver_source_dir), shell=True, stderr=subprocess.STDOUT)
  13.         except subprocess.CalledProcessError, e:
  14.                 print "Some kind of error happened"
  15.                 print e.output
  16.  
  17.         # Parse results of `grep`
  18.         tags = []
  19.         lines = output.split('\n')
  20.         for line in lines:
  21.                 line = line.strip()
  22.  
  23.                 # Hueristic detection of debug statements
  24.                 # We only want the tags to `Debug()` functions
  25.                 if line[0:6] != "Debug(":
  26.                         continue
  27.  
  28.                 # Find the two "'s and extract what's between them
  29.                 index1 = line.find('"', 0)
  30.                 index2 = line.find('"', index1+1)
  31.                 tag = line[index1+1:index2]
  32.                 if ' ' not in tag and tag not in tags:
  33.                         tags.append(tag)
  34.  
  35.         #acc = ""
  36.         for tag in tags:
  37.                 #acc += tag + ", "
  38.                 print tag
  39.         #print acc
  40.  
  41. if __name__ == '__main__':
  42.         print 'Recursively grubbing for debug tags in: {0}'.format(trafficserver_source_dir)
  43.         main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement