Tareq Alam

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

download xml of various settings of plone from zmi April 1, 2009

in zmi of plone click on portal_setup
click on export tab
click on export selected steps button and save in local
done
u can now use these xmls where u need them

 

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

 

If you forget password of ZMI (zope management interface) … dont panic November 29, 2008

Filed under: Ubuntu, Zope, ploneCMS — tareqalam @ 6:19 am
Tags: , , , ,

here is a way to create a new user of zope

open terminal … go to zope instance directory.. (cd parts/instance in my case)

then type

bin/zopectl adduser user1 password1

then a user will be created with username user1 and password passord1

you can login with this
 

Pack ZODB with repozo.py October 25, 2008

Hi I have created a script which will pack zodb. here is the code:

#pack zodb with repozo.py

### CONFIGURATION START ##########
ZOPE_HOME=/home/tareq/Plone-3.1/zeocluster/parts/zope2 # this is the zope home find your zope home #from zmi control panel
PYTHONPATH=$ZOPE_HOME/lib/python # this is the python path that the zope is using
PATH_TO_REPOZOPY=/home/tareq/Plone-3.1/zeocluster/bin/repozo.py # find the repozo.py to find in #terminal type: locate repozo.py
BACKUP_DIRECTORY=/home/tareq/plone/Learning # where you want to keep the backup of data.fs file
PATH_TO_DATAFS_FILE=/home/tareq/Plone-3.1/zeocluster/var/filestorage/Data.fs #this is the path of zodb #database Data.fs

################### N-O N-E-E-D T-O E-D-I-T A-F-T-E-R T-H-I-S L-I-N-E ##############################
export PYTHONPATH #this is needed to be done else repozo.py cant find path

COMMAND_DB_BACKUP=”$PATH_TO_REPOZOPY -BvQ -r $BACKUP_DIRECTORY -f $PATH_TO_DATAFS_FILE” # creating the command here
`${COMMAND_DB_BACKUP}` # this line executes the command

### HOW TO RUN THIS COMMAND ##########

#1. Open Terminal type sh packzodb.sh
#see files created in the BACKUP_DIRECTORY
# Simple ;)

 

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.:)

 

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.