Hello!

This content has been updated. You will be momentarily redirected to the current version.

Moved!



Moved! I now blog at http://www.saicharan.in



Wednesday, March 18, 2009

CVS, ViewVC integration with Google Prettify

Been wanting to do this for long: browse SVN/CVS via a web interface. Ofcourse, it is a solved problem. But I wanted this set up for my own local CVS repos.

ViewVC to the rescue.

Prerequisites: Python2.x, Apache2.0+, CVS, CVS/SVN Python Bindings.

Detailed installation process:
1. ViewVC:
I have CVSNT on my workstation. So I downloaded ViewVC-1.0.7 from http://www.viewvc.org/download.html (spcecifically, version 1.0.7 from http://viewvc.tigris.org/servlets/ProjectDocumentList?folderID=6004).

To install ViewVC, first unpack it to some folder, run 'python viewvc-install' from the command line, with the current directory as the unpacked directory. I chose all the defaults values when prompted.

Next, I configured viewvc to pick up my repositories by editing the /viewvc.conf file. I changed the cvs_roots and cvsnt_exe_path variables.

2. SVN Python bindings for ViewVC:
ViewVC is written in python and tigris.org provides python bindings to talk to the CVS/SVN repository. This can be got from subversion.tigris.org Documents Area. Be sure to download the version appropirate for your version of python. Simply run the installer. You will be asked to point the installer to the Apache installation directory.

3. mod_python:
You will need to download the mod_python for Apache if you dont have it already. You can check the /modules/ directory. Look for mod_python.so file. If it is not here, download it from here: http://www.apache.org/dist/httpd/modpython/win/3.3.1/ I used this: http://www.apache.org/dist/httpd/modpython/win/3.3.1/mod_python-3.3.1.win32-py2.5-Apache2.2.exe

4. Configuring Apache.
Edit the httpd.conf file to add the following:
a) LoadModule python_module modules/mod_python.so
b) ScriptAlias /viewcvs "C:/Program Files/viewvc-1.0.7/bin/mod_python/viewvc.py"

<location>
AddHandler python-program .py
PythonPath "[r'c:\\Program Files\\viewvc-1.0.7\\bin\\mod_python']+sys.path"
PythonHandler apache
PythonDebug On
AddDefaultCharset UTF-8
</location>

NOTE: The above will work if you have chosen the defaults while installing ViewVC.

Done! Goto: http://your-machine/viewcvs.

However, I got an error when I did this: "ImportError: No module named apache"

So, I tried the alternate approach:
A) Copy <viewvc-install-dir>/bin/cgi/*.cgi to <apache-install-dir>/cgi-bin/
B) Add the following line to the <apache-install-dir>/conf/httpd.conf file:
ScriptAlias /viewvc /cgi-bin/viewvc.cgi
C) Restart Apache.

Done! Go to: http://localhost/cgi-bin/viewvc.cgi
It works for me!! I wish I could fix the other method too.

Good. Now that it works, I should be happy. But I was not :( When I 'view' a source file, it does not do the syntax highlighting (I use CVS with C++/C projects and I was not getting the syntax highlighting for these languages). So what do I do? Wanted to integrate some open source syntax highlighters. I dug thru' the code of viewvc.py and from there went on to find the place where the markup is done. (search the code base for view_markup function. I use RedHat sourcenavigator to browse and read code). They seemed to be using some PHP code to get the job done. However, I remembered I was very happy with Google's Prettify (any code you browse on code.google.com has probably used Google prettify to syntax highlight the code). So I decided to use it.

Also, using the Google Pettify is quite simple:
A) Add the following lines to the "head" section:

<link href="[docroot]/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="[docroot]/prettify/prettify.js" > < /script >

B) Add "onload=prettyPrint()" attribute to the "body" tag.
C) Put your code in <pre class="prettyprint"> or <code class="prettyprint" >tags.
D) Done!

It took quite some reading of the ViewVC python code to figure out simple ways to do it. Here is my story:
I read thru the ViewVC python code and found that there was a header and footer being used for each page. Then there was a template for markup and each of the different views that ViweVC supports. Then I stumbled upon the EZT class (EaZyTemplates). Just what I needed to integrate with Google Prettify!! So I found the templates being loaded by ViewVC. They are loacated under <viewvc-install-dir>/templates/. Here are my modifications:
1. Download Google Prettify from: http://code.google.com/p/google-code-prettify/
2. Unzip it. Copy the src folder to <viewvc-install-dir>/templates/docroot/
3. I renamed the src folder to prettify (just to help me later)
4. Add the following lines to <viewvc-install-dir>/templates/include/header.ezt, in the "head" section:

<link href="[docroot]/prettify/prettify.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="%5Bdocroot%5D/prettify/prettify.js"></script>

also, modify the body tag to: <body onload="prettyPrint()">
5. Modify <viewvc-install-dir>/templates/markup.ezt:
Change this: <div id="vc_markup"><pre&t;[markup]</pre></div>
to: <div id="vc_markup"><pre class="prettyprint">[markup]</pre></div>

Done!.

Have fun! And post your questions as comments.

Sunday, March 01, 2009

Google default language

Each time I use Google from office, Google responds in Thai. I fixed that by going to www.google.com/ncr.

Now onwards, I hope to always get results in English :) Btw, if you happen to clear your cookies, you should go to www.google.com/ncr again.

NS2 nam error

I have been bothered by this error while running ns/nam for a long time now. Finally found that tk needed patching :( Here is the error that I got and the solution that helped me fix it.

Error:
[root@localhost]# nam:
[code omitted because of length]
: no event type or button # or keysym
while executing
"bind Listbox {

%W yview scroll [expr {- (%D / 120) * 4}] units

}"

invoked from within

"if {[tk windowingsystem] eq "classic" || [tk windowingsystem] eq "aqua"} {
bind Listbox {
%W yview scroll [expr {- (%D)}] units

}

bind Li..."


And, I got the solution to this on: http://forums.fedoraforum.org/showthread.php?t=206795.
Essentially you need to patch tk8.4.18 with the patches from: http://bugs.gentoo.org/show_bug.cgi?id=225999

Details of how to patch are available at: http://forums.fedoraforum.org/showpost.php?s=a2bb89875669ff26ed61cd371399a517&p=1131049&postcount=3

Monday, February 16, 2009

My Reading List

Very frequently my friends ask for my reading list. So I decided to follow the DRY and SRP principles to help them and help myself. Hence this blog entry. Here goes:

My favourite tech blogs/sites:

Programming blogs:
1. codinghorror.com
2. blog.objectmentor.com (this along with its original site at butunclebob.com)
3. thedailywtf.com
4. c2.com --> Advanced stuff. Really interesting though. It takes some time to follow their style of expression - but is definitely worth a shot.
5. Reddit.com In particular, http://www.reddit.com/r/programming/ & http://www.reddit.com/r/technology/

Programming + Technology + Perspectives (my favourite pass-times):
1. steve-yegge.blogspot.com
2. paulgraham.com
3. joelonsoftware.com
4. norvig.com
5. googleblog.blogspot.com
6. TED.com - My personal favorite for advances in human thought and creativity!

Tech News:
1. digg.com
2. slashdot.org

Management: ( Yeah, I am interested in Genuine management! )
1. sethgodin.typepad.com


PS: I will update this post as my reading list changes (Yes. that includes additions and deletions as well. For deletions, I will keep the links, but the text will be struck off like this).