Venky's Blog http://www.venkysblog.com Whatever feels interesting! posterous.com Sun, 08 May 2011 00:09:00 -0700 Pep8 and Pylint in Geany http://www.venkysblog.com/pep8-and-pylint-in-geany http://www.venkysblog.com/pep8-and-pylint-in-geany

Pep8 and Pylint are utilities that let you write cleaner Python code as per the conventions. These can be used from command line, however, I have been trying to enable it in my IDE, Geany, so that using it becomes a part of my workflow.

 

Here is how I did integrate it:

1. Install Pep8 and Pylint if not installed

easy_install pep8

easy_install pylint

 

or

pip install pep8

pip install pylint

 

2. Enable Pep8 and Pylint as build commands in Geany

Go to the Menu Build > Set build commands 

Make the below changes in the independent commands section:

- For Pep8

  In the first column, enter Pep8

  Now in the second column enter the following:

  pep8 --repeat --count "%f"

 

- For Pylint

    In the first column, enter Pylint

 

    Now in the second column enter the following:

    PYTHONPATH=${PYTHONPATH}:$(dirname %d) pylint --output-format=parseable --reports=n "%f"

 

Now, In the below row of regular expression enter the following:

  ^(.+?):([0-9]+):.+

Now Click on OK

 

Here on you will see the the above two command in the build menu. You can execute them on every file from within geany and see the errors in the IDE itself.

 

Known Issues:

Currently, If you use a virtualenv for a project those imports are falsely shown as errors. If somebody finds a way to fix these let me know.

 

 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1406940/Venky2.jpeg http://posterous.com/users/4SykxB4hhgl3 Venky Venky Venky
Sun, 10 Apr 2011 00:02:00 -0700 Using Django with Virtualenv and PIP http://www.venkysblog.com/installing-virtualenv-pip-and-django http://www.venkysblog.com/installing-virtualenv-pip-and-django

Recently, I have switched over to using Virtualenv and PIP for all my python devolopment, and I am totally convinced that is the way to go. I will not get into why we should use those, instead will outline how to set this up with Django for development as well as deployment.

 

1. Install Basic Tools like Git, PhpMyadmin, MySQL, Mercurial etc

 apt-get install curl sox mysql-server mysql-client libmysqlclient16-dev git-core apache2 libexpat1 ssl-cert unixodbc-dev libmyodbc phpmyadmin mercurial 

2. Prepare the system

apt-get install python-setuptools python-dev build-essential python-mysqldb python-tz python-imaging


3. Install PIP & Virtualenv

easy_install pip

pip install virtualenv


4. Create a virtual environment

This command creates the isolated virtual environment. The  --no-site-packages option tells virtualenv not to inherit any libraries from your existing Python installation's  site-packages directory. For more information, see the virtualenv documentation on  --no-site-packages.

 

cd /usr/src

 virtualenv --no-site-packages django1.3_env

 

If you are setting up your systemk for development go to Setp 5, else you can skip directly to step 6.

 

5. For Development

source /usr/src/django1.3_env/bin/activate

Now you should see the environment name - django1.3_env besides the prompt. Upon this install the below packages into this virtual environment.

 

pip install Django

 

pip install MySQL-python

pip install python-dateutil

pip install simplejson

pip install yolk

pip install pytz

 

This will install all needed packages in this environment. Now you can start your django project as per the django tutorial. Every time, you open a new prompt type in source /usr/src/django1.3_env/bin/activate, and then continue development.

 

 

6. For Deployment

On the Production server checkout the project from reporsitory

cd /usr/src/

git clone <url/project.git>

cd project

 

Start the Virtual Env

If you have not completed  steps 1-4, please complete them.

source ../django1.3_env/bin/activate

pip install -r requirements.txt

 

The above command assumes you have a requirements file in your project root folder. If you are not sure what tis is please check on how to create a requirements file for PIP.

 

Create the Database on the server with the needed permissions

 

Install mod_wsgi from source

 

cd /usr/src/

wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz

tar xvfz mod_wsgi-3.3.tar.gz

cd mod_wsgi-3.3/

apt-get install apache2-threaded-dev

./configure

make && make install

 

 

 

Instruct Apache2 to load mod_wsgi module

cd /etc/apache2/mods-available

vi mod_wsgi.load

and add the following line to the new file

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

 

Symlink in mods-enabled

cd /etc/apache2/mods-enabled

ln -s ../mods-available/mod_wsgi.load .

 

 

 

 

Add a the django project as a new virtual host

cd /etc/apache2/sites-available

vi project.com

 

Add the following in the new file

 </span></strong> WSGIPythonHome /usr/src/django1.3_env/ WSGIPythonPath /usr/src/project/ <VirtualHost *:80> ServerAdmin admin@project.com ServerName www.project.com ServerAlias project.com   # Log Files LogLevel warn ErrorLog /var/log/apache2/project.com_error.log CustomLog /var/log/apache2/project.com.log common   #Aliases for static media Alias /static_media/ /usr/src/project/project/static_media/   #Aliases for Admin media Alias /static/admin/ /usr/src/django1.3_env/lib/python2.6/site-packages/django/contrib/admin/media/   #Alias for wsgi requests WSGIScriptAlias / /usr/src/project/deploy/apache.wsgi   <Directory /usr/src/project/deploy/> Order allow,deny Allow from all </Directory>   </VirtualHost>  

 

Add a wsgi file to your project/deploy directory as below

  import sys import os   #Add the virtual Python environment site-packages directory to the path import site site.addsitedir('/usr/src/django1.3_env/lib/python2.6/site-packages/')   #Add project to PYTHONPATH WSGI_FILE_LOCATION = os.path.dirname(__file__) sys.path.append(os.path.join(WSGI_FILE_LOCATION, "../project_subfolder/"))   #Add django settings file to environment path os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'   #This import should be here as it will only work after virtual python env is set import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()  

 

Restart Apache

service apache2 restart

 

 

Voila, all should be done and working now...

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1406940/Venky2.jpeg http://posterous.com/users/4SykxB4hhgl3 Venky Venky Venky
Thu, 31 Mar 2011 23:52:00 -0700 My new editor - Geany http://www.venkysblog.com/my-new-editor-geany http://www.venkysblog.com/my-new-editor-geany

I have been using the default text editor in Ubuntu, Gedit, and have modified it to work it like an IDE. It worked good, but still lacked a lot of features which a good IDE would have (like code folding, symbols browser etc). Lately, I saw a blog post with a mention of few new IDEs around which are as light wieght as G-Edit. That is when i first heard of Geany.

Geany is a lightweight but surprisingly powerful GTK-based IDE. I am totaly sold over it and it has become my default IDE in just 2 hours of playing around. Works beautifully with Python, Django, HTML, JS, CSS and FreeSWITCH C source files. Thats all i need for my coding. But Im sure it plays well with other languages too. It has advanced features of an IDE and remains very light weight.

How to Install Geany in Ubuntu 10.10

 add-apt-repository ppa:geany-dev/ppa

apt-get update

apt-get install geany

apt-get install geany-plugins

apt-get install xterm

 

These are the customizations I did from my side:

1. Enable the required plugins, from Tools > Plugin Manager

2. Enable Django template syntax highlighting:

- Copy /usr/share/geany/filetypes.html to ~/.config/geany/filedefs/

- Find the [lexer_properties] section of the file and add, the following line:

lexer.html.django=1

 

3. Copy the file below to ~/.config/geany/  (This includes, python snippets, basic django model basic, basic django template snippets, html snippets, js snippets and css snippets)

http://dl.dropbox.com/u/668529/conf/snippets.conf

 

 

 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1406940/Venky2.jpeg http://posterous.com/users/4SykxB4hhgl3 Venky Venky Venky
Sun, 13 Mar 2011 07:59:00 -0700 Why Phone number verification services will fail in India? http://www.venkysblog.com/phone-number-verification-services-fail-in-in http://www.venkysblog.com/phone-number-verification-services-fail-in-in

Update: I have been pondering over some posible solution for this, and the primary reason for concern for me here was how would businesses verify phone numbers authentically in India considering both approaches look flawed. After some basic hacking and testing at my end, I have a probable solution which seems to be working for India.

Current Flaw in Approach 2 (Similiar to ZipDial):

Currently, the Caller ID can easily be spoofed to the Regular phone numbers (080349xxxx) like the ones used by ZipDial, using any VoIP service, and it is very difficult for the system to detect the spoofed ID. However the caller id cannot be spoofed through a regular phone connection from within India.

This, got me thinking, if there could be a way to block VoIP services from reaching the numbers, then Approach 2 could very well get the job done.

Solution

And, there came the Indian Telcos to the rescue. Indian Telcos provide two kinds of numbers in India:

1. Regular Phone Numbers (080XXX) and

2. Toll Free Numbers (1800XX)

What I discovered after some testing at my end was, that the Indian Telcos did not allow the VoIP routes to reach the Toll Free Numbers. This is a very different behaviour than the US Telcos who allow this, however this seems to be the saving grace for us.

Hence, if services like ZipDial start using Toll Free Numbers instead of the regular phone numbers for verification, it could work well.

How I tested this

1. Usually when dialling from VoIP services the Phone number is prefixed with the country code, so I tried calling the toll free number as 911800XXX, and the call didnt complete as expected.

2. Dialing only the toll free number from a VoIP service, wouldnt work as then the call will be routed to US, as its a US/Canada Country code.

Conclusion

So far, I havent found a flaw in this approach and tried about 7 different VoIP operators. If any of you find a way to call the toll free numbers in India from a VoIP service, please post a comment.

I have also communicated this approach to the ZipDial team, and they are working on testing it throughly from thier side. Lets hope they announce something positive soon, as thier intent to launch this kind of service was quite innovative in the first place.

 

 

Posted Earlier: Phone number verification services are designed to confirm, that a given phone number is in service and belongs to the said user. It a great way to increase trust for websites and businesses.

Verification services are often used reduce spamming, fraud etc. Businesses which would use such services, would include:

  • Lead generation companies
  • Ecommerce sites
  • Social networking sites
  • Internet forums
  • dating sites
  • wikis etc

These services can be categorized primarly by two approcahes:

1. The business initiates the verification to a customers phone (via sms or by making an automated phone call to the customer)

2. Customer initiates the verification from his phone (by sending a sms or by dialing a phone number)

Lets look in more detail as how these services would work, and why both these approaches fail to work for India.

 

1. The business initiates the verification to a customers phone (via sms or by making an automated phone call to the customer)

 This approach normally is based verifying a PIN number. What I mean, by this is that businesses would generate a randomPIN number at thier end and this is sent to the customers phone via a sms or an automated phone call IVR. If the phone belongs to the intended user, he would recieve this PIN and then would be able to verify the PIN. Traditionally, this has been used by almost all businesses in India.  

Pros:

  - Verification is completly credible as its PIN number based, which is generated at the business end, hence very difficult to beat/cheat.

Cons:

 - Won't work very well anymore in India, due to new TRAI regulations as lots of numbers could be present in the do not disturb registry, and SMS might never reach customers.

 - Can be missued by spammers by entering anonymous phone numbers which could lead to customer complaints being registered to TRAI on businesses, leading to heavy penalty. 

 

2. Customer initiates the verification from his phone (by sending a sms or by dialing a phone number)

In this approach, the customer is asked to send an sms to a random phone number or call a random phone number and then the verification is based on identifying the caller id of the customer phone via sms or phone call. This sounds like decent approach and recently, there have been services launched around this approach, however it is not at all credible and very easy to beat or cheat. We will see later in this post, how.

Pros:

- Will work as per TRAI regulation, as customer is the one initiating the call/sms.

- No spam and less intrusive for a customer.

Cons:

 - Verification of the phone is not at all credible. The system can easily be fooled as there are many services through which you can send sms, phone calls with custom caller id.

 

Initially, I had planned to end this post here, but I got feedback, to include a sample case study on how a system using approach no. 2, could be fooled and why that method is not credible. So here we go...

 

Case study - ZipDial to verify service 

As per ZipDial's website - "ZipDial to verify is used for instant verification of your customers' mobile numbers and can be used on your site for account registration, login, CAPTCHA, transaction confirmation, authenticated voting, etc."

 

Thier marketting pitch

- SMS free Mobile Verification

- Toll-Free for both mobile and landline users, including international

- Compatible with latest TRAI regulations

- Go live on your site in 30 minutes!

 

The most intresting of the above statement to me was "Go live on your site in 30 minutes!". So I decided to check this out, but to my dissapointment, I was able to cheat this system without any issues. I have even made a dummy website as a Proof of Cheat Concept in just 15 minutes, which is even lesser than thier promised time to go live.

How does the cheat work:

1. Open www.zipdial.com and click on the ZipDial to verify image. Now enter the phone number you want to verify with zipdial. Dont worry, enter any number for example 918030050099, and press the green arrow key.

 (Note: This is zipdials number itself, which we will verify as our own by cheating the system)

Screenshot

 

2. Note down the last 2 digits of the random number given by zipdial in the next screen.

Screenshot-1

 

3. Now, open  the site I coded up as an example for this post http://antizipdial.alwaysdata.net/ and enter the details you asked for as shown below:

Screenshot-2

Once you submit the button, you should see the ZipDial to verify service showing you number as verified within a few seconds. Yeah it was that easy :)

This leaves me to wonder, big businesses like Myntra, Flipkart using services like ZipDial are left open with a big loop hole.

Some Additional Notes 

1.  I have nothing against ZipDial, it has been just used as a case study to show how simple it is to beat such services.

2.  Just to put how easy it was me to cheat the system:

    a. It took me a total of 15 odd minutes to write this up

    b. The hosting is hosted at a free site

    c. It does not cost any money to beat the ZipDial service as ZipDial disconnects my calls from thier side, and hence my calls are free

3. Please dont use this for illegal purposes, as this is only meant for information

 

Please, retweet this post if you are able to succesfully verify on ZipDial using this information.

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1406940/Venky2.jpeg http://posterous.com/users/4SykxB4hhgl3 Venky Venky Venky
Tue, 08 Mar 2011 22:53:00 -0800 Setup Mercurial GUI Client on Ubuntu 10.10 http://www.venkysblog.com/setup-mercurial-gui-client-on-ubuntu-1010 http://www.venkysblog.com/setup-mercurial-gui-client-on-ubuntu-1010

Recently Bitbucket  introduced new plans, which allows unlimited private repositories for startups (Less than 5 contributors). This works really well for me, when I decide to use a dvcs and want to avoid the Github paid plans for private repo hosting.

 

Command line is nice, but somehow, I still prefer a GUI client to see my diffs, as its more productive for me. So Lets get started..

(All the commands are for the terminal/shell)

Step 1: Add the Tortoise ppa to your system

sudo add-apt-repository ppa:tortoisehg-ppa/releases

 

Step 2: Update the system Package List

sudo apt-get update


 

Step 3: Install Tortoisehg Client

sudo apt-get install tortoisehg

Step 4: Enable Tortoisehg and Nautilus Integration

    - Open System > Administration > Synaptic Package Manager

    - Search Tortoise on the quick search, and then mark and apply the TortoiseHg-nautilus

    - Open terminal and type nautilus -q

 

Now you should be able to see a context item when you right click inside any folder. Thats it. We are done!

 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1406940/Venky2.jpeg http://posterous.com/users/4SykxB4hhgl3 Venky Venky Venky
Wed, 02 Mar 2011 04:30:00 -0800 Replace OpenJDK with Oracle-SunJDK on Ubuntu 10.10 http://www.venkysblog.com/replace-openjdk-with-oracle-sunjdk-on-ubuntu http://www.venkysblog.com/replace-openjdk-with-oracle-sunjdk-on-ubuntu

By default Ubuntu 10.10 (32-bit) installs OpenJDK for JRE, JDK. Since OpenJDK tries to replace the properietry pieces of Sun-JDK, this is a nice project, however, there is still time before it grasps all the specs and works flawlessly.

Before we begin, type: java -version, at the command prompt, and you will see that the version is a Open-JDK version.

 

To Replace Sun-JDK with Open-JDK follow the setps below:

1. Enable partner repositories :  

  - Open  System -> Administration -> Synaptics Package Manager

 - In the Package Manager > Settings menu > Repositories, and check the box for Software restricted by copyright or legal issues

 

2. Install Sun-JDK

sudo apt-get install sun-java6-jdk sun-java6-jre sun-java6-source sun-java6-fonts sun-java6-bin sun-java6-plugin

 

3. Replace OpenJDK with SunJDK

sudo update-java-alternatives -v -s java-6-sun


To Double check, type: java -version, and you should see the Sun-Java version details.

 

 

 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1406940/Venky2.jpeg http://posterous.com/users/4SykxB4hhgl3 Venky Venky Venky
Wed, 27 Oct 2010 14:16:00 -0700 Using Google Text to Speech with FreeSWITCH http://www.venkysblog.com/using-google-text-to-speech-with-freeswitch http://www.venkysblog.com/using-google-text-to-speech-with-freeswitch

Google Translate can be used as a  text-to-speech converter, providing a handy MP3 file of your chosen words. It's not an official offering, but Google Translate provides you the spoken version of your translation. There’s no official API for the text-to-speech service yet, but people around the web have figured out a way on using it.

One can get the speech audio as an MP3 file via a simple HTTP GET (REST) request:

"http://translate.google.com/translate_tts?tl=en&q=Venky+is+trying+Freeswitch”

 

Points to note here:

1. Just by changing the text in the above URL, after the 'q=' parameter, to whatever you want, will allow you’ll get back a MP3 file based on the text.

2. This is English only for now, and its limited to 100 characters.

3. This is not officially released by Google, so can be stopped/blocked anytime.

 

Now lets get to how we would use this with FreeSWITCH, to allow text to speech.

FreeSWITCH has a module to play audio from a streaming source - Mod_shout. We will be using this to get the job done.

 

Mod_shout can play remote mp3 files at any sample rate (8khz, 16khz, 44.5khz) in mono/stereo and re-sampling happens on the fly.

One could use this in one of the supported scripting languages like Lua, Javascript as below:

session.streamFile("shout://translate.google.com/translate_tts?tl=en&q=Venky+is+trying+Freeswitch", "")

 

or in a Dialplan like below for the extension 100:

 

<extension name="Google_TTS_FreeSWITCH">  <condition field="destination_number" expression="^100$">        <action application="answer" data=""/>        <action application="playback" data="shout://translate.google.com/translate_tts?tl=en&q=Venky+is+trying+Freeswitch"/>  </condition> </extension>

 

Enjoy the free TTS experience!

 

 


 


 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1406940/Venky2.jpeg http://posterous.com/users/4SykxB4hhgl3 Venky Venky Venky
Sun, 12 Sep 2010 18:26:00 -0700 Install Python2.6.4, mod_wsgi and Django on CentOS 5.4 http://www.venkysblog.com/install-python264-modwsgi-and-django-on-cento http://www.venkysblog.com/install-python264-modwsgi-and-django-on-cento

Once I got Django running on windows, I started hacking around setting Django up on CentOS. Little did I know, that upgrading Python and getting Django wouldn't be that easy. CentOS 5.4 uses python 2.4, and replacing it is not really an option since yum and other core packages depend on it.

The solution was to install 2.6.4 from source and use /opt for the prefix  so that 2.6.4 becomes the default python. Then move on to install mod_wsgi, setup Apache to use mod_wsgi and Install Django on CentOS 5.4

 

 

Step1: Install Build Requirements

Run the following command as root (or with sudo) to install gcc and the development libraries used by python:

yum install gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-develsqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel

 

Step2: Download & Install Python 2.6 from source

cd wget http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tgz tar xvfz Python-2.6.4.tgz cd Python-2.6.4 ./configure --prefix=/opt/python2.6 --with-threads --enable-shared

 

Configure Python 2.6 so that we're not overwriting the system's python installation:

./configure --prefix=/opt/python2.6 --with-threads --enable-shared make make install

 

After running the make command you will see a list of modules that were not built. If you installed all of the devel libraries listed above, the only missing modules should be bsddb185 and sunaudiodev. You probably don’t need these – bsddb185 is the old version of the berkely db module, and sunaduiodev is for solaris. On x86_64 db and imageop may also be in the list, but if you look at the setup.py file, it looks like this is normal.

 

Step 3: Add an alias to root's .bash_profile and make a symbolic link

vi ~/.bash_profile alias python='/opt/python2.6/bin/python'

 

source ~/.bash_profile ln -s /opt/python2.6/bin/python /usr/bin/python2.6

 

Step4: Configure ld to find your shared libs

cat >> /etc/ld.so.conf.d/opt-python2.6.conf /opt/python2.6/lib (hit enter) (hit ctrl-d to return to shell) ldconfig

 

Step 5: Test python 2.6 installation

On the console type python, and you should get an interactive Python 2.6 session like:

Python 2.6 (r25:XXXX, Dec 11 2009, 23:18:24) [GCC X.XXXXX.X Type "help", "copyright", "credits" or "license" for more information. >>> Hit ctrl-d to exit

 

Step 6: Install setuptools

cd.. wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg#md5=bfa92100bd772d5a213eedd356d64086 sh setuptools-0.6c11-py2.6.egg --prefix=/opt/python2.6

 

Step 7: Install MySQL

wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm yum --enablerepo=remi install mysql-server mysql-devel python-devel

 

Step 8: Install MySQLdb package

wget http://internap.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz tar xvfz MySQL-python-1.2.2.tar.gz cd MySQL-python-1.2.2 python setup.py build python setup.py install

 

Verify MySQL-Phyton DB adapter:

On the console type python, and you should get an interactive Python session . In the session prompt below:

Python 2.6 (r25:XXXX, Dec 11 2009, 23:18:24) [GCC X.XXXXX.X Type "help", "copyright", "credits" or "license" for more information. >>> Hit ctrl-d to exit

 

Type

import MySQLdb

 

There should be no errors on the screen. So far so good!

 

Step 9: Install Apache2 and Apache2 Devel

yum install httpd yum install httpd-devel

 

Step 10: Installing mod_wsgi

What is mod_wsgi?

The aim of mod_wsgi is to implement a simple to use Apache module which can host any Python application which supports the Python WSGI interface. The module would be suitable for use in hosting high performance production web sites, as well as your average self managed personal sites running on web hosting services.

 

Why mod_wsgi?

The consensus seems to be that mod_wsgi is the prefered Apache module (as opposed to mod_python). It's stable, less memory intensive, and faster.

 

Configure and Install mod_wsgi to link with Python 2.6 shared libs:

cd /opt/python2.6/lib/python2.6/config ln -s ../../libpython2.6.so . cd wget http://modwsgi.googlecode.com/files/mod_wsgi-3.1.tar.gz tar xvfz mod_wsgi-3.1.tar.gz cd mod_wsgi-3.1 ./configure --with-python=/opt/python2.6/bin/python make make install

 

It’s important to read the mod_wsgi docs on building with shared libs - mod_wsgi should compile to around 250kbytes.

Confirm that the size of mod_wsgi.so is around 250 Kilobytes:

ls -Al /usr/lib/httpd/modules/mod_wsgi.so

 

Mine turned out to be around 295 kilo bytes.

 

Add mod_wsgi to Apache 2.x:

vi /etc/httpd/conf/httpd.conf LoadModule wsgi_module /usr/lib/httpd/modules/mod_wsgi.so

 

Restart Apache

service httpd restart

 

Check if mod_wsgi is loaded in the loaded module list by typing:

httpd -M

 

Step 10: Next Download Django.

Assuming your django download is extracted in /usr/src/django

ln -s /usr/src/django/django /opt/python2.6/lib/python2.6/site-packages/

 

You should now be up and running django on CentOS.

 

Important Notes:

1. SElinux does not go very well with wsgi environment. For testing, please turn off SElinux and then try these steps.

2. Apache might use wrong python version while calling wsgi handlers. Use wsgihome and wgipythonpath directives inside the httpd.conf to point it correctly.

3. In case of any errors, check the Apache error log for more details. You can always post a comment here, in case of any help.

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1406940/Venky2.jpeg http://posterous.com/users/4SykxB4hhgl3 Venky Venky Venky
Sun, 12 Sep 2010 18:26:00 -0700 Run FusionPBX for FreeSWITCH on CentOS in 4 steps http://www.venkysblog.com/run-fusionpbx-for-freeswitch-on-centos-in-4-s http://www.venkysblog.com/run-fusionpbx-for-freeswitch-on-centos-in-4-s

Below are some of the features of FusionPBX:

Unlimited extensions, voicemail-to-email, music on hold, call parking, Direct Inward System Access, Auto Attendant, Call Detail Records, Call Monitoring, Call Routing etc..

For a complete list visit their website

 

Note: If you already have Apache, PHP and MySQL & Phpmyadmin setup, then jump directly to step 4

 

Step 1: Install Apache2

yum install httpd httpd-devel

 

Step 2: Install PHP 5.3(with PDO) & MySQL

Since CentOS does not yet ship a recent enough version of PHP, so we you use the RPMs provided in the REMI repository. To do so:

wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm

Now use remi to install php and MySQL

yum --enablerepo=remi install php php-common php-mysql php-gd php-mbstring php-mcrypt php-devel php-pdo php-soap php-xml php-xmlrpc mysql mysql-server mysql-devel

 

Step 3: Install Phpmyadmin (This step is optional)

yum --enablerepo=remi install phpmyadmin

You might encounter the following errors while configuring phpmyadmin.

 

1. Forbidden : You don't have permission to access /phpmyadmin/ on this server.

Fix: vi /etc/httpd/conf.d/phpmyadmin.conf

Remove or comment the first two lines in bold.

#Order Allow,Deny #Deny from all Allow from 127.0.0.1

 

2. Error: The configuration file now needs a secret passphrase (blowfish_secret)

Fix:  vi /usr/share/phpmyadmin/conf.inc.php

Look for a line and enter any password. Just dont leave it empty!

$cfg['blowfish_secret'] = 'mydemopass';   /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

 

Now, Restart the Apache Server service httpd restart To Test

1. Open http://localhost/phpmyadmin in your local web browser. You should be prompted for authentication

2. Enter the system root username and password and click OK

3. You should now be presented with the phpMyAdmin home page

 

Step 4 : Download and install FusionPBX

cd /var/www/html wget http://www.fusionpbx.com/downloads/fusionpbx-1.0.tar.gz tar -zxvf fusionpbx-1.0.tar.gz service httpd restart

 

Next create a database name fusionpbx using Phpmyadmin. If needed you can also create a separate db user or by default we can use root.

Now Open the fusionpbx Auto-Install Wizard

http://(yourserver hostname or localhost)/fusionpbx/install.php

 

On the Install screen enter the mysql db name, user, password you created. For the database host you can use localhost and the port can be empty. On Submission, if you see any of the below errors, then please fix these before trying again:

 

  • Write access to /var/www/html/fusionpbx/includes/ is required during the install.
  • Write access to the 'FreeSWITCH Directory' and most of its sub directories is required.
  • Write access to the 'Secure Directory' is required. If the /var/www/html/fusionpbx/secure is incorrect please change it below.
  • Write access to /var/www/html/fusionpbx and its sub-directories are required during the install.

This is basically a permission issue, so change the permissions for write access Correct all the errors before you proceed further. Then click "Install" button to proceed further. If all goes well, you should see a "Congratulations Page".

 

Cool... We are done.. Now play around with freeswitch and this powerful GUI. Special thanks to Mark J Crane, the lead developer of Fusion, for supporting me through the install. It was a breeze.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1406940/Venky2.jpeg http://posterous.com/users/4SykxB4hhgl3 Venky Venky Venky
Sun, 12 Sep 2010 18:26:00 -0700 Setup Django on Windows with Apache and MySQL in 15 mins http://www.venkysblog.com/setup-django-on-windows-with-apache-and-mysql http://www.venkysblog.com/setup-django-on-windows-with-apache-and-mysql

Django is an open source web application development framework, for python. I am totally impressed with it as it allows rapid application development and provides a brilliant auto generated administrative interface for the web app. Setting up Django on Windows without Apache & Mysql is fairly out of the box, but doing that in production is not recommended. Hence I tried to use existing portable and ready made stacks for Django on windows. Having tried them I would say, I wasted around 6 hours trying to get everything working.

Bottom line: I decided to install Django on windows on my own using WAMP + mod_wsgi + mysql_python to run Django on windows. Lets see how:

 

Step 1: Install Python

The first step is to get the latest version of Python installed.

Head over to Python.org and download the stable installer version (2.6.X) for Windows. Double click and run it.

The install is fairly simple, and involves clicking through the installer steps.

For the rest of this post, the assumption is that installed Python in "C:\Python26\"

 

 

Step 2: Download and setup Django

Download and extract the Django files.

Copy the complete directory named "django", inside the extracted directory and paste it under "C:\Python26\Lib\site-packages\"

Quick check: File "django-admin.py" should exist under the path "C:\Python26\Lib\site-packages\django\bin"

Now to be able to run python and Django from windows command line lets add it into the path variable.

Right click on “My Computer” and select Properties. Go to Advanced, then Environment Variables at the bottom.

 

Edit “Path” and at the end add the following:

";C:\Python26;C\Python26\scripts;C:\Python26\Lib\site-packages\django\bin\”

On the Windows command line type python If you see an interactive python shell, Python is installed and running properly.

To check Django installation, type import django You should see no errors.

 

Congratulations Django is successfully installed on your system.

At this point, it would probably be a good idea to make sure that your Django install works before you attempt to get it working with Apache and mod_wsgi.

 

So move forward to create a basic Django project and test the setup. From the command prompt, enter into directory name where you wish to create your project:

C:\ cd djangoTest

 

Type the following to create the dummy project:

C:\djangoTest django-admin.py startproject testproject

 

 

Now lets go inside the created project and run the project:

C:\djangoTest cd testproject C:\djangoTest\testproject python manage.py runserver

 

You should get something like this on your screen:

Validating models... 0 errors found. Django version 1.1.1, using settings 'testproject.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. [10/Dec/2009 20:45:50] “GET / HTTP/1.1? 404 2063

 

Now, open your browser and type: 127.0.0.1:8000 and press enter.

 

If all was good, you should have your Django test page up.

 

Step 3. Install WAMP

Download the WAMP stack.

Double click and run the installer.

Once again, the actual installation is simple and consists of clicking through the default installer steps. After it is installed, you will the WAMP icon in your system tray. Left click on it and select "Start all Services". After 10 seconds, left click again and click put online. Apache and MySQL should be running now.

 

To ensure Apache is running on port: 80, open the browser and type localhost.

 

You should see the WAMP page now. Congrats.

 

 

Step 4: Install mysql_python 2.6 for Mysql

Download MySQL_Python2.6 module binary here

Run and install the file you just downloaded. Its a simple install.

 

Now, let’s test if the MySQL works currently with Django. Edit the database setting in ‘testproject/settings.py’.

Here’s what I fill in: (‘root’ is the default user)

DATABASE_ENGINE = ‘mysql’ DATABASE_NAME = <enter your db name here> DATABASE_USER = ‘root’ DATABASE_PASSWORD = '' DATABASE_HOST = '' DATABASE_PORT = ”

 

Run the server if it isn’t started:

C:\djangoTest\testproject python manage.py runserver

 

If you see no error messages(in the browser and the console), the database works correctly with python. To do a bit of testing, we can set our user name wrongly on purpose and watch Python throw out the errors then correct it. So far so good.

 

Phew now the final step...

 

Step 5:Install and enable mod_wsgi with Apache to run Django

Download the correct mod_wsgi file based on your apache and python. If you have followed this tutorial step by step you have Apache 2.2 and Python 2.6.

Rename the downloaded file as "mod_wsgi.so"

Copy the renamed file mod_wsgi.so to "C:\wamp\bin\apache\Apache2.2\modules" folder.

Now, open the Apache configuration file, located at "C:\wamp\bin\apache\Apache2.2\conf\httpd.conf" with notepad.

Scroll down and look for a section that includes a bunch of lines that start with LoadModule. Add the following line towards the end of that section:

LoadModule wsgi_module modules/mod_wsgi.so

Before we move further, copy your Django testProject folder into "C:/wamp/www".

This is not mandatory, but I did this, and the remaining instructions below are based on that.

Once you’ve got mod_wsgi installed and activated, edit your httpd.conf file and add: WSGIScriptAlias / "c:/wamp/www/testProject/django.wsgi"

Next we'll need to actually create the django.wsgi WSGI application, so create a file "django.wsgi" and add:

import os, sys sys.path.append('c:/wamp/www/') os.environ['DJANGO_SETTINGS_MODULE'] = 'testProject.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()

 

Now restart Apache, and boom you should see your "It Worked" Page.

 

Congratulations!! Wasn't this easy, and just in time - 15 mins ... If this helps you, leave a comment, tweet or share this post.

 

PS: Updated this post with typos and other errors based on input from justin. Many thanks to him for pointing it out.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1406940/Venky2.jpeg http://posterous.com/users/4SykxB4hhgl3 Venky Venky Venky
Sun, 12 Sep 2010 18:26:00 -0700 Tutorial: Write your own GTalk custom bot in 10 mins!! http://www.venkysblog.com/tutorial-write-your-own-gtalk-custom-bot-in-1 http://www.venkysblog.com/tutorial-write-your-own-gtalk-custom-bot-in-1

A Chat bot is completely automated, that is online 24×7 and will always send & respones to your requests, just like a virtual friend. You can do lot of interesting stuff  like receive alert notifications, post to twitter, book tickets, set reminders, write blogs, and so much more.

Now the reason I am specifically looking at GTalk here is, coz its on open standards - XMPP !!

So how do we write your GTalk custom bot in 10 minutes!


The Solution: We will write a basic chat bot which will change its status message on our command, using an Opensource Framework PYGtalkRobot.Later, you can expand the idea to more complex tasks like posting to twitter or checking emails etc..

Requirements:

-- Geeky mindset, with basic language skills of python.

-- Linux server running Centos with SSH access

-- 2 Gtalk user accounts.

 

Lets, Get Started..

Step 1: Install Python - 2.4 and above

  yum install python

Step 2: Download and unpack xmpppy.

To install it go into the unpacked directory and run:

python setup.py install

Step 3: Download and unpack pydns.

To install it go into the unpacked directory and run:

python setup.py install

 

Step 4: Next, Checkout the source code for pygtalkrobot from SVN server:

svn checkout http://pygtalkrobot.googlecode.com/svn/trunk/pygtalkrobot/src pygtalkrobot-read-only

Step 5: Setup the Bot

 The pygtalktrobot directory contains the file:'sampleRobotcode.py".In this file, edit the following lines:

Change the following lines as below:

--  if jid == 'ldmiao@gmail.com': to  'ldmiao@gmail.com' to your gtalk id, so that this bot recognizes you as the admin. --  bot.start("account_name@gmail.com", "password")  to "account_name@gmail.com" & "password" to your second gtalk account details through which the bot will login.

Step 6: Run the sampleRobot

python sampleRobotcode.py

Your sample bot should start running now, and the status should show connected.

 

Step 7: Add the gtalk bot user as a friend in your Gtalk Messenger.

Gtalk bot will automatically accept you as a friend.

 

Step 8: Once added, send the command "online GTalk Bot".

This will change the status message of the bot to "GTalk Bot". Hurray!! Your own bot is ready and it responds to the commands..

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1406940/Venky2.jpeg http://posterous.com/users/4SykxB4hhgl3 Venky Venky Venky