Posted By

phalkunz on 05/22/09


Tagged

svn Bash python productivity


Versions (?)

Color coded SVN status


 / Published in: Python
 

URL: http://phalkunz.com/2009/05/23/print-color-coded-svn-status/

  1. #!/usr/bin/python
  2. """
  3. Author: Saophalkun Ponlu (http://phalkunz.com)
  4. Contact: [email protected]
  5. Date: May 23, 2009
  6. """
  7.  
  8. import sys, os, re
  9.  
  10. # add more status & color codes
  11. colors = {
  12. "M": "31", # red
  13. "\?": "32", # green
  14. "C": "30;41" # black on red
  15. }
  16.  
  17. # build a paramter list
  18. parameters = "";
  19. for i in range(1, sys.argv.__len__()):
  20. parameters += sys.argv[i] + " ";
  21.  
  22. status = os.popen('svn st ' + parameters);
  23. for line in status:
  24. passed = False
  25. # remove newline character from the line
  26. line = re.sub("\n", "", line)
  27.  
  28. for color in colors:
  29. match = re.match(color+(" "*6), line)
  30. if match:
  31. os.popen("echo '\E[" + colors[color] + "m" + line + "\E[m'", 'w')
  32. passed = True
  33. if(passed):
  34. continue
  35.  
  36. os.popen("echo \"" + line + "\"", 'w')

Report this snippet  

You need to login to post a comment.