Monday, May 31, 2010

How to Setup Logo in Plone!

1. Logo
========
Go to the Zope Management Interface (Site Setup > Zope Management Interface)

Go to portal_skins > plone_images

Click logo.jpg and then click the customize button

Now replace the image by clicking the browse button and choosing your own image from your file system

Edit the Title field (this will ensure that the title attribute changes in the HTML)

Save your changes and refresh your browser to see the changes on your site

OR


Go to the Zope Management Interface (Site Setup > Zope Management Interface)

Make sure that you've switched your css registry to debug mode (portal_css)

Go to portal_skins > custom and choose Image from the drop down list on the right

Upload your own image giving it an ID and a Title e.g.:

ID = MyLogo.jpg
Title = My Logo

Go to portal_skins > plone_styles, click base_properties and then click the customize button
You'll now have a customized version of base_properties in the custom folder of portal_skins which you can change as you like. Find the logoName field and replace the value logo.jpg with the ID you gave your image (if you gave your ID a .jpg or .gif suffix, make sure you include that, and remember that it is case-sensitive) e.g.:
logoName = MyLogo.jpg
Save your changes and refresh your browser

Size
-----
ZMI -> /portal_view_customizations -> plone.logo -> manage_main

How to install new Packages in Plone!

2. Installing a new Package in Plone
=========================

To install an egg-based product, first unpack your theme product (if in a .tgz, .tar.gz or zip archive). Copy the package to the src/ folder of your buildout. Then, edit your buildout.cfg and add the following information into the buildout, instance, and zcml sections. The actual buildout.cfg file will be much longer than the snippets below:

[buildout]
...
develop =
src/plonetheme.yourtheme (where yourtheme is the name of the theme you downloaded)

[instance]
eggs =
...
plonetheme.yourtheme

zcml =
...
plonetheme.yourtheme

The last line tells buildout to generate a ZCML snippet (slug) that tells Zope to recognize your theme product, prefixed by the namespace (plonetheme is the default). The dots [...] indicate that you may have additional lines of ZCML code here. If another package depends on the theme egg or includes its ZCML directly, you do not need to specify anything in the buildout configuration; buildout will detect this automatically. This is considered a more advanced topic.

After updating the configuration you need to run the ''bin/buildout'', which will refresh your buildout.

Then, restart your site and go to the 'Site Setup' page in the Plone interface and click on the 'Add/Remove Products' link. The 'Site Setup' area is also known as plone_control_panel, as this is the URL used to get to 'Site Setup'.

Choose the product by selecting the checkbox next to it and click the 'Install' button.


To install older version of product simply copy the package after extracting into products directory....

typical location may be...
/usr/local/Plone/zinstance/products
Then, restart your site and go to the 'Site Setup' page in the Plone interface and click on the 'Add/Remove Products' link.


SVN Configuration on Linux!

1. Install the Subversion

2. Create a new Repository:
Suppose to create a Repository at /usr/local/subversion/repository using fsfs database so execute the command:

mkdir -v /usr/local/subversion/
svnadmin create --fs-type fsfs /usr/local/subversion/repository

That should create a subversion repository under /usr/local/subversion/repository.

ls /usr/local/subversion/repository
conf/ dav/ db/ format hooks/ locks/ README.txt

Now, change the ownership of the newly created repository...
chown -R subversion:subversion /usr/local/subversion/repository/

Now, add the newly created member to the subversion group located in /etc/group

You should be able to see those files under the repository directory.

3. Edit the /home/svn/repository/conf/svnserve.conf and enable the following lines :
[general]
password-db = passwd
realm = repository_name

4. Edit the file /home/svn/repository/conf/passwd and add the following lines:
[users]
akshat=akshat

You can add as many users in the format USERNAME=PASSWORD. The passwords are not encrypted.

5. Set a text editor as the default SVN editor:
# export SVN_EDITOR=vim

Now that your Repository and authentication schemes are set, you need to import the development source tree to the server. You can use the file protocol or the SVN protocol to import the files. If you need to make the repository available in a network then you have to set up the svnserve.

Issue the command:
# svnserve -d -r /home/svn/
This will run the svn server in daemon mode.

6. You can now import the source tree with the following command:
$ svn import /usr/local/subversion/repository svn://yourhost/repository --username akshat
or
svn import /home/akshat/svn/IYA2009 svn://mutha/usr/local/subversion/IYA2009 --username akshat

7. You can checkout the source by using the command:
$ svn checkout svn://mutha/GMRTARchive
or
svn co svn+ssh://mutha/usr/local/subversion/IYA2009

Suppose we want to checkout a repository named GOSIP we need to do the following:

svn co svn://mutha/GOSIP
cd GOSIP/
mkdir Database ; cp /home/akshat/ncra.sql Database/ncra.sql
svn add Database

Where ncra.sql is file that is sitting under Database directory.

akshat@akshat-laptop:~/GOSIP$ svn commit Database
Authentication realm: GOSIP
Password for 'akshat': ******
Adding Database
Adding Database/ncra.sql
Transmitting file data .
Committed revision 3.

svn ci Database
svn -m 'first checkin of Databse' ci Database
cd Database/
vim ncra.sql

akshat@akshat-laptop:~/GOSIP/Database$ svn stat => for checking the editing status
M ncra.sql

M=> shows that the file has been modified.

akshat@akshat-laptop:~/GOSIP/Database$ svn up
At revision 3.
up=> update

If we want to revert to a specific version than we have to use the following command:
svn merge -rHEAD:4 .
svn commit -m "Reverted to revision 3."\

==Adding SVN users:==
Since we are using svn with an apache server, and an apache basic authentication method.

We need to create a password file with the htpasswd binary provided with a standard apache installation.

htpasswd -cmd /usr/local/subversion/repository/conf/svn-auth-file {user-name}

-c option creates a new htpasswd file.
-m encrypts the password with an MD5 algorithm.
-d encrypts the password with a CRYPT algorithm.

Where {user-name} stands for an actual user name that will be used for authentication.

Warning: We should not use the -c option once we have added the first user. Using so will create and replace all existing user within the file.

htpasswd -md /usr/local/subversion/repository/conf/svn-auth-file {user-name}

Trac Installation On Linux!

Step by Step Installation of Trac on Linux:

Genshi Installation
---------------------------
python setup.py install

install setuptools

python setup.py build install (Trac Installation)

install svn

-----------------------------------

Now Install Mysql-python
$ tar -xfz MySQL-python-1.2.1.tar.gz
$ cd MySQL-python-1.2.1
$ # edit site.cfg if necessary
$ python setup.py build
$ sudo python setup.py install # or su first

If the error comes likes this during building:
error: command 'gcc' failed with exit status 1
then install the python-dev library.......
root@term146:~/Desktop/MySQL-python-1.2.2# sudo apt-get install python-dev


Install additional libraries like neon, neon-devel, python-devel, swig (Simplified Wrapper and Interface Generator)

After the installation, you have to setup the trac Environment Directory. For that create a folder any where in you system.
(mkdir myenv) and give full permission to that environment (chmod -R 777 myenv)

To make this directory as your trac environment , use the following command.
trac-admin /path/to/myenv initenv

It will ask for name of your project, mysql connection string, type of subverstion, repository path, and template of your trac.
1) Provide a name for your project
2) If you are not using mysql, the trac by default use Sqlite database . Just enter the option for blank

-----------------------------------
FOR MySQL:

A proper database can be created with any MySQL client, like this:

CREATE DATABASE trac DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
To check character set settings for your database, issue the following commands:

mysql> USE trac;
Database changed

mysql> SHOW VARIABLES WHERE variable_name IN ('character_set_database', 'collation_database');
+------------------------+----------+
| Variable_name | Value |
+------------------------+----------+
| character_set_database | utf8 |
| collation_database | utf8_bin |
+------------------------+----------+
2 rows in set (0.01 sec)

To create a user and give this user access to the database created above:

GRANT ALL ON trac.* TO tracuser@localhost IDENTIFIED BY 'password';
The connection string will then be:

mysql://tracuser:password@localhost/trac

NOTE: If mysql socket is present at /tmp/mysql.sock then create the symbolic link as--

ncra@localhost:3306 root aksncra /tmp/mysql.sock
because trac will take the Connection String from /var/lib/mysql/mysql.sock
----------------------------------------------------------

3) Enter type of subversion there. Just type ’svn’ if you are using svn subversion.

4) Enter the path to your repository

4. Tell Apache about trac.. Add the following lines to your Apache configuration file:

SetHandler mod_python
PythonHandler trac.web.mod python_frontend
PythonOption TracEnv $pathtoyourtracproject
PythonOption TracUriRoot /trac

BUT FOR MULTIPLE PROJECTS..........

SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnvParentDir /usr/local/trac/
PythonOption TracUriRoot /trac

Finally, restart httpd and try it out by going to:

http://$yourhost/trac/

5. Edit Trac.ini

6. trac-admin /usr/local/..... resync



************************************************

SETTING UP OF AUTHENTICATION TRAC WITH APACHE2

************************************************

Adding Authentication

To enable authentication with Apache is to create a password file. Use the htpasswd program to create the password file:

$ htpasswd -c /somewhere/trac.htpasswd admin
New password:
Re-type new password:
Adding password for user admin
After the first user, you dont need the "-c" option anymore:

$ htpasswd /somewhere/trac.htpasswd akshat
New password:
Re-type new password:
Adding password for user akshat

Now we can set their permissions using TracPermissions.
========================================
Now, you'll need to enable authentication against the password file in the Apache configuration:

AuthType Basic
AuthName "Trac"
AuthUserFile /somewhere/trac.htpasswd
Require valid-user
If you're hosting multiple projects you can use the same password file for all of them:

AuthType Basic
AuthName "Trac"
AuthUserFile /somewhere/trac.htpasswd
Require valid-user

For better security enable SSL or use the “digest” authentication instead of “Basic”.

LoadModule auth_digest_module /usr/lib/apache2/modules/mod_auth_digest.so
AuthType Digest
AuthName "trac"
AuthDigestDomain /trac
AuthUserFile /somewhere/trac.htpasswd
Require valid-user
and you'll have to create your .htpasswd file with htdigest instead of htpasswd as follows:

# htdigest /somewhere/trac.htpasswd trac admin
where the "trac" is the Realm.

=============
Web Admin Plugin
=============
This plugin is for administering Trac projects through the web interface.

Note: Don't forget to give permissions to your user.

trac-admin /path/to/my/project
permission add username-from-htpasswd TRAC_ADMIN
permission list username-from-htpasswd

E.g.:
Trac [/usr/local/trac/GMRTArchive]> permission add /usr/local/trac/trac.htpasswd/akshat TRAC_ADMIN
Trac [/usr/local/trac/GMRTArchive]> permission list akshat
-----> Add permission for each user and each project to have Admin Tab.............


********************
Graphical Admin Tab
********************

To access this tab, a user must have TRAC_ADMIN privileges. This can be performed as follows:

$ trac-admin /path/to/projenv permission add akshat TRAC_ADMIN
E.g. trac-admin -c /usr/local/trac/IYA2009/ permission add admin TRAC_ADMIN
-----> Add permission for each user and each project to have Admin Tab.............
Then, the user akshat will be able to see the Admin tab, and can then access the permissions menu. This menu will allow you to perform all the following actions, but from the browser without requiring root access to the server (just the correct permissions for your user account).


********************
TracAccountManager
********************

A user account management plugin for Trac.

== Installation ==
1. Run: python setup.py bdist_egg
2. If necessary create a folder called "plugins" in your Trac environment.
3. Copy the .egg file from the dist folder created by step 1 into the "plugins"
directory of your Trac environment.

== Configuration ==
Add one of the following sections to trac.ini to manage an Apache htpasswd or
htdigest file.

=== Htpasswd ===
[account-manager]
password_format = htpasswd
password_file = /path/to/trac.htpasswd

=== Htdigest ===
[account-manager]
password_format = htdigest
password_file = /path/to/trac.htdigest
htdigest_realm = TracDigestRealm

=====================
LDAP Authentication for Trac
=====================

VirtualHost *>
ServerAdmin webmaster@localhost
ServerName trac.example.com
DocumentRoot /var/www
ErrorLog /var/log/apache2/error.trac.log
CustomLog /var/log/apache2/access.trac.log combined

SetHandler mod_python
PythonInterpreter main_interpreter
PythonHandler trac.web.modpython_frontend
PythonOption TracEnvParentDir /usr/local/trac
PythonOption TracUriRoot /trac
PythonOption PYTHON_EGG_CACHE /tmp

# use the following for one authorization for all projects
# (names containing "-" are not detected):
AuthType Basic
AuthName "Authorization Required for NCRA-TIFR Trac"
AuthBasicProvider ldap
AuthLDAPURL "ldap://localhost:389/ou=people,o=ncra,c=in?uid"
AuthLDAPGroupAttribute memberUid
AuthLDAPGroupAttributeIsDN off
AuthzLDAPAuthoritative on
Require valid-user

Wednesday, January 20, 2010

MySQL Configuration in Zope/Plone

What is Zope

  • Zope Click here to access its official Website (Z Object Publishing Environment) is an open source web application server written Python on which well known CMS Plone runs. Everything in the Zope is Objects the URL is used for connecting from one Object to another. As the question arises for making dynamic pages we need one database that can talk to Zope for fetching the information from from the Zope and rendering into the HTML Page. For Presentation point of view Zope uses DTML (Dynamic Template Markup Language) which consist of DTML Documents (having identity of their own) and DTML Method (having no identity of their own) but our theme is to connect it by MySQL without further going into details of other topic I will now explain how can we connect to MySQL to the Zope.



What is ZODB/Gadfly

  • Zope also has its own Database called ZODB (Z Object Database) which is a full featured Object database and has Gadfly which is a Relational Database which has limited capability. If you are using Object Database than ZODB works fine but in case of Relational database if you are having a high traffic site or mission critical project than this database is not recommended at all.



Your RDBMS already existed

  • The other case may be that your database already existed in some other Database and you don't want to migrate to other database, here I will use MySQL Database to make a connection with Zope. The other database supported are Oracle, MySQL, SQL Server, PostgreSQL...
  • To set up a connection between the Database and the Zope u need -- Database Connection and Z SQL Method which is used for making queries to the database. (Don't get confused I will explain them)



Very 1st Step

  • But 1st and the foremost thing you have to install the MySQL from the source package, doing it so you will get know the path and various other configuration files, if you prefer installing it directly it will only trouble you. So, download the .tar file from MySQL site and follow the Instruction to install, once you have done with installing now its time to move further.



Installing MySQL from Source File....

The basic commands that you must execute to install a MySQL source distribution are:
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> gunzip <>
shell> cd mysql-VERSION
shell> ./configure --prefix=/usr/local/mysql
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql

========================================
FATAL ERROR: Could not find mysqld

The following directories were searched:

/usr/libexec
/usr/sbin
/usr/bin
========================================
IF THIS ERROR COMES THEN SIMPLY JUST DELETE THE /etc/mysql FOLDER

From the source directory run:
cp support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig mysql on
service mysql start


shell> chown -R root .
shell> chown -R mysql var
shell> bin/mysqld_safe --user=mysql &

RESTART SYSTEM!!!!!!!!!!


Key Concept

  • Remember as in case of JDBC we have to download the driver for MySQL Connection and place in the Apache Tomcat's lib directory and set the path in the .bashrc file, the concept is same here...
  • But 1 more extra step is needed here. The concept is that let the Python talk to MySQL using the driver for it and allow the Zope to talk to the MySQL by using ZMySQLDA adapter.



Step by Step Procedure

Its Time to Start Congiguration....
1. Download the Python MySQL Database Interface (MySQLdb),Download Here

2. Download Zope MySQL Database Adapter (ZMySQLDA),Download Here

3. Extract the MySQLdb .tar file and simply copy the extracted Directory in Zope add-on Products
  • Directory Location which typically may be /usr/local/Plone/Zope-2.2*************/lib/python/Products

4. Simillary Extract the ZMySQLDA .tar file and simply copy the extracted Directory in Zope add-on
  • Products Directory Location which typically may be
/usr/local/Plone/Zope-2.2*************/lib/python/Products

5. Now, see which version of python Zope is using so you have to use the python executable only bundled with the Zope otherwise MySQLdb will not be able to install or it will be installed in the wrong location which results that Zope will not be able to detect the ZMySQLDA Adapter.

6.Typically if you have installed the Zope through Plone pacakge it may typically goes to the the location/usr/local/Plone/Python-2.4/bin/python, once you have detected this then give the commands as written in the instruction in that package, like this....
  • export ZOPEBIN="/usr/local/Plone/Python-2.4/bin/"
  • $ZOPEBIN/python setup.py build
  • (If you have not installed the MySQL by source it will retun error like 'mysql_config' file not found)
  • $ZOPEBIN/python setup.py install

NOTE:
If you are getting the following Error :

error: command 'gcc' failed with exit status 1

You need to install the following package according to your machine configuration:
mysql-devel.i386 : Files for development of MySQL applications
mysql-devel.x86_64 : Files for development of MySQL applications


7. After the installation is successful you can check the MySQLdb in the python interface like this:
  • root@akshat-desktop:/home/akshat# $ZOPEBIN/python
  • root@akshat-desktop:/home/akshat# $ZOPEBIN/python
  • Python 2.4.6 (#1, Jan 7 2010, 10:23:05)
  • [GCC 4.3.3] on linux2
  • Type "help", "copyright", "credits" or "license" for more information.
  • >>> import MySQLdb;
  • Traceback (most recent call last):
  • File "", line 1, in
  • ImportError: No module named MySQLdb
  • >>>
  • Means something wrong happened during the installation..
So, check all the steps and again try unless you got no error...

One another error that can give you headache is like this...
  • Python 2.4.6 (#1, Jan 7 2010, 10:23:05)
  • [GCC 4.3.3] on linux2
  • Type "help", "copyright", "credits" or "license" for more information.
  • >>> import MySQLdb;
  • Traceback (most recent call last):
  • File "", line 1, in ?
  • File "/usr/local/Plone/Python-2.4/lib/python2.4/site-packages/MySQLdb/__init__.py", line 27, in ?
  • import _mysql
  • ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
So, remember while installing the MySQL export the path like this...
  • export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH
  • (Assuming it is installed in /usr/local)

8. Finally Restart the Zope/Plone.

9. Now go to the http://localhost:8080/manage at the dropdown you will found the Z MySQL Database Connection which you will add and later it will display a textbox where you have to pass string like this... Enter a Database Connection String : ncra@localhost:8080 root secret where
  • ncra = Database Name in MySQL
  • @localhost:8080 = host and Port Number which it is using
  • root = Username
  • secret = Password
Enjoy......
The Queries will be discussed in the next section..

ADDITION OF TABS IN MAIN NAVIGATION OF PLONE 3




First create folders for the Required sections, into which you will add content. Each of the above sections will be visible in your top-level navigation. Within each top-level folder, you can also create subfolders.
To create a folder, go to your homepage, select Add new... and choose the Folder option from the drop-down list, Specify the Title and the optional Description.
Click on Save, and then make sure that your folder has been published, after that on refreshing you can be able to see the Brand New tab which you have added.

OR
IF YOU HAVE ALREADY INSTALLED qPloneDropDownMenu-0.2.1 (VERSION NOT IMPORTANT) THAN THIS METHOD WILL NOT WORK
THEN TRY THIS
Go to the Plone Site Setup and choose the DROP DOWN MENU from the Add-on Product Configuration which you have recently installed and simply add the TAB by adding the lines for new tab by giving the path.
The Script will be like as shown except the code written between ul Tag (that code is for Drop Down Menu) if and only if you have installed the qPloneDropDownMenu-0.2.1 package otherwise older method will work.


FOR GETTING DROP DOWN MENUS

* You have to install qPloneDropDownMenu-0.2.1 and add the following lines between the TABS code like this

<li id="portaltab-Members" class="plain">
<a href="http://localhost:8080/ncra/Members" accesskey="t" title="Container for users' home directories">Users</a>
<ul>
<li><a href="localhost:8080/ncra/Members/akshat">Akshat</a></li>
<li><a href="localhost:8080/ncra/Members/xyz">XYZ</a></li>
</ul>
</li>


FULL SCRIPT WILL LOOK LIKE THIS

<li id="portaltab-index_html" class="plain">
<a href="http://localhost:8080/ncra" accesskey="t" title="">Home</a>
</li>
<li id="portaltab-Members" class="plain">
<a href="http://localhost:8080/ncra/Members" accesskey="t" title="Container for users' home directories">Users</a>
<ul>
<li><a href="localhost:8080/ncra/Members/akshat">Akshat</a></li>
<li><a href="localhost:8080/ncra/Members/xyz">XYZ</a></li>
</ul>
</li>
<li id="portaltab-gmrt-1" class="plain">
<a href="http://localhost:8080/ncra/gmrt-1" accesskey="t" title="GIANT METERWAVE RADIO TELESCOPE - KHODAD">GMRT</a>
<ul>
<li><a href="http://localhost:8080/ncra/gmrt-1/gmrt-array">GMRT Array</a></li>
<li><a href="http://localhost:8080/ncra/gmrt-1/images/folder_contents">Images</a></li>
</ul>
</li>