Tuesday, August 20, 2013

Add trunk/tags/branches directories to an existing SVN repository

In a standard SVN repository, the top level directory is the project directory, which contains three subdirectories: trunk, tags and branches (SVN Best Practices). Most time, you actively work and update the trunk directory. When you release a new version, you may take a snapshot of the trunk directory by copying the trunk directory to tags. The branches directory is where you may try out some new ideas.

Occasionally, you may have a svn repository that does not follow the recommend layout, probably because it seemed not worth the efforts when you first start that toy-like project. However as developments continue, that repository may have lots of commits, and you found it much convenient if there are the trunk/tags/branches layout (for example, link). Here I will give a step-by-step tutorial.

First, we need to dump the old repository with svnadmin, and then create a new clean repository.
svnadmin dump /srv/svn/repos/test > test-repo.dump
mv /srv/svn/repos/test /srv/svn/repos/test-backup
svnadmin create /srv/svn/repos/test
Next, check out the clean repository, and add trunk, tags, and branches directories.
svn checkout PATH-TO-TEST-REPO
cd test
svn mkdir trunk tags branches
svn ci  trunk tags branches -m "add trunk tags branches structure"
Finally, load the previous repository dump into the trunk subdirectory. Note, the --parent-dir is essential.
svnadmin load  /srv/svn/repos/test --parent-dir  trunk < test-repo.dump
Done!

Friday, August 16, 2013

A Simple Python ConfigParser Class for Parsing Configuration Files

The default ConfigParser in Python is flexible and sophisticated, but surprisingly it behaves annoyingly when working with simple configutation files. It requires that every option must belong to certain sections (link). If there is no section, it aborts with an error. Additionally, it automatically converts keys to lower case,  therefore it is case-insensitive regarding keys (link).

To deal with these annoyances, I implemented an alternative ConfigParser (https://github.com/songqiang/configparser). It aims to work simple configuration files, that contains a key and its value in each line. The delimiter between a ket and its value can be equal (=), colon (:), whitespaces and tabs. Section names are  optional. It implements the same set of interfaces of the default ConfigParser excluding the functionality for writing and sophisticated customization. To use my ConfigParser, just download the ConfigParser.py  file and put it in the same directory with the calling python script. Since Python first looks up the current working directory when importing a module, my ConfigParser will override the default one.