Recursively find subversion working copies and update


/ Published in: Python
Save to your folder(s)

Little utility script I wrote to find subversion working copies and update them. If no arguments are given the script starts from the current directory.


Copy this code and paste it in your HTML
  1. #!/usr/bin/env python
  2. """
  3. sevenup
  4.  
  5. Created by Clayton Parker
  6. http://www.claytron.com
  7. """
  8.  
  9. import os
  10. import sys
  11. import subprocess
  12.  
  13. # the directories that we want to scan
  14. dirs = sys.argv[1:]
  15. if not dirs:
  16. cur_dir = os.path.abspath(os.curdir)
  17. print "Using the current directory (%s) since none have been specified." % cur_dir
  18. dirs = [cur_dir]
  19. # we will walk each dir structure looking for working copies
  20. to_up = []
  21. ta = to_up.append
  22. for directory in dirs:
  23. directory = os.path.expanduser(directory)
  24. # TODO os.walk doesn't follow symlinks...
  25. for current_dir, directories, files in os.walk(directory):
  26. if '.svn' in directories:
  27. ta(current_dir)
  28. # delete the subdirs to stop recursion
  29. del directories[:]
  30. number_of_updates = len(to_up)
  31. print "Updating %s working copies...\n" % number_of_updates
  32. scall = subprocess.call
  33. # loop through all the paths and svn up them
  34. for upper in to_up:
  35. print "\n%s" % upper
  36. scall(('svn up %s' % upper).split())
  37. # what just happened? oh...
  38. print """
  39. *******
  40. summary
  41. *******
  42.  
  43. The following %s items have been updated:
  44.  
  45. """ % number_of_updates
  46. for upper in to_up:
  47. print upper
  48. print

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.