I’m writing a utility in Python that will attach changed files in Subversion to an email and send it when a subset of folders that are under source control in SVN have been changed. I am using the pysvn library to access the repository.
I have a copy of the files on my local file system and I do an update to check if the files have changed since the last time the utility was run.
I am at the point where I am translating the path names in SVN to the path names on my local copy.
Currently I have written the following to do the job:
def formatPaths(self, paths): newPaths = list() for path in paths: path = path[len(self.basePath):] path = path.replace('/', '\\') newPaths.append(path) return newPaths
self.basePath would be something like ‘/trunk/project1’ and I’m looking to just get the relative path of a subset of folders (I.e. folder1 under ‘/trunk/project1’).
Is this a good way to solve this problem or is there some magical function I missed?
Stay with the slice operator, but do not change the loop variable inside the loop. for fun, try the generator expression (or keep the listcomp).
Edit: `lstrip()’ is not relevant here. From the manual: