Difference between pages "Welcome" and "Zope HOWTO"

(Difference between pages)
 
m (Updated some of the syntax on the page.)
 
Line 1: Line 1:
<div class="container"><div class="row"><div class="col-xs-12 col-md-8 col-lg-8">
+
This page documents how to use Zope with Funtoo Experimental, which currently has good Zope support thanks to [[Progress Overlay Python]] integration.
{{Slideshow}}
+
Want to submit a screenshot? [http://forums.funtoo.org/index.php?/topic/180-screenshots/ See here.]
+
</div><div class="col-xs-12 col-md-4 col-lg-4">
+
'''Funtoo Linux''' is a Linux-based operating system that is a variant of [http://www.gentoo.org Gentoo Linux]. Funtoo Linux is:
+
* ...'''fun!''' Our priority is to create a ''great, supportive and responsive'' user community.
+
* ...'''user-centric and collaborative'''. Everyone is considered a '''user''' of Funtoo, first and foremost. You don't need any special privileges to collaborate with us.
+
* ...'''production-oriented''': Our goal is to have Funtoo be useful for ''real-world tasks''. We use Funtoo to do stuff, like host our infrastructure. It needs to work.__NOTOC__
+
* ...'''creative''': We seek creative, elegant and maintainable solutions to problems of all kinds.
+
  
'''View the [[Funtoo Linux FAQ]] for answers to common questions.'''
+
== About Zope ==
  
{{#ask: [[Category:People]] [[Gravatar MD5::+]]
+
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.
| limit=22
+
 
| order=random
+
=== Zope History ===
| format=template
+
 
| template=GravatarDisplay
+
{{Note|This HOWTO targets Zope 2.13, which includes Five. It is typically the version you should be using for new Zope projects.}}
| link=none
+
 
| searchlabel=
+
* 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 [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.
 +
 
 +
* 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].
 +
 
 +
* 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.
 +
=== Zope Resources ===
 +
 
 +
Now that you understand what version of Zope you should be targeting (2.13), we can point you towards the correct documentation :)
 +
 
 +
; '''[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.
 +
; '''[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.
 +
; '''[http://codespeak.net/z3/five/manual.html The Five Manual]'''
 +
: 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.
 +
; '''[http://docs.zope.org/ztkpackages.html ZTK Documentation]'''
 +
: ZTK 
 +
; '''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.
 +
 
 +
== First Steps ==
 +
 
 +
First, you will need to emerge {{Package|net-zope/zope}}:
 +
{{console|body=
 +
###i## emerge zope
 
}}
 
}}
 +
Zope is now installed.
  
Join us - {{CreateAccount}}, and then add yourself to our [[Usermap]]!
+
== Project Skeleton ==
</div>
+
</div><div class="row">
+
<div class="col-xs-12 col-md-4 col-lg-4">
+
== Resources ==
+
  
{{fancyimportant|1=
+
{{Note|Zope should be run by a regular user account, not as the root user.}}
[[Support Funtoo]] to help our project grow! '''Donate $15 per month and get a free [[Funtoo Hosting|Funtoo Virtual Container]].'''}}
+
  
'''Our resources:''' -- also see the <code>Go</code> menu:
+
The first step in using Zope is to ensure that you are using a regular user account. As a regular user, create a new directory called {{c|zope_test}}:
* '''{{CreateAccount}}''' ([[Funtoo Authentication FAQ|Auth FAQ]])
+
{{console|body=
* '''[http://forums.funtoo.org forums.funtoo.org]''' - our new forums!
+
$##bl## cd
* '''[http://bugs.funtoo.org bugs.funtoo.org]''', our bug tracker ([[Reporting Bugs|Instructions]]).
+
$##bl## mkdir zope_test
* [http://larrythecow.org larrythecow.org], Gentoo blog service.
+
}}
* [http://kernel-seeds.org kernel-seeds.org], kernel build help.
+
Now, enter the directory, and create an "instance", which is a set of files and directories that are used to contain a Zope project:
* [http://git.funtoo.org git.funtoo.org], our cgit repository browser.
+
{{console|body=
* '''[[Support Funtoo]]''' to help our project grow.
+
$##bl## cd zope_test
* '''[[Funtoo Hosting|Get a Funtoo Virtual Container]]'''.
+
$##bl## /usr/lib/zope-2.13/bin/mkzopeinstance
</div><div class="col-sm-12 col-xs-12 col-md-4 col-lg-4">
+
}}
== Getting Started ==
+
You will see the following output and will be prompted to answer a few questions:
 +
{{console|body=
 +
Please choose a directory in which you'd like to install
 +
Zope "instance home" files such as database files, configuration
 +
files, etc.
  
We encourage you to '''[[Funtoo Linux Installation|install Funtoo Linux]]''', and get involved in our user community. Get to know fellow Funtoo Linux users on our '''[http://forums.funtoo.org forums]'''. If you have any improvements or find any bugs in Funtoo Linux, you are strongly encouraged to report them on our '''[http://bugs.funtoo.org bug tracker]'''. We take all bugs seriously, and all work performed on Funtoo Linux is tracked on our bug tracker, for purposes of transparency.
+
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.
  
Funtoo Linux has a very active [http://en.wikipedia.org/wiki/IRC IRC] community on Freenode, in the <code>#funtoo</code> channel, and you are encouraged to hang out online with us.
+
Username: admin
 +
Password: ****
 +
Verify password: ****
 +
}}
 +
Now, we will start our Zope instance:
 +
{{console|body=
 +
$##bl## cd instance
 +
$##bl## bin/runzope
 +
}}
 +
Now that Zope is functional, you can go to the {{c|localhost:8080/manage}} URL in your web browser: 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.)
  
== Expand the wiki! ==
+
You can stop your application by pressing Control-C. In the future, you can start and stop your Zope instance using the following commands:
 +
{{console|body=
 +
$##bl## zopectl start
 +
$##bl## zopectl stop
 +
}}
 +
{{Note|{{c|zopectl start}} will cause your instance to run in the background rather than consuming a shell console.}}
  
The [[:Help:Funtoo_Editing_Guidelines | How to 'wiki']] will help get you started on wiki editing. Have a look at [[Requested-Documents]] and [[:Category:Needs_Updates | pages that need to be updated.]]
+
== First Project ==
  
See [[:Category:Ebuilds|Ebuilds]] for a list of all ebuild pages, and [[Adding an Ebuild to the Wiki]] for information on how to add one.
+
We will create a single, very primitive Zope package, consisting of an Interface for a TODO class, and a TODO class.
  
'''Ebuild pages recently updated:''' {{#ask: [[Category:Ebuilds]]
+
Create the following files and directories relative to your project root:
| order=descending
+
 
| sort=Modification date
+
* Create the directory {{c|lib/python/example}}.
| format=list
+
* Create the file {{c|lib/python/example/__init__.py}} by typing {{c|touch lib/python/example/__init__.py}}.
| limit=10
+
* Create these files:
| searchlabel=more...
+
 
 +
=== {{c|example-configure.zcml}} ===
 +
 
 +
This file registers the {{c|example}} directory you created in {{c|lib/python}} as a ''package'', so that it is seen by Zope. Edit {{c|/etc/package-includes/example-configure.zcml}}:
 +
{{file|name=/etc/package-includes/example-configure.zcml|body=
 +
<include package="example" />
 
}}
 
}}
</div><div class="col-sm-12 col-xs-12 col-md-4 col-lg-4">
 
== Distinctives ==
 
  
Funtoo Linux packages are installed from source code, automatically, thanks to the [http://en.wikipedia.org/wiki/Portage_(software) Portage ports system], inspired by the FreeBSD ports system, but written in Python and with full advanced package management functionality. Funtoo Linux is a meta-distribution, which means it is built (fully automatically) with the functionality and optimizations that ''you'' want, not what some distro maintainer thought was best for you.
+
=== {{c|interfaces.py}} ===
  
We use [http://en.wikipedia.org/wiki/Git_(software) Git] for all our development, and we also use Git to deliver our ports tree to you.
+
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>. Edit <code>/lib/python/example/interfaces.py</code> with your favorite text editor:
  
In contrast to Gentoo Linux, we offer a number of innovations, including our extensive use of git, [[Funtoo 1.0 Profile|our profile system]], [[Package:Boot-Update|boot-update]] boot management tool, our incredibly flexible [[Funtoo Linux Networking|template-based networking scripts]], [[Metro Quick Start Tutorial|Metro]] distribution build system, support of Debian, RHEL and other kernels, [[Creating_Python-related_Ebuilds|enhanced Python support]], Portage mini-manifests, user-centric distribution model, and a large number of community infrastructure improvements.
+
<syntaxhighlight lang="python">
 +
from zope.interface import Interface
 +
from zope.schema import List, Text, TextLine, Int
  
== Project Structure ==
+
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)
 +
</syntaxhighlight>
  
Funtoo Linux is led by [http://en.wikipedia.org/wiki/Daniel_Robbins_(computer_programmer) Daniel Robbins], the creator and former Chief Architect of [http://en.wikipedia.org/wiki/Gentoo_Linux Gentoo Linux], who serves as benevolent dictator for life (BDFL) of the project.  
+
=== {{c|TODO.py}} ===
  
'''Learn more about Funtoo Linux's [[staff]] and [[Funtoo Linux Vision|development vision]].'''
+
Now, we define {{c|TODO}} to be a ''persistent'' object, meaning it can be stored in the ZODB. We specify that it implements our previously-defined {{c|ITODO}} interface, and provide reasonable defaults for all values when we create a new TODO object. Edit {{c|/lib/python/example/TODO.py}} using your favorite text editor:
</div></div></div>
+
{{file|name=/lib/python/example/TODO.py|lang=python|body=
 +
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''
 +
}}
  
__NOTITLE__
+
=== {{c|configure.zcml}} ===
__NOEDITSECTION__
+
{{#subobject:|slideIndex=0|slideCaption=
+
== [[User:Drobbins|drobbins]] ==
+
  
[[GNOME First Steps|GNOME 3.12]]
+
Create the <tt>/lib/python/example/configure.zcml</tt> configuration file:
([[Funtoo_Linux_FAQ#Do_you_support_systemd.3F|without systemd]], because that's how we roll.)
+
<syntaxhighlight lang="xml">
 +
<configure xmlns="http://namespaces.zope.org/zope"
 +
    xmlns:five="http://namespaces.zope.org/five"
 +
    xmlns:browser="http://namespaces.zope.org/browser">
 +
</configure>
 +
</syntaxhighlight>
  
Note: Badgers optional.
+
== Debug Mode ==
|slideImage=File:gnome3122.jpg|slideLink=GNOME First Steps}}
+
{{#subobject:|slideIndex=1|slideCaption=
+
== [[User:Anak1n|anak1n]] ==
+
  
flux box
+
We can test our first project by entering debug mode:
|slideImage=File:fluxbox-09.02.14.jpg}}
+
<console>
{{#subobject:|slideIndex=2|slideCaption=
+
$##i## bin/zopectl debug
== spectromas ==
+
Starting debugger (the name "app" is bound to the top-level Zope object)
 +
</console>
  
[[Package:Awesome_(Window_Manager)|Awesome WM]]
+
Now, let's try creating a new TODO object and writing it out to a ZODB database:
|slideImage=File:awesome.jpg|slideLink=Package:Awesome (Window Manager)}}
+
<console>
{{#subobject:|slideIndex=3|slideCaption=
+
>>> from ZODB import FileStorage, DB
== [[User:Anak1n|anak1n]] ==
+
>>> 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()
 +
</console>
  
KDE
+
[[Category:HOWTO]]
|slideImage=File:anak1n-kde.jpg}}
+

Latest revision as of 17:32, June 25, 2015

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

Note

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

  • 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.

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.
The Five Manual
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.
ZTK Documentation
ZTK
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 zope

Zope is now installed.

Project Skeleton

Note

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. As a regular user, 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 functional, you can go to the localhost:8080/manage URL in your web browser: 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

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:

example-configure.zcml

This file registers the example directory you created in lib/python as a package, so that it is seen by Zope. Edit /etc/package-includes/example-configure.zcml:

/etc/package-includes/example-configure.zcml
<include package="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. Edit /lib/python/example/interfaces.py with your favorite text editor:

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)

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. Edit /lib/python/example/TODO.py using your favorite text editor:

/lib/python/example/TODO.py (python source code)
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''

configure.zcml

Create the /lib/python/example/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()