Tareq Alam

i have promises to keep and miles to go before i sleep – Robert Frost

install python 2.4.3 in ubuntu 8.10 March 15, 2009

Filed under: Ubuntu, Zope, ploneCMS, python — tareqalam @ 2:14 pm
Tags: , ,

I have got error at first when i tried to install python 2.4.3 in ubuntu 8.10

error is something like this:

/usr/bin/install -c -m 644 ./LICENSE /usr/local/lib/python2.4/LICENSE.txt
PYTHONPATH=/usr/local/lib/python2.4   \
./python -Wi -tt /usr/local/lib/python2.4/compileall.py \
-d /usr/local/lib/python2.4 -f \
-x ‘badsyntax|site-packages’ /usr/local/lib/python2.4
*** buffer overflow detected ***: ./python terminated
then i searched the net for solution i got this

https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/286334

and the solution isgo inside the python 2.4.3 directory

$ ./configure CC=gcc-4.2 # works
$ ./configure OPT=”-g -O0″ # works

then

$ make

$sudo make install

then the python 2.4.3 will be installed

I need that version of python to run the bootstrap.py of plone svn

now I am happy that the buildout is running ..

Thanks

 

python setlocale .. not working?make it work.. November 22, 2008

Filed under: Ubuntu, python — tareqalam @ 2:46 pm
Tags: , , , ,

when you are using the function in python:

locale.setlocale(locale.LC_ALL, ‘en_GB‘)

have you got this error message?

return _setlocale(category, locale)
locale.Error: unsupported locale setting

Then you should do what I have done in ubuntu..

This intelligent man helped me .. please go to this link and follow the steps to add the locale to the list of ’supported locales’

http://blog.andrewbeacock.com/2007/01/how-to-change-your-default-locale-on.html

Also I am writing it here for your convenience:

Edit /var/lib/locales/supported.d/local and add the following line:
en_GB ISO-8859-1

Then run the python script again .. hope it will not show error this time

THanks

 

R and Rpy September 21, 2008

Filed under: Linux, Ubuntu, python — tareqalam @ 1:14 pm
Tags: , , , ,

R is a strong language. And there is a way in python with that R can be used that is called Rpy http://rpy.sourceforge.net/

its easy to install. here I will show you an example to create simple graphics using rpy

from rpy import *

def create_simple_bar_chart(file_name,size=5,bottom=1,left=0.5,top=0,right=0):
if bottom>left:
graphics_width = size+bottom;
graphics_height = size+bottom;
if left>bottom:
graphics_width = size+left;
graphics_height = size+left;
if left==bottom:
graphics_width = size+left;
graphics_height = size+left;

r.pdf(file_name,graphics_width,graphics_height,paper=”a4″,pagecentre=r.F)
r.par(omi=r.c(bottom,left,top,right))
r.par(pty = “s”)
r.plot(r.table(r.rpois(150,7)),ylab=”hospital”,xlab=”patient”, type = “h”, col = “red”, lwd=10,main=”number of patients per hospital”)
r.dev_off()

def create_hist_with_R(file_name,size=5,bottom=1,left=1,top=0,right=0):
x = [24,60,18,63,32,47,88,64,72,87,100,16,37,46,50,\
64,11,45,77,35,38,39,84,90,6,87,25,67,51,71,52,\
98,57,5,65,75,8,68,35,75,95,29,50,44,30,1,92,93,\
56,56]

if bottom>left:
graphics_width = size+bottom;
graphics_height = size+bottom;
if left>bottom:
graphics_width = size+left;
graphics_height = size+left;
if left==bottom:
graphics_width = size+left;
graphics_height = size+left;

r.pdf(file_name,graphics_width,graphics_height,paper=”a4″,pagecentre=r.F)
r.par(omi=r.c(bottom,left,top,right))
r.par(pty = “s”)
#r.plot(r.table(r.rpois(100,5)),xlab=”frequency”, type = “h”, col = “red”, lwd=10,main=”rpois(100,lambda=5)”)
r.hist(x, xlab=”frequency”, ylab=”count”, main=”histogram example using R”, col=’cyan’)
r.dev_off()

def create_simple_bar_chart_rainbow(file_name,size=5,bottom=1,left=0.5,top=0,right=0):
if bottom>left:
graphics_width = size+bottom;
graphics_height = size+bottom;
if left>bottom:
graphics_width = size+left;
graphics_height = size+left;
if left==bottom:
graphics_width = size+left;
graphics_height = size+left;

r.pdf(file_name,graphics_width,graphics_height,paper=”a4″,pagecentre=r.F)
r.par(omi=r.c(bottom,left,top,right))
r.par(pty = “s”)

r.plot(r.cos, -r.pi, 2*r.pi,col=r.rainbow(20),ylab=”biologic”,xlab=”total”,main=”Test Data”)

r.dev_off()
def draw_pie_chart(file_name,size=5,bottom=1,left=0.5,top=0,right=0):
if bottom>left:
graphics_width = size+bottom;
graphics_height = size+bottom;
if left>bottom:
graphics_width = size+left;
graphics_height = size+left;
if left==bottom:
graphics_width = size+left;
graphics_height = size+left;

r.pdf(file_name,graphics_width,graphics_height,paper=”a4″,pagecentre=r.F)
r.par(omi=r.c(bottom,left,top,right))
r.par(pty = “s”)

r.pie(r.rep(1, 24), col = r.rainbow(24), radius = 0.9,main=”test pie chart”)

r.dev_off()

draw_pie_chart(“rgraphics_pie.pdf”,5,1,1,0,0)

create_hist_with_R(“rgraphics_hist.pdf”,5,1,1,0,0)

create_simple_bar_chart(“rgraphics_bar.pdf”,4,5.5,0.5,0,0)

 

pyExcelerator: Python exportar Excel to MySQL June 20, 2008

Filed under: ploneCMS, python — tareqalam @ 12:43 pm
Tags: , , ,

Hi all… here is the code to import the xls data into mysql using pyexcelerator and python.. About the pyexcelarator installation and configuration i have discussed an article… click this link to view that if you dont have any idea what is pyexclerator.. http://tareqalam.wordpress.com/2008/05/03/python-exportar-mysql-to-excel/

Now here is the python script which takes input a xls file and inserts the comment field it into the mysql table. basically it is helpful if you want to add comment to a mysql table.. I know there is some other easy way to do that.. but this code by making some customization you can insert data also.. Maybe my coding is not that rich.. but i am trying to help people.. if my code helps people a little i will be happy.. so hav e a look on the code…

import pyExcelerator
import sys
from pprint import pprint as pp

#put the table name here
table_name = 'test_table'
#put the xls file name here after modifying the commet fields
xls_file = 'test_table.xls'


sql_array = []
try:
workbook = pyExcelerator.parse_xls(xls_file)
except:
sys.exit('cant load %s '%xls_file)
worksheet = workbook[0]
# print cells A1 and B1
rowvalue= worksheet[1]
#pp(worksheet)
#sys.exit(1)
err_flag=0
#print t[(10,0)]
#print len(row_value.keys())
i = 1
for row_idx, col_idx in sorted(row_value.keys()):
if row_idx !=0:
err_flag=0
try:
MODIFY_FIELD_COMMENT = row_value[(i,0)]
except:
err_flag=1
try:
MODIFY_FIELD_NAME = row_value[(i,4)]
except:
err_flag=1
try:
MODIFY_FIELD_TYPE = row_value[(i,8)]
except:
err_flag=1

if err_flag == 0:
sql_for_insert_data_into_table="alter table %s modify %s %s COMMENT '%s'"%(table_name,MODIFY_FIELD_NAME,MODIFY_FIELD_TYPE,MODIFY_FIELD_COMMENT)
sql_array.append(sql_for_insert_data_into_table)
i=i+1


#print sql_array

#now inserting comments are done here

import MySQLdb

conn = MySQLdb.connect(host='localhost',user='root',passwd='',db='test_db')
cu = conn.cursor()
for insert_row_sql in sql_array:
try:
cu.execute(insert_row_sql)
except MySQLdb.Error, e:
errInsertSql = "Insert Sql ERROR!! sql is==>%s" %(insert_row_sql)
print errInsertSql
#sys.exit(errInsertSql)
continue
print 'done!! see in the database the %s table field\'s comment'%table_name
#pp(worksheet)

Pleas contact me if you are unable to understand any thing.. i ll try to help you ..

Thanks…

 

pyExcelerator : Python exportar MySQL to Excel May 3, 2008

Filed under: ploneCMS, python — tareqalam @ 11:33 am
Tags: , , ,

Lets try to create Excel Files using python. There is a Addon for python named pyExcelerator. First you have to install it. Thats easy just go to http://sourceforge.net/projects/pyexcelerator
download pyExcelerator. Unpack it any where. Point folder from terminal as root. then
python setup.py build then type python setup.py install

Now here is a simple code to create an excel file of a table of MySQL database.
To connect with MySQL you need MySQL python its easy to install search google for installing MySQL Python.

My objective is to show you an easy code to create Excel file using python.

The code is given below:
__rev_id__ = """$Id: blanks.py,v 1.2 2005/07/22 08:22:26 rvk Exp $"""
#importing is done here
from pyExcelerator import *
import sys
import MySQLdb

#get data from mysql
table_name = "tareqfolder" #change the table name to the table name from which you want to create xls
sql_select="SELECT * FROM %s"%table_name
conn1 = MySQLdb.connect(host='host_name',user='mysql_user',passwd='secret_passwd',db='database_name') #connection information(change according to your mysql server)
cu_select=conn1.cursor(MySQLdb.cursors.DictCursor)

try:

    cu_select.execute(sql_select)

except MySQLdb.Error, e:

    errInsertSql = "Insert Sql ERROR!! sql is==>%s" %(sql_select)
    sys.exit(errInsertSql)

result_set = cu_select.fetchall()

#creation of excel file starts here
wb = Workbook()
ws0 = wb.add_sheet('0')

borders = Borders()
borders.left = 1
borders.right = 1
borders.top = 1
borders.bottom = 1


borders_cell = Borders()
borders_cell.right = 1

TestNoPat = Pattern()
TestNoPat.pattern = Pattern.SOLID_PATTERN
TestNoPat.pattern_fore_colour = 0x07

Alg = Alignment()
Alg.horz = Alignment.HORZ_CENTER
Alg.vert = Alignment.VERT_CENTER

row_number=1
for row in result_set:

    i=0
    for item in row:

val=str(row[item])

if row_number==1:

    style = XFStyle()
    style.borders = borders
    style.pattern = TestNoPat
    style.alignment = Alg
    ws0.write(0,i,'', style)
    ws0.write(0,i,item, style)
    style = XFStyle()
    style.borders = borders_cell
    ws0.write(row_number,i,val, style)
    i= i+1

else:

    style = XFStyle()
    style.borders = borders_cell
    ws0.write(row_number,i,val, style)
    i=i+1

row_number=row_number+1

wb.save('%s.xls'%table_name)
#xcel file created

print "SUCCESSFUL see in the directory a %s.xls is created "%table_name

 

PyRTF : create RTF file using Python May 3, 2008

Filed under: ploneCMS, python — tareqalam @ 10:45 am
Tags: , , , , ,

Rich Text Format (RTF) Document Generation in Python. To know more about PyRTF click here http://pyrtf.sourceforge.net/
Download
clck here to download pyrtf

Lets dive into the task. For this you need Python,Pyrtf installed in your pc. To install Python just ask google.
To install PyRTF just download from the given link. then unpack it any where then in Linux system open a terminal window go to the unpacked folder location and type python setup.py build
then python setup.py install
this should install PyRTF into your system.

Now I am giving an example where a RTF file can easily be created:

#!/usr/bin/env python
import sys
sys.path.append( ‘../’ )
from PyRTF import *
SIMPLE_TEXT=”this is simple pyrtf example….. hello pyrtf”

def test_rtf_generate():

    doc = Document()
    ss = doc.StyleSheet
    section = Section()
    doc.Sections.append( section )
    # text can be added directly to the section
    # a paragraph object is create as needed
    section.append( ‘Example 1′ )
    # blank paragraphs are just empty strings
    section.append( ” )
    # a lot of useful documents can be created
    # with little more than this
    section.append( ‘A lot of useful documents can be created ‘
    ‘in this way, more advance formating is available ‘
    ‘but a lot of users just want to see their data come out ‘
    ‘in something other than a text file.’ )
    return doc

def OpenFile( name ) :

    return file( ‘%s.rtf’ % name, ‘w’ )

if __name__ == ‘__main__’ :

    print “this is done by Tareq…….”
    DR = Renderer()
    doc3 = test_rtf_generate()
    DR.Write( doc3, OpenFile( ‘myrtf_doc’ ) )
    print “Finished”
    print “see in the current directory a myrtf_doc.rtf is created!!”

For your information it may cause problem if you just copy paste this code. You better write down in a file. That will make the code run easily. And your programming concept will also be clear by writing code. To learn a Programming language everyone should write down the codes rather than just copy pasting.
let me know if you face any problem running this code. Thanks for reading this.:)

 

Google App Engine!! April 23, 2008

Filed under: python — tareqalam @ 2:28 am
Tags: , ,

google

What is it??

Google App Engine lets you run your web applications on Google’s infrastructure. App Engine applications are easy to build, easy to maintain, and easy to scale as your traffic and data storage needs grow. With App Engine, there are no servers to maintain: You just upload your application, and it’s ready to serve your users.

The Application Environment..

Its just too cool!!

Google App Engine makes it easy to build an application that runs reliably, even under heavy load and with large amounts of data. The environment includes the following features:

  • dynamic web serving, with full support for common web technologies
  • persistent storage with queries, sorting and transactions
  • automatic scaling and load balancing
  • APIs for authenticating users and sending email using Google Accounts
  • a fully featured local development environment that simulates Google App Engine on your computer

Google App Engine applicationsgoogle are implemented using the Python programming language. The runtime environment includes the full Python language and most of the Python standard library.

To download the sdk clickhere . Follow the installation instructions.
For getting started with this engine click here
This is a great engine for python developer. I am just learning this and I believe this is very much helpful for all developer from beginner to advanced… So long live google….

 

Install Eclipse,Pydev and Subeclipse April 17, 2008

Filed under: Ubuntu, ploneCMS, python — tareqalam @ 6:50 am
Tags: , , , ,

Install eclipse, Pydev and Subeclipse in ubuntu

1.apt – get  install eclipse
or
go to System->Administration->Synaptic Package Manager
I. Enter Root Password
ii. click search
iii. type eclipse
iv. select eclipse click right mouse button select mark for installation
v. click apply
vi. click next then sit back and relax
2. Install Pydev
apt -get install pydev
or
go to System->Administration->Synaptic Package Manager
i. Enter Root Password
ii. click search
iii. type pydev
iv. select pydev click right mouse button select mark for installation
v. click apply
vi. click next then sit back and relax
3. Install Subeclipse
start eclipse
Install Subclipse:
Again navigate the menus to: “Help” – “Software Updates” – “Find and Install…”.
Select “Search for new features to install” and click “Next >”.
On the “Install” page click the button “New Remote Site”.
For “Name:” enter “Subclipse”. For “URL:” enter “http://subclipse.tigris.org/update_1.0.x”
Ensure that only “Subclipse” is included (checked) in the “Sites to include in search” and click the “Finish” button.
In the “Updates” window select “Subclipse” by checking the box next to it and click the “Next >” button.
Read the License Agreement, accept the terms, and click the “Next >” button.
The downloads should be installed into the .eclipse folder in your home directory by default. If this is acceptable click the “Finish” button.
Wait for the downloads to complete.
Once the downloads are complete click the “Install” button on the “Verification” screen.
When it is recommended that Eclipse be restarted click “Yes”.

 

Install Plone CMS March 19, 2008

Filed under: ploneCMS, python — tareqalam @ 1:27 pm
Tags: , ,

here i am trying to explain how i have installed plone in ubuntu linux system.

First, download the tar ball from here

http://plone.org/products/plone

click on Get Plone for Linux

next, extract it any where in ur linux system

this cms installation requires

  • gcc, the GNU Compiler Collection.
  • g++, the C++ extensions for gcc.
  • GNU make, the fundamental build-control tool.
  • GNU tar. This is the version of tar on all Linux, BSD and OS X platforms, but not Solaris. Your tar utility must be able to handle long pathnames and bzip2 and gzip compression.

if u dont have these don’t wory just go to

system->Adminstration->synaptic package manager then search g++,c++ and mark the softwares then click on apply button.

Now, open a terminal window to write commands

tar zxf Plone-3.0.VERSION-UnifiedInstaller.tar.gz  this will extract the package

Then change into the newly created directory:

cd Plone-3.0.VERSION-UnifiedInstaller

Running install.sh

If you’ve chosen to install with root privileges, either su to root or precede these commands with sudo.

ZEO Installation:

./install.sh zeo


Stand-Alone Zope Installation:

./install.sh standalone

Checking your installation

If your installation succeeded, try starting it by following the instructions displayed at the end (or in the “adminPassword.txt” file). Startup problems are uncommon, but do occasionally happen. The most common cause is that some other process has already claimed the 8080 port (or one or more of the 8100, 8080 and 8081 ports if you’re using ZEO). You may wish to stop or kill the competing process if it’s an old Zope/Plone installation. If not, you may reassign the ports used by your Plone installation by editing the etc/zope.conf (and etc/zeo.conf for the ZEO server) to reassign ports.

If the start is successful, test your installation by opening a web browser and navigating to http://localhost:8080. (If you’re testing on another machine, substitute your server host name for “localhost”.)

You should see a Zope welcome message. A test Plone site should be available at http://localhost:8080/Plone, and the Zope Management Interface at http://localhost:8080/manage.

If Zope appears to be running, but you cannot connect, check to see if a firewall may be in place and blocking the connection.