toxicsoftware.com

RANDOMIZE USR 0

toxicsoftware.com header image 2

-tidy

December 18th, 2005 · Comments · Uncategorized

Another quick subversion script. This Python script automatically scans through a ‘ status’ report and automatically removes missing files and adds new files to your subversion repository. Of course you’ll need to commit the changes (or revert back if you made a mistake). This script is a quick and easy way of making a subversion repository match your working directory.

#!/usr/bin/python

import popen2
import re
import os

stdout, stderr = popen2.popen2(' status')

theRegex = re.compile('^(.)[ \t]+(.+)$')

theLines = stdout.readlines()
for theLine in theLines:
    try:
        theLine = theLine[:-1]
        theMatch = theRegex.match(theLine)
        theStatus = theMatch.groups()[0]
        theFile = theMatch.groups()[1]

        theOperation = None
        if theStatus == '!':
            theOperation = 'delete';
        elif theStatus == '?':
            theOperation = 'add';

        if theOperation:
            theCommand = ' %s \'%s\'' % (theOperation, theFile)
            os.system(theCommand)

    except:
        pass

Tags:

  • Alicia de Vries
    Nice. But when posting python, could you please put a link to a text file? Cutting and pasting from the browser then requires a lot of manual reindenting in vi :-(

    That's my one complaint, and it's a generic Python complaint, not anything bad about your code, which I appreciate you posting.
  • Yup - completely understand. I'll be upgrading to a different blogging engine soon and will make sure it supports easy copy & paste.
  • Very helpful. Thanks!
blog comments powered by Disqus