Wednesday, September 16, 2009

Merging a branch with git-svn and still retaining the association with the previous svn path

git-svn uses commit messages to tie the commits in a particular local branch to its corresponding SVN path, which works great most of the time.

It causes a problem though when you want to merge branches in git and have the merged results be put back into svn.  I wanted to do this because the git merge functionality is much easier to use, IMHO, than subversion's merge command.

The problem is that when you do a git merge of two remote svn folders in a local git branch the commit message path changes from the previous path to the path of the source of the merge.

So, for instance, if you want your trunk in svn to match a branch (let's say branch 1.1.1), you could do the following in a git-svn checked out repo (Assuming you have already done git svn clone -s...)

git checkout trunk
git checkout -b localtrunk
You are now in the local git branch 'localtrunk' which is a copy of the trunk path of your svn repository.
Now, let's say you want to merge changes from branch 1.1.1 into trunk, you could do this...
git merge 1.1.1
If the merge is successful there is still a problem. The problem is that now if you do a git svn dcommit to push the merged changes into trunk they will not go into trunk. They will go into the 1.1.1 branch! Bummer. If you read the man page for git-merge you might say, "Hey, there is a --no-commit option to git-merge! That could fix the problem." In theory you would be right and I thought the same thing, but after many attempts (on Ubuntu 9.04) it would always commit after merging. Bummer! --no-log didn't work either. So, after a lot of searching, I found a way to do this, but it only works if you don't have a lot of commits to replicate.
Instead of running git merge as above do this. For each commit do...
git cherry-pick -e (SHA1 hash of the commit to merge from branch 1.1.1)
You can get those hashes from git log, after doing git checkout 1.1.1 in another terminal.

Each time you do it delete the line in the commit message that starts with git-svn-id: (and the line after it, but I don't think deleting that 2nd line is technically necessary)

Now do...
git svn dcommit (to send the merged changes to svn while keeping your local git branch pointing to trunk!)
git svn fetch
git svn rebase

Check that your localbranch branch and your 1.1.1 branch are the same with...
git diff 1.1.1

If there is no output they are identical.

Check that your localbranch branch is still pointing to trunk by doing...
git log

and verifying the git-svn-id: lines for the last commits (the ones at the top) still point to trunk@(svn commit number)

All done!

Tuesday, June 30, 2009

How to easily fork python code into separate processes via a decorator

Do you have a bit of python code that is taking a long time, and you don't want to wait for it to finish?

The blogger here made an excellent way of forking pieces of your code into separate processes using a decorator.

http://buffis.com/2008/01/09/easy-forking-of-processes-in-python-using-generators/

It doesn't get easier than this.

Friday, June 19, 2009

How to get the firefox java plugin working in Ubuntu 8.10 64bit

The default java plugin for Firefox on Ubuntu 8.10 is not fully functional on 64 bit machines.  It works for some applets, but not all.

This blogger took the time to figure out how to replace it with Sun's plugin. Thank you for sharing!

http://tp0x45.blogspot.com/2009/03/openjdk-issue-in-ubuntu-810-64-bit.html

Friday, April 17, 2009

Use Python for Microsoft Windows Login and Group Policy Scripts

Background

Microsoft's Active Directory provides a way to distribute msi files and execute scripts on login, logout, shutdown etc. This makes it very easy to distribute a script to be run on login for a group of machines registered to Active Directory.

The type of scripts that can be run are .bat files, JScript or VBScript files via Windows Script Host (WSH. It's executables are wscript.exe (windows version) and cscript.exe (command-line version)), or windows executables (exe files). While those options are not too bad, I much prefer python for programming so here we are going to outline how to use python for these scripts.

Tim Golden has written some excellent wrapper code for python to make programming for Active Directory, WMI, shell work (like creating shortcuts) amoung other windows-specific things a pleasure.

Instructions
  • Get the Python MSI from Active State. We could have used the msi from python.org but we would have had installed the windows specific stuff that Mark Hammond wrote (pywin32 Windows Python Extensions) separately. And since I want to distribute this with Actirve Directory I would have had to convert the pywin32 package to an MSI as it is distributed as an exe. I tried compiling the source distribution to an msi with distutils (i.e.,
    python setup.py bdist_msi
    ) but the build failed because I did not have Visual Studio 2003 installed (I was building python 2.5). I do not want to buy or install Visual Studio (especially the old 2003 version) so I was happy that Active State packaged it all up in an msi already and distributed it for free! Thank you Active State!
  • If you would like to install Tim Golden's wrapper code via Active Directory as well (highly recommended) it is easy since he provided the setup.py distutils scripts for each package. Just download the zip files you want from his site and then for each one run
    python setup.py bdist_msi
    and an msi will be created for you. Thank you Tim!
  • You can distribute any python code that you want via Active Directory this way. Just make an msi of your code by writing a setup.py script and then running
    python setup.py bdist_msi
    . Distutils makes it easy!
  • Then, distribute those msi files with Active Directory Group Policy. I'll leave that to an exercise for the reader, but here is a good starting point. For some reason, I had to reboot a couple of times on some workstations for them to get the msi files installed.
  • Now your setup work is done and your workstations (or servers) have python installed along with pywin32 and optionally some nice wrapper code. From here you can write python scripts for those hosts that will be able to interact with active directory, WMI, COM, etc.
  • Now write your python login scripts.
  • To setup your login scripts to run at login you have a choice. First, you could compile your python code into exe files. You can do that without a lot of effort using py2exe (a distutils extension). This route adds a separate step (conversion to exe file) and every time you make a new exe it copies the whole python interpreter and other code with it so the exe files are large. This is a good option if you don't want to install python on the hosts though.
  • Windows Script Host (WSH) integration is another good option (I won't go into calling the python intepreter on your scripts via a bat file, but that is also an option). This way cscript.exe or wscript.exe runs the python intepreter which runs your script. Here's what you need to do to set this up.
    • First, run C:\Python25\Lib\site-packages\win32comext\axscript\client\pyscript.py (adjust for your installed version of python) on each host. This registers python as a language that Windows Script Host can run (called pyscript). Once this is done your python files (saved with the .pys extension can be used as Windows login scripts! You could put this command in a MSI file and distribute it with python so that when your login script runs it will already have been done.

    • There is one registry entry that needs to be added I have found in experimenting and below is some jscript code that does it (put it in a file in with a .js extension that you can publish it via a Group Policy in the Computer section of the policy to run on startup of the machine (best not done on logon to make sure it get's done before your python scripts run))


      var objShell = WScript.CreateObject("WScript.Shell");
      objShell.RegWrite("HKEY_CLASSES_ROOT\\pysFile\\shell\\open\\command\\", "\"C:\\WINDOWS\\system32\\wscript.exe\" \"%1\"", "REG_SZ");



    • Lastly setup your new shiny .pys script to run at login user the User side of the Active Directory Group Policy Object. Here is a site that shows you how.

    • This site has a lot of good information as well, but I have found that you don't need to do all the steps it outlines because the msi files above do most of it. The steps above worked for me.

Friday, January 30, 2009

edendb - A thin, flexible and fast python DBAPI wrapper for those who like SQL but don't like to type

If you are like me, you have looked for ways to make connecting to database from your python code easier and less painful.

For a long time I looked into the myriad ORMs available for python and they all seemed to be overkill for me. I don't mind using SQL. In fact I like it, but when putting it into python code and using the DBAPI I found my productivity was declining. I needed something to make executing sql commands faster and easier from python code. I needed something abstracted away from the DBAPI, but that also allowed me to execute straight sql if needed and easily handle all the possible values that could be returned.

So, I wrote a python library to do it.

Meet edendb!

Check it out and let me know what you think.

Thursday, January 29, 2009

Google Talk on Ubuntu Linux

Chat, Voip calls, system tray, Excellent!

http://jamesselvakumar.wordpress.com/2008/11/17/good-news-for-google-talk-users-on-linux/

Thursday, January 22, 2009

How to configure mutt to use Gmail as smtp and imap server

The following helped me the most when configuring this.

http://shreevatsa.wordpress.com/2007/07/31/using-gmail-with-mutt-the-minimal-way/

The only thing I changed was

set postponed =~/Mail/Drafts

so that I could write messages offline and then send them when I get back to an internet connection.

I can't wait to try this out on my Asus Eeepc 2G Surf