Thursday, December 31, 2009

Using django-admin.py within cygwin

Sometimes I still work in windows environment. I always have cygwin installed in windows environment since I use a lot of *nix tools and scripts.
Currently, I am working a lot with python and django, very nice scripting language and powerful web framework. I used native windows python installation, instead of installing it within cygwin.
The problem occur when I tried to invoke django-admin.py script in cygwin's bash shell. It won't run. It is due to windows version of python expecting windows path of the django-admin.py script as the argument.
Here is the exact situation. Windows python expecting, something like this:

python c:\Python26\Scripts\django-admin.py


but since I run that command within cygwin, it will become like the following:

python /cygdrive/c/Python26/Scripts/django-admin.py


and throws some error messages.

So, I searched a bit and found out that cygwin has a tool that converts *nix path to windows path. The name of the tool is cygpath.

And here is what I did to solve the problem.
I created the following file:
/usr/local/bin/django-admin.py

which contains:
python.exe "$(cygpath -aw "/cygdrive/c/Python26/Scripts/django-admin.py")"

Of course you need to make /usr/local/bin/django-admin.py executable

chmod +x /usr/local/bin/django-admin.py


and you can run django-admin.py from anywhere.


Check out the following links for more information:
http://www.cygwin.com/cygwin-ug-net/using-effectively.html
http://www.cygwin.com/cygwin-ug-net/using-utils.html#cygpath

Wednesday, December 16, 2009

multipart sftp download and resume using lftp

Previously I wrote about how to resume scp download using rsync. It is pretty nice. After working a lot with scp and sftp, I was looking for a way to perform multipart download using sftp. It is pretty easy to resume sftp download, since there is already 'reget' command. Then I read some article about lftp. I thought that it was just another ftp client. I was wrong. Taken from the website itself, 'LFTP is sophisticated ftp/http client.' Truly sophisticated. Check more information about lftp from wiki.
One of the coolest feature is the ability to resume and multi-part sftp download. The command itself is pretty simple. Here is how one can do it:

$ lftp -e 'pget -c -n 5 /path/to/file' sftp://username@server


short explanation:
-e: lftp option to execute command
pget: is the command for partial download
-c: pget option to resume
-n: pget option for number of parts

Enjoy!