On the road to remote SVN syncing: svn_directory_sync.py
Fore more than one project that I’m working on right now, I’m managing the source code using Subversion. Unfortunately, I only have FTP access to the production server that the code lives on. Therefore, it’s not a trivial process to update the code on the production server to the latest revision.
Many of the repositories are very large, and therefore it’s too time and bandwidth consuming to re-upload the entire directory. I attempted to use weex to sync my local repository with the FTP server, but ran into two issues:
- Weex sometimes timesout and throws errors while creating directories
- Weex takes a long time for large repositories with deep file structures
Eventually, I’d like to write a complete alternative solution to weex in python with direct SVN integration. But, for now, I’ve written svn_directory_sync: a python script that makes things a bit easier.
For now, I keep a log of what subversion repository is on the production FTP server. Then, I use svn_directory_sync to move all the files that have been modified or added to the repository since the production revision to a separate local folder on my development machine. I can then upload those files manually or use weex to sync that ftp folder (setting weex to not delete remote files if they are not in the local folder).
For example, let’s say I have a local copy of a svn repository located at ~/www/mywebsite. I last updated the production server at revision 60. Since then, I’ve made several subversion commits: I’ve modified two files and added one directory and added one file to the local subversion repository. I now can run the following command to put those files in a separate folder to upload manually or using weex.
I run the following command, telling svn_directory_sync to move the modified and added files since revision 60 into a new folder located at ~/tmp/files_to_upload
python svn_directory_sync.py -s ~/www/mywebsite/ -o ~/tmp/files_to_upload -r 60
The script then outputs:
Copying /home/steve/www/mywebsite/modified_file1.html to /home/steve/tmp/files_to_upload/modified_file1.html Copying /home/steve/www/mywebsite/modified_file2.html to /home/steve/tmp/files_to_upload/modified_file2.html Creating directory /home/steve/tmp/files_to_upload/new_directory Copying /home/steve/www/mywebsite/new_directory/newfile.html to /home/steve/tmp/files_to_upload/new_directory/newfile.html
You can now manually upload the files in ~/tmp/files_to_upload to the web server or use weex to sync the local and remote folders.
To download the script and view the source check out svn_directory_sync on github