Difference between pages "Package:Mutt" and "Zope HOWTO"

(Difference between pages)
(Mutt postfix setup)
 
m
 
Line 1: Line 1:
Mutt is a popular mail reader for Linux systems. This page is being created as a good place for people to place their mutt configurations to share with others. These configuration settings go in the user's <tt>~/.muttrc</tt> file.
+
This page documents how to use Zope with Funtoo Experimental, which currently has good Zope support thanks to [[Progress Overlay Python]] integration.
  
== Essential Mutt ==
+
== About Zope ==
  
<pre>
+
Zope is an Open Source application server framework written in Python. It has an interesting history which you should familiarize yourself with before starting Zope development, as it contains several interesting twists and turns.
set pager_stop
+
</pre>
+
  
This turns off the default behavior of mutt where hitting space to scroll will automatically move to the next message when the end of the current message is reached. This is very annoying when scrolling in long emails like cron jobs, and the line above sets this behavior to off.
+
=== Zope History ===
  
== angry_vincent's .muttrc ==
+
There are two versions of Zope, Zope 2 and Zope 3. One might assume that Zope 3 is the version that people should use for new software development projects by default, but this is not the case. Most Zope-based projects continue to use Zope 2. Zope 3 was an attempt to redesign Zope 2 from scratch, and is completely different from Zope 2, but it was not adopted by the community.
  
<pre>
+
There is also something called [http://codespeak.net/z3/five/ Five] (named because it is "2 + 3") that backports many of the new features of Zope 3 into the Zope 2 framework. Several projects will use Zope 2 plus Five in order to use some of the newer features in Zope. Five was merged into mainline Zope 2 in early 2010, and first appeared in Zope 2.8.
# General config
+
# ---------------
+
  
set folder=~/Mail   # mail folder
+
You can learn more about the history of Zope 2, 3 and Five in the [http://svn.zope.org/Zope/trunk/src/Products/Five/README.txt?view=markup Five README].
set alias_file=~/.mail_aliases    # alises file
+
set arrow_cursor   # cursor is '->'
+
set attribution="%d, %n wrote:"    # beginning of mail answer
+
set copy=yes   # save mail copies
+
set edit_headers   # edit mail header
+
set editor="vim"                               # editor
+
set folder_format="%t%N %-30.30f %8s"                        # folder list look
+
set index_format="%4C %Z %{%b %d} %-31.31F %N (%4c) %s"      # mail list look
+
set mailcap_path="~/.mailcap"                               # path to .mailcap
+
set menu_scroll # scroll list by one line
+
set mail_check=5 # mail check interval
+
set pager_stop # at the end of mail do not move to next message
+
set postponed=+drafts # postponed mails
+
set print=ask-yes # ask before print
+
set print_command=lpr # print command
+
set record=+sent # where to save sent mails
+
set signature="~/.signature" # signature file
+
set visual=vim                  # editor caled by  ~v
+
  
# mail sort
+
To make things even more interesting, work on [http://docs.zope.org/zope2/releases/4.0/ Zope 4] is underway, and it will be based on 2.13 rather than 3.x. It includes a number of [http://docs.zope.org/zope2/releases/4.0/CHANGES.html#restructuring incompatible changes] with prior versions.
set sort=threads
+
set sort_aux=reverse-date-received
+
set sort_browser=reverse-date
+
ignore *    # ignore headers so the mail body is not overloaded
+
unignore        from: subject to cc mail-followup-to \
+
                date x-mailer x-url user-agent reply-to  # fieids i like to see in mail body
+
  
# Colors
+
{{Note}} This HOWTO targets Zope 2.13, which includes Five. It is typically the version you should be using for new Zope projects.
color index brightcyan black ~N
+
color index brightyellow black ~F
+
color index black green ~T
+
color index brightred black ~D
+
mono index bold ~N
+
mono index bold ~F
+
mono index bold ~T
+
mono index bold ~D
+
  
# Highlights inside the body of a message.
+
=== Zope Resources ===
  
# URLs
+
Now that you understand what version of Zope you should be targeting (2.13), we can point you towards the correct documentation :)
color body brightgreen black "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
+
color body brightgreen black "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
+
mono body bold "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
+
mono body bold "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
+
  
# email addresses
+
; [http://docs.zope.org/zope2/zope2book/ The Zope 2 Book]: This book provides a general introduction to Zope concepts and ZMI. It is a good place to start, but doesn't provide a direct introduction to Zope development. It's recommended that you skim through this book to familiarize yourself with Zope. It generally does not assume much prior knowledge about Web development or Python.
color body brightgreen black "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"
+
; [http://docs.zope.org/zope2/zdgbook/ Zope Developer's Guide]: This guide will give you a better introduction to Zope development. It assumes you already know Python. Skip chapters 1 and 2 and start in [http://docs.zope.org/zope2/zdgbook/ComponentsAndInterfaces.html chapter 3], which covers components and interfaces. [http://docs.zope.org/zope2/zdgbook/Products.html Chapter 5] covers the creation of your first product.
mono body bold "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"
+
; Five: We're not done yet. There is a bunch of stuff in Zope 2.13 that is not in the official documentation. Namely, the stuff in Five. Check out [http://codespeak.net/z3/five/manual.html The Five Manual].
 +
; ZTK: [http://docs.zope.org/ztkpackages.html ZTK Documentation]  
 +
; ZCA: [http://www.muthukadan.net/docs/zca.html A Comprehensive Guide to Zope Component Architecture] offers a good introduction to the programming concepts of ZCA. We also have a new page on [[Zope Component Architecture]] which will help you to understand the big picture of ZCA and why it is useful. ZCML ("Z-camel") is a part of ZCA and  was introduced in Zope 3, so typically you will find ZCML documented within Zope 3 documentation and book.
 +
; Content Components: Views and Viewlets: [http://docs.zope.org/zope.viewlet/index.html This tutorial on viewlets] also contains some viewlet-related ZCML examples near the end. The "Content Component way" of developing in Zope seems to be a Zope 3 thing and tied to ZCML. Chapter 13+ of Stephan Richter's ''Zope 3 Developer's Handbook'' (book) seems to cover this quite well. You will probably also want to check out Philipp Weitershausen's ''Web Component Development with Zope 3'' (book).
 +
; [http://wiki.zope.org/zope2/Zope2Wiki Zope 2 Wiki]: Main wiki page for all things related to Zope 2.
 +
; [http://docs.zope.org docs.zope.org]: This is the main site for Zope documentation.
  
# header
+
== First Steps ==
color header green black "^from:"
+
color header green black "^to:"
+
color header green black "^cc:"
+
color header green black "^date:"
+
color header yellow black "^newsgroups:"
+
color header yellow black "^reply-to:"
+
color header brightcyan black "^subject:"
+
color header red black "^x-spam-rule:"
+
color header green black "^x-mailer:"
+
color header yellow black "^message-id:"
+
color header yellow black "^Organization:"
+
color header yellow black "^Organisation:"
+
color header yellow black "^User-Agent:"
+
color header yellow black "^message-id: .*pine"
+
color header yellow black "^X-Fnord:"
+
color header yellow black "^X-WebTV-Stationery:"
+
color header yellow black "^X-Message-Flag:"
+
color header yellow black "^X-Spam-Status:"
+
color header yellow black "^X-SpamProbe:"
+
color header red black "^X-SpamProbe: SPAM"
+
  
# Coloring quoted text - coloring the first 7 levels:
+
First, you will need to emerge {{Package|net-zope/zope}}:
color quoted cyan black
+
color quoted1 yellow black</pre>
+
  
== Interesting Color Options ==
+
<console>
 +
# ##i## emerge -av zope
 +
</console>
  
http://github.com/altercation/mutt-colors-solarized
+
Zope is now installed.
  
== golodhrim's mutt config ==
+
== Project Skeleton ==
  
First I split up my muttconfig in several subfiles under <tt>~/.mutt</tt>. The resulting files will be:
+
{{Note}} Zope should be run by a regular user account, not as the root user.
  
* ~/.mutt/account_hooks
+
The first step in using Zope is to ensure that you are using a regular user account. Create a new directory called ''<tt>zope_test</tt>'':
* ~/.mutt/colors
+
<console>
* ~/.mutt/folder_hooks
+
$##bl## cd
* ~/.mutt/gpg
+
$##bl## mkdir zope_test
* ~/.mutt/lists
+
</console>
* ~/.mutt/macros
+
* ~/.mutt/mutt-alias
+
* ~/.mutt/muttrc
+
* ~/.mutt/sidebar
+
* ~/.secret/.passwd.gpg
+
  
=== ~/.mutt/account_hooks ===
+
Now, enter the directory, and create an "instance", which is a set of files and directories that are used to contain a Zope project:
<pre>
+
<console>
#-------------------------------------------------------------------------     
+
$##bl## cd zope_test
#
+
$##bl## /usr/lib/zope-2.13/bin/mkzopeinstance
# Account Hooks
+
</console>
#-------------------------------------------------------------------------
+
account-hook . 'unset imap_user imap_pass'
+
account-hook 'imap://user@imaphost/' "set imap_user=user imap_pass=$my_pass1 "
+
</pre>
+
  
=== ~/.mutt/colors ===
+
You will see the following output, and will be prompted to answer a few questions:
<pre>
+
<console>
#-------------------------------------------------------------------------     
+
Please choose a directory in which you'd like to install
# Set colors
+
Zope "instance home" files such as database files, configuration
#-------------------------------------------------------------------------
+
files, etc.
color  attachment  brightmagenta      default
+
color  error      brightred          default
+
color  hdrdefault  red                default
+
color  indicator  brightyellow        red
+
color  markers    brightcyan          default
+
color  message    brightcyan          default
+
color  normal      default            default
+
color  quoted      brightblue          default
+
color  search      default            green
+
color  signature  red                default
+
color  status      yellow              blue
+
color  tilde      magenta            default
+
color  tree        magenta            default
+
</pre>
+
  
=== ~/.mutt/folder_hooks ===
+
Directory: instance
<pre>
+
Please choose a username and password for the initial user.
#--------------------------------------------------------------------------   
+
These will be the credentials you use to initially manage
#
+
your new Zope instance.
# Folders, mailboxes and folder hooks
+
#--------------------------------------------------------------------------
+
# Setup for imap-user in account_hooks
+
set folder="imap://user@imaphost/"
+
mailboxes =INBOX =INBOX/Archives =INBOX/Drafts =INBOX/Sent =INBOX/Trash
+
folder-hook 'imap://user@imaphost/' " \
+
    set folder=imap://user@imaphost/ \
+
        postponed=+INBOX/Drafts \
+
        record=+INBOX/Sent \
+
        smtp_url=smtp://user@smtphost \
+
        smtp_pass=$my_pass1 \
+
        #signature=~/.sig/pr.txt \
+
        from='Name Familyname <name@host> ' \
+
        realname='Realname' \
+
        pgp_sign_as='PGP-signature' \
+
        spoolfile='imap://user@imaphost/' "
+
</pre>
+
  
=== ~/.mutt/gpg ===
+
Username: admin
<pre>
+
Password: ****
# vim:syn=muttrc                                                               
+
Verify password: ****
##
+
</console>
  
set smime_decrypt_use_default_key=yes
+
Now, we will start our Zope instance:
 +
<console>
 +
$##bl## cd instance
 +
$##bl## bin/runzope
 +
</console>
  
# Decode application/pgp attachments like so:
+
Now that Zope is running, you can visit ''<tt>localhost:8080</tt>'' in your Web browser. You will see a nice introductory page to Zope.
set pgp_decode_command="/usr/bin/gpg %?p?--passphrase-fd 0? --no-verbose --batch --output - %f"
+
  
# And use this to verify pgp signatures:
+
If you now go to the ''<tt>localhost:8080/manage</tt>'' URL, you will be prompted to log in. Enter the username and password you specified. You are now logged in to the ZMI (Zope Management Interface.)
set pgp_verify_command="/usr/bin/gpg --no-verbose --batch --output - --verify %s %f"
+
  
# How to decrypt pgp encrypted messages:
+
You can stop your application by pressing Control-C. In the future, you can start and stop your Zope instance using the following commands:
set pgp_decrypt_command="/usr/bin/gpg --passphrase-fd 0 --no-verbose --batch --output - %f"
+
  
# How to pgp sign a message:
+
<console>
set pgp_sign_command="/usr/bin/gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --detach-sign --textmode %?a?-u %a? %f"
+
$##bl## zopectl start
 +
$##bl## zopectl stop
 +
</console>
  
# How to pgp clearsign a message:
+
{{Note}} ''<tt>zopectl start</tt>'' will cause your instance to run in the background rather than consuming a shell console.
set pgp_clearsign_command="/usr/bin/gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f"
+
  
# Import a pgp key from a message into my public keyring as follows:
+
== First Project ==
set pgp_import_command="/usr/bin/gpg --no-verbose --import -v %f"
+
  
# Use this to export a key from my public keyring:
+
We will create a single very primitive Zope package, consisting of an Interface for a TODO class, and a TODO class.
set pgp_export_command="/usr/bin/gpg --no-verbose --export --armor %r"
+
  
# Verify key information (from the key selection menu):
+
Create the following files and directories relative to your project root:
set pgp_verify_key_command="/usr/bin/gpg --verbose --batch --fingerprint --check-sigs %r"
+
  
# List my public keyring like so:
+
* Create the directory <tt>lib/python/example</tt>.
set pgp_list_pubring_command="/usr/bin/gpg --no-verbose --batch --with-colons --list-keys %r"
+
* Create the file <tt>lib/python/example/__init__.py</tt> by typing <tt>touch lib/python/example/__init__.py</tt>.
 +
* Create these files:
  
# List my private keyring like so:
+
=== <tt>etc/package-includes/example-configure.zcml</tt> ===
set pgp_list_secring_command="/usr/bin/gpg --no-verbose --batch --with-colons --list-secret-keys %r"
+
  
# Automatically sign outgoing messages
+
This file registers the ''<tt>example</tt>'' directory you created in ''<tt>lib/python</tt>'' as a ''package'', so that it is seen by Zope:
set pgp_autosign=yes
+
  
# Timeout (in seconds) for cached passphrases:
+
<console>
set pgp_timeout=1800
+
<include package="example" />
 +
</console>
  
# Text to show before a good signature:
+
=== <tt>lib/python/example/interfaces.py</tt> ===
set pgp_good_sign="^gpg: Good signature from"
+
</pre>
+
  
=== ~/.mutt/lists ===
+
The following file defines the ''<tt>ITODO</tt>'' interface, and also uses some Zope Schema functions to define what kind of data we expect to store in objects that implement ''<tt>ITODO</tt>'':
<pre>
+
#-------------------------------------------------------------------------     
+
# Mailinglist Subscriptions
+
#-------------------------------------------------------------------------
+
# Syntax:
+
# subscribe mailinglist@domain.com
+
</pre>
+
  
=== ~/.mutt/macros ===
+
<console>
<pre>
+
from zope.interface import Interface
# Macros to toggle the sidebar visibility                                     
+
from zope.schema import List, Text, TextLine, Int
macro index b '<enter-command>toggle sidebar_visible<enter><refresh>'
+
macro pager b '<enter-command>toggle sidebar_visible<enter><redraw-screen>'
+
  
# abook query
+
class ITODO(Interface):
macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
+
    name = TextLine(title=u'Name', required=True)
macro generic,index,pager \Cb "abook" "launch abook"
+
    todo = List(title=u"TODO Items", required=True, value_type=TextLine(title=u'TODO'))
</pre>
+
    daysleft = Int(title=u'Days left to complete', required=True)
 +
    description = Text(title=u'Description', required=True)
 +
</console>
  
=== ~/.mutt/alias ===
+
=== <tt>lib/python/example/TODO.py</tt> ===
multiple lines like
+
<pre>
+
alias nick Realname <email@host.tld>
+
</pre>
+
  
=== ~/.mutt/muttrc ===
+
Now, we define ''<tt>TODO</tt>'' to be a ''persistent'' object, meaning it can be stored in the ZODB. We specify that it implements our previously-defined ''<tt>ITODO</tt>'' interface, and provide reasonable defaults for all values when we create a new TODO object:
<pre>
+
<console>
# Some minimal Mutt settings, Gentoo-style.  These reflect the Gentoo
+
from persistent import Persistent
# predilection for maildir folders.
+
from zope.interface import implements
#
+
from example.interfaces import ITODO
# Please don't add settings to this file to change other user
+
# preferences (such as colors), since those can be hard for a user to
+
# undo if their preference doesn't match yours!  For example, it is
+
# *impossible* currently in mutt to remove color settings from objects
+
# other than the index.
+
  
#-------------------------------------------------------------------------
+
class TODO(Persistent):
# Process the password file first
+
    implements(ITODO)
#-------------------------------------------------------------------------
+
    name = u''
set my_tmp=`gpg -o ~/.secret/.tmp -d ~/.secret/.passwd.gpg`                   
+
    todo = []
set my_pass1=`awk '/user:/ {print $2}' ~/.secret/.tmp`
+
    daysleft = 0
set my_del=`rm -f ~/.secret/.tmp`
+
    description = u''
+
</console>
#-------------------------------------------------------------------------
+
# Further customisations
+
#-------------------------------------------------------------------------
+
set smart_wrap = yes
+
set sort = 'threads'
+
set sort_aux = 'last-date-received'
+
set imap_check_subscribed
+
  
ignore "Authentication-Results:"
+
=== <tt>lib/python/example/configure.zcml</tt> ===
ignore "DoaminKey-Signature:"
+
ignore "DKIM-Signature:"
+
hdr_order Date From To Cc
+
  
#-------------------------------------------------------------------------
+
Create an empty ''<tt>configure.zcml</tt>'' configuration file:
# Configuration variables
+
<console>
#-------------------------------------------------------------------------
+
<configure xmlns="http://namespaces.zope.org/zope"
set abort_nosubject=yes
+
    xmlns:five="http://namespaces.zope.org/five"
set abort_unmodified=yes
+
    xmlns:browser="http://namespaces.zope.org/browser">
set query_command="abook --mutt-query '%s'"
+
</configure>
set alias_file="~/.mutt/mutt-alias"
+
</console>
set alias_format="%4n %t %a %r"
+
source $alias_file
+
set assumed_charset="utf-8"
+
set attach_charset="utf-8"
+
set charset="utf-8"
+
set date_format=""
+
set edit_headers=yes
+
set editor='vim + -c "set textwidth=72" -c "set wrap" -c "set nocp" -c "?^$"        '
+
set folder="~/.offlineimap"
+
set forward_quote=yes
+
set header_cache=~/.mutt/cache/headers
+
set message_cachedir=~/.mutt/cache/bodies
+
set certificate_file=~/.mutt/certificates
+
set help=yes
+
set imap_idle=yes
+
set imap_peek=yes
+
set imap_servernoise=no
+
set include=yes
+
set mail_check=60
+
set mbox_type=Maildir
+
set menu_move_off=no
+
set menu_scroll=no
+
set mime_forward=ask-no
+
set pager_context=2
+
set pager_stop=yes
+
set postponed="~/.mutt/mail/postponed"
+
set realname="Martin 'golodhrim' Scholz"
+
set record="~/.mutt/mail/sent"
+
set reply_regexp="^(re([\[0-9\]+])*|betr):[ \t]*"
+
#set reply_to=yes
+
set tilde=yes
+
 
+
#--------------------------------------------------------------------------
+
# muttprint for printing
+
#--------------------------------------------------------------------------
+
set print_command="muttprint"
+
 
+
#--------------------------------------------------------------------------
+
# Automatically process html mails
+
#--------------------------------------------------------------------------
+
auto_view text/html
+
 
+
#--------------------------------------------------------------------------
+
# Other configuration files
+
#--------------------------------------------------------------------------
+
source ~/.mutt/account_hooks
+
source ~/.mutt/folder_hooks
+
source ~/.mutt/colors
+
source ~/.mutt/sidebar
+
source ~/.mutt/gpg
+
source ~/.mutt/macros
+
source ~/.mutt/lists
+
</pre>
+
  
=== ~/.mutt/sidebar ===
+
== Debug Mode ==
<pre>
+
#--------------------------------------------------------------------------   
+
# Sidebar configuration
+
#--------------------------------------------------------------------------
+
set sidebar_width=30
+
set sidebar_visible=yes
+
set sidebar_delim='|'
+
color sidebar_new yellow default
+
  
#--------------------------------------------------------------------------
+
We can test our first project by entering debug mode:
# Sidebar keys
+
#--------------------------------------------------------------------------
+
bind index \CP sidebar-prev
+
bind index \CN sidebar-next
+
bind index \CO sidebar-open
+
bind pager \CP sidebar-prev
+
bind pager \CN sidebar-next
+
bind pager \CO sidebar-open
+
</pre>
+
 
+
=== ~/.secret/.passwd.gpg ===
+
For this file follow the next steps:
+
* Step 1:
+
Create a folder <tt>~/.secret</tt> and inside a file <tt>.passwd</tt> and enter the following into it:
+
<pre>
+
user1:    passwd1
+
user2:    passwd2
+
</pre>
+
where user1 and user2 are your identifiers for the accounts you added in account_hooks and folder_hooks and at the start of muttrc.
+
* Step 2:
+
Now encrypt the file with your gpg-key, if you don't have one execute <tt>gpg --gen-key</tt> and create one first. After that don't forget to delete your unencrypted passwordstorage.
+
<pre>
+
$ gpg -r 0x<Your-ID-fingerprint> -o .passwd.gpg --encrypt .passwd
+
$ rm -f .passwd
+
</pre>
+
=== Mutt postfix setup ===
+
Postfix is another popular and powerful mail transfer agent which somehow easier to configure than sendmail. Let's start a quick postfix mail transfer setup that will work with mutt. Set <tt>sasl,berkdb</tt> USE flags to <tt>mail-mta/potsfix</tt> and <tt>mail-client/mutt</tt>
+
 
<console>
 
<console>
# ##i##echo "mail-mta/postfix berkdb sasl" >> /etc/portage/package.use/mail
+
$##bl## bin/zopectl debug
# ##i##echo "mail-client/mutt berkdb sasl" >> /etc/portage/package.use/mail
+
Starting debugger (the name "app" is bound to the top-level Zope object)
# ##i##emerge -uN1 mutt postfix
+
 
</console>
 
</console>
Edit <tt>/etc/postfix/main.cf</tt> and add the following lines:
+
 
<pre>
+
Now, let's try creating a new TODO object and writing it out to a ZODB database:
relayhost = smtp.gmail.com:587
+
smtp_use_tls = yes
+
smtp_sasl_auth_enable = yes
+
smtp_sasl_password_maps = hash:/etc/postfix/gmail_passwd
+
smtp_sasl_security_options = noanonymous
+
</pre>
+
Create and edit above mentioned authorization file <tt>gmail_passwd</tt>
+
<console>
+
# ##i##touch /etc/postfix/gmail_passwd
+
# ##i##echo "smtp.gmail.com:587 my.name@gmail.com:password" >> /etc/postfix/gmail_passwd
+
</console>
+
Where <my.name> is gmail account and passwd is account password.
+
Convert <tt>gmail_passwd</tt> into Berkeley DB format, secure the file and finaly restart the postfix daemon
+
 
<console>
 
<console>
# ##i##postmap /etc/postfix/gmail_passwd
+
>>> from ZODB import FileStorage, DB
# ##i##chown root:postfix /etc/postfix/gmail_passwd*
+
>>> storage = FileStorage.FileStorage('mydatabase.fs')
# ##i##chmod 0640 /etc/postfix/gmail_passwd*
+
>>> db = DB(storage)
# ##i##/etc/init.d/postfix restart
+
>>> connection = db.open()
 +
>>> import transaction
 +
>>> root = connection.root()
 +
>>> from example.TODO import TODO
 +
>>> a = TODO
 +
>>> a.name = u'My TODOs'
 +
>>> a.TODOS = [ u'Do Laundry', u'Wash Dishes' ]
 +
>>> a.daysleft = 1
 +
>>> a.description = u'Things I need to do today.'
 +
>>> root[u'today'] = a
 +
>>> transaction.commit()
 
</console>
 
</console>
  
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
 
[[Category:Featured]]
 
[[Category:Featured]]

Revision as of 14:20, January 13, 2014

This page documents how to use Zope with Funtoo Experimental, which currently has good Zope support thanks to Progress Overlay Python integration.

About Zope

Zope is an Open Source application server framework written in Python. It has an interesting history which you should familiarize yourself with before starting Zope development, as it contains several interesting twists and turns.

Zope History

There are two versions of Zope, Zope 2 and Zope 3. One might assume that Zope 3 is the version that people should use for new software development projects by default, but this is not the case. Most Zope-based projects continue to use Zope 2. Zope 3 was an attempt to redesign Zope 2 from scratch, and is completely different from Zope 2, but it was not adopted by the community.

There is also something called Five (named because it is "2 + 3") that backports many of the new features of Zope 3 into the Zope 2 framework. Several projects will use Zope 2 plus Five in order to use some of the newer features in Zope. Five was merged into mainline Zope 2 in early 2010, and first appeared in Zope 2.8.

You can learn more about the history of Zope 2, 3 and Five in the Five README.

To make things even more interesting, work on Zope 4 is underway, and it will be based on 2.13 rather than 3.x. It includes a number of incompatible changes with prior versions.

Note

{{{1}}}

This HOWTO targets Zope 2.13, which includes Five. It is typically the version you should be using for new Zope projects.

Zope Resources

Now that you understand what version of Zope you should be targeting (2.13), we can point you towards the correct documentation :)

The Zope 2 Book
This book provides a general introduction to Zope concepts and ZMI. It is a good place to start, but doesn't provide a direct introduction to Zope development. It's recommended that you skim through this book to familiarize yourself with Zope. It generally does not assume much prior knowledge about Web development or Python.
Zope Developer's Guide
This guide will give you a better introduction to Zope development. It assumes you already know Python. Skip chapters 1 and 2 and start in chapter 3, which covers components and interfaces. Chapter 5 covers the creation of your first product.
Five
We're not done yet. There is a bunch of stuff in Zope 2.13 that is not in the official documentation. Namely, the stuff in Five. Check out The Five Manual.
ZTK
ZTK Documentation
ZCA
A Comprehensive Guide to Zope Component Architecture offers a good introduction to the programming concepts of ZCA. We also have a new page on Zope Component Architecture which will help you to understand the big picture of ZCA and why it is useful. ZCML ("Z-camel") is a part of ZCA and was introduced in Zope 3, so typically you will find ZCML documented within Zope 3 documentation and book.
Content Components
Views and Viewlets: This tutorial on viewlets also contains some viewlet-related ZCML examples near the end. The "Content Component way" of developing in Zope seems to be a Zope 3 thing and tied to ZCML. Chapter 13+ of Stephan Richter's Zope 3 Developer's Handbook (book) seems to cover this quite well. You will probably also want to check out Philipp Weitershausen's Web Component Development with Zope 3 (book).
Zope 2 Wiki
Main wiki page for all things related to Zope 2.
docs.zope.org
This is the main site for Zope documentation.

First Steps

First, you will need to emerge net-zope/zope (package not on wiki - please add):

#  emerge -av zope

Zope is now installed.

Project Skeleton

Note

{{{1}}}

Zope should be run by a regular user account, not as the root user.

The first step in using Zope is to ensure that you are using a regular user account. Create a new directory called zope_test:

$ cd
$ mkdir zope_test

Now, enter the directory, and create an "instance", which is a set of files and directories that are used to contain a Zope project:

$ cd zope_test
$ /usr/lib/zope-2.13/bin/mkzopeinstance

You will see the following output, and will be prompted to answer a few questions:

Please choose a directory in which you'd like to install
Zope "instance home" files such as database files, configuration
files, etc.

Directory: instance
Please choose a username and password for the initial user.
These will be the credentials you use to initially manage
your new Zope instance.

Username: admin
Password: ****
Verify password: **** 

Now, we will start our Zope instance:

$ cd instance
$ bin/runzope

Now that Zope is running, you can visit localhost:8080 in your Web browser. You will see a nice introductory page to Zope.

If you now go to the localhost:8080/manage URL, you will be prompted to log in. Enter the username and password you specified. You are now logged in to the ZMI (Zope Management Interface.)

You can stop your application by pressing Control-C. In the future, you can start and stop your Zope instance using the following commands:

$ zopectl start
$ zopectl stop

Note

{{{1}}}

zopectl start will cause your instance to run in the background rather than consuming a shell console.

First Project

We will create a single very primitive Zope package, consisting of an Interface for a TODO class, and a TODO class.

Create the following files and directories relative to your project root:

  • Create the directory lib/python/example.
  • Create the file lib/python/example/__init__.py by typing touch lib/python/example/__init__.py.
  • Create these files:

etc/package-includes/example-configure.zcml

This file registers the example directory you created in lib/python as a package, so that it is seen by Zope:

<include package="example" />

lib/python/example/interfaces.py

The following file defines the ITODO interface, and also uses some Zope Schema functions to define what kind of data we expect to store in objects that implement ITODO:

from zope.interface import Interface
from zope.schema import List, Text, TextLine, Int

class ITODO(Interface):
    name = TextLine(title=u'Name', required=True)
    todo = List(title=u"TODO Items", required=True, value_type=TextLine(title=u'TODO'))
    daysleft = Int(title=u'Days left to complete', required=True)
    description = Text(title=u'Description', required=True)

lib/python/example/TODO.py

Now, we define TODO to be a persistent object, meaning it can be stored in the ZODB. We specify that it implements our previously-defined ITODO interface, and provide reasonable defaults for all values when we create a new TODO object:

from persistent import Persistent
from zope.interface import implements
from example.interfaces import ITODO

class TODO(Persistent):
    implements(ITODO)
    name = u''
    todo = []
    daysleft = 0
    description = u''

lib/python/example/configure.zcml

Create an empty configure.zcml configuration file:

<configure xmlns="http://namespaces.zope.org/zope"
     xmlns:five="http://namespaces.zope.org/five"
     xmlns:browser="http://namespaces.zope.org/browser">
</configure>

Debug Mode

We can test our first project by entering debug mode:

$ bin/zopectl debug
Starting debugger (the name "app" is bound to the top-level Zope object)

Now, let's try creating a new TODO object and writing it out to a ZODB database:

>>> from ZODB import FileStorage, DB
>>> storage = FileStorage.FileStorage('mydatabase.fs')
>>> db = DB(storage)
>>> connection = db.open()
>>> import transaction
>>> root = connection.root()
>>> from example.TODO import TODO
>>> a = TODO
>>> a.name = u'My TODOs'
>>> a.TODOS = [ u'Do Laundry', u'Wash Dishes' ]
>>> a.daysleft = 1
>>> a.description = u'Things I need to do today.'
>>> root[u'today'] = a
>>> transaction.commit()