Difference between pages "Creating System Rescue CD ZFS Modules" and "Zope HOWTO"

From Funtoo
(Difference between pages)
Jump to: navigation, search
 
m
 
Line 1: Line 1:
This HOWTO will show you how to create your own zfs srm or download the prebuilt zfs srm module from my website.
+
This page documents how to use Zope with Funtoo Experimental, which currently has good Zope support thanks to [[Progress Overlay Python]] integration.
  
== Compiling a compatible kernel ==
+
== About Zope ==
  
The first thing you need to do is decide for which version of System Rescue CD you will be building for. Each System Rescue CD version has a different set of kernels. Specifically each version has a Stable kernel and an Alternate Kernel. The stable kernels get minor version increments every release (Sometimes major ones but usually doesn't happen too quickly), the Alternate kernels tend to move up much faster. For example System Rescue CD had the following stable/alternate kernels:
+
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.
  
{| class="wikitable"
+
=== Zope History ===
|-
+
! Version !! Stable !! Alternate
+
|-
+
| 3.7.0 || 3.4.47 || 3.9.4
+
|-
+
| 3.5.0 || 3.4.37 || 3.8.4
+
|}
+
  
===Download kernel and patches===
+
{{Note}} This HOWTO targets Zope 2.13, which includes Five. It is typically the version you should be using for new Zope projects.
Once you decide which version you want to use, you can go to http://kernel.sysresccd.org/ and pick the version you want. After you do this, download all the stuff in that directory and put them in their own folder (a work directory). The files that are named std-sources are the patches for the regular stable kernel, the patches named alt-sources are the patches for the alternate kernel. Once you have the patches, go to kernel.org and also download the initial release of the kernel sources you want. For example, if you want to build an srm for 3.4.2 which uses the 3.4.35 kernel, just download the 3.4 (3.4.0) kernel. You just need to download the initial release because one of the patches you downloaded earlier is the patch to update the 3.4.0 to 3.4.35.
+
  
Once you download the kernel you want, let's extract and patch it.
+
* 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.
  
<console>
+
* 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.
# ##i##tar xf linux-3.4.tar.bz2
+
# ##i##mv linux-3.4 linux-3.4.35-std342-amd64
+
# ##i##bzcat std-sources-3.4-01-stable-3.4.35.patch.bz2 | patch -p1 -d linux-3.4.35-std342-amd64
+
# ##i##bzcat std-sources-3.4-02-fc16.patch.bz2 | patch -p1 -d linux-3.4.35-std342-amd64
+
# ##i##bzcat std-sources-3.4-03-aufs.patch.bz2 | patch -p1 -d linux-3.4.35-std342-amd64
+
</console>
+
 
+
===Retrieve kernel configuration===
+
Once that is complete, you will need to get the kernel config specifically for the kernel and architecture you want. The easiest way I found to do this was to download the System Rescue CD you want, and then boot it inside a VM. Once you are inside the VM, go to the /root directory, and it will be a file named kernel-<version>.conf. Copy this file over SSH and put it in a safe location. Also copy it over into the linux kernel directory and rename it to .config.
+
 
+
===Build the kernel===
+
Once you copy the kernel config over, do a make menuconfig to begin. You will only need to change two settings inside the config, add the proper kernel name, and remove the old initramfs source files directory. This directory doesn't exist locally. This is a remnant of upstream's build process.
+
  
Follow the below tree structure, and make it equal to what is below:
+
* 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].
  
{{kernelop
+
* 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.
|General Setup ->|<pre>
+
=== Zope Resources ===
(-std342-amd64) Local version - append to kernel release
+
      [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
+
      ( ) Initramfs source file(s)
+
</pre>}}
+
  
The Local version above will end up making the kernel modules directory be 3.4.35-std342-amd64. The reason the kernel modules directory has to be equal to this is because our directory will be merged into the System Rescue CD later on, so the names need to be exactly the same so that the System Rescue CD system can find our kernel modules.
+
Now that you understand what version of Zope you should be targeting (2.13), we can point you towards the correct documentation :)
  
If you want to build an srm (which you do), you also need to change the following inside the kernel config so that squashfs-tools can work later on:
+
; [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.
 +
; 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.
  
{{kernelop
+
== First Steps ==
|File Systems ->|<pre>
+
Miscellaneous Filesystems ->
+
      <*>  SquashFS 4.0 - Squashed file system support
+
      [*]    Squashfs XATTR support
+
      [*]    Include support for ZLIB compressed file systems
+
      [*]    Include support for LZO compressed file systems
+
      [*]    Include support for XZ compressed file systems
+
      [ ]    Use 4K device block size?
+
      [ ]    Additional option for memory-constrained systems
+
</pre>}}
+
  
Now save and exit, and continue to build your kernel.
+
First, you will need to emerge {{Package|net-zope/zope}}:
  
 
<console>
 
<console>
# ##i##make bzImage modules
+
# ##i## emerge -av zope
# ##i##make modules_install
+
 
</console>
 
</console>
  
{{fancynote|If you have multiple cores, do a make -j<# of processors+1> to build faster. Example: '''make -j9''' for an 8 core machine.}}
+
Zope is now installed.
  
=== Using the portage tree ===
+
== Project Skeleton ==
Inside the portage tree, there are ebuilds already prepared that will download the kernel, patch it, and perform any required substitutions. Afterwards you literally just go into your /usr/src/<kernel> directory, and run make. To see the available versions, run the following:
+
  
<console>
+
{{Note}} Zope should be run by a regular user account, not as the root user.
Versions available for standard kernel
+
# ##i##equery y std-sources
+
 
+
[I]3.4.37-r1 | o ~ o o o o o o o o o o o | o 3.4.37 | gentoo
+
 
+
Versions available for alternate kernel
+
# ##i##equery y alt-sources
+
 
+
[I]3.8.4 | o ~ o o o o o o o o o o o | o 3.8.4 | gentoo
+
</console>
+
 
+
I haven't written the ebuilds in a way where it's easy to tell (at first glance) what System Rescue CD version you need. However, you can check the ebuild and you will see the version of the CD inside there. You can also check the chart above.
+
 
+
If you wanted to install the standard kernel sources, you just emerge it like any other application:
+
  
 +
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>'':
 
<console>
 
<console>
# ##i##emerge std-sources
+
$##bl## cd
 +
$##bl## mkdir zope_test
 
</console>
 
</console>
  
Once the kernel and the kernel module are installed, you need to make the SRM.
+
Now, enter the directory, and create an "instance", which is a set of files and directories that are used to contain a Zope project:
 
+
== Creating the SRM ==
+
It's time to gather the required files and pack them together in order for it to become an SRM. An SRM is nothing more than a directory that has been compressed with squashfs. You can emerge the "Bliss Initramfs Creator" which has a feature that will automagically build the srm for you.
+
 
+
 
+
You also need to have spl, zfs, and zfs-kmod installed on your system before you try to make the srm. Emerging '''"bliss-initramfs"''' should automatically pull those packages. If it doesn't, make sure you install them.
+
 
+
 
<console>
 
<console>
# ##i##echo "sys-kernel/bliss-initramfs srm" >> /etc/portage/package.use
+
$##bl## cd zope_test
# ##i##emerge bliss-initramfs
+
$##bl## /usr/lib/zope-2.13/bin/mkzopeinstance
 
</console>
 
</console>
  
 
+
You will see the following output, and will be prompted to answer a few questions:
You should now have the following directory layout inside the '''/opt/bliss-initramfs''' folder:
+
 
+
 
<console>
 
<console>
octopus bliss-initramfs # ls -l
+
Please choose a directory in which you'd like to install
total 117
+
Zope "instance home" files such as database files, configuration
-rw-r--r-- 1 root root 6718 May 23 18:05 CHANGES
+
files, etc.
-rw-r--r-- 1 root root  176 May 23 18:05 CREDITS
+
-rw-r--r-- 1 root root  431 May 23 18:05 HELP
+
-rw-r--r-- 1 root root 1397 May 23 18:05 LICENSE
+
-rw-r--r-- 1 root root 1852 May 23 18:05 README
+
-rw-r--r-- 1 root root 3194 May 23 18:05 USAGE
+
-rwxr-xr-x 1 root root 2891 May 23 18:05 createInit
+
drwxr-xr-x 3 root root    4 May 23 18:11 files
+
drwxr-xr-x 3 root root    6 May 23 18:11 hooks
+
drwxr-xr-x 2 root root    5 May 23 22:01 resources
+
</console>
+
 
+
 
+
Then run the '''createInit''' script and follow the instructions for the kernel you want to make the srm for (In this case it's '''3.4.37-std350-amd64'''):
+
 
+
<console>
+
-----------------------------------
+
| Bliss Initramfs Creator - v1.8.1
+
| Author: Jonathan Vasquez <jvasquez1011@gmail.com>
+
| Distributed under the Simplified BSD License
+
-----------------------------------
+
 
+
>>> Which initramfs would you like to generate:
+
>> 1. ZFS
+
>> 2. Encrypted ZFS (LUKS + ZFS)
+
>> 3. More Options
+
>> 4. Exit Program
+
 
+
>>> Current choice [1]: ##i##3 ↵
+
 
+
>>> More Options:
+
 
+
>> 1. ZFS - System Rescue Module
+
>> 2. Back
+
>> 3. Exit Program
+
 
+
>>> Current choice [1]: ##i##↵
+
 
+
>>> Creating a ZFS System Rescue Module!
+
 
+
>>> Do you want to use the current kernel: 3.8.13-ALL? [Y/n]: ##i##n ↵
+
  
>>> Please enter the kernel name: ##i##3.4.37-std350-amd64 ↵
+
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.
  
>>> Detected 64 bit platform
+
Username: admin
>>> Checking to see if modules directory exists for 3.4.37-std350-amd64...
+
Password: ****
>>> Creating SRMs for 3.4.37-std350-amd64...
+
Verify password: ****
>>> Creating directory structure for initramfs...
+
>>> Checking preliminary binaries...
+
>>> Checking binaries...
+
>>> Using ZFS
+
>>> Checking modules...
+
>>> Copying binaries...
+
>>> Copying modules...
+
>>> Copying documentation...
+
>>> Copying udev rules...
+
>>> Compressing kernel modules...
+
>>> Getting dependencies...
+
>>> Copying dependencies...
+
>>> Configuring files...
+
>>> Creating and Packing SRMs...
+
>>> Complete :)
+
 
</console>
 
</console>
  
 
+
Now, we will start our Zope instance:
Now you should have two new files:
+
 
+
 
<console>
 
<console>
-rw-r--r-- 1 root root 2068480 May 24 01:05 zfs-core-3.4.37-std350-amd64.srm
+
$##bl## cd instance
-rw-r--r-- 1 root root  483328 May 24 01:05 zfs-kmod-3.4.37-std350-amd64.srm
+
$##bl## bin/runzope
 
</console>
 
</console>
  
 +
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.
  
Now all you need to do is put those two files in the root of your USB directory.
+
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.)
 
+
If you are making srms for both the standard and alternate kernels, you will end up with two zfs-core files and two zfs-kmod files (1 set for each kernel). You don't need to put the zfs-core that it makes for one of the kernels. The zfs-core srm only has zfs program binaries, man pages, udev rules, and a few other things. The zfs-kmod is the srm that has the kernel modules (and only the kernel modules). So you can easily just put two zfs-kmods (one for each kernel version) and just re-use the same zfs-core for both of them.
+
 
+
== Using the prebuilt srm ==
+
  
=== Download the SRM ===
+
You can stop your application by pressing Control-C. In the future, you can start and stop your Zope instance using the following commands:
If you didn't build your own srm and want to use the prebuilt one, just emerge '''"zfs-srm"''' from the tree:
+
  
 
<console>
 
<console>
# ##i##emerge zfs-srm
+
$##bl## zopectl start
 +
$##bl## zopectl stop
 
</console>
 
</console>
  
You can check available versions just as you did above for the kernels:
+
{{Note}} ''<tt>zopectl start</tt>'' will cause your instance to run in the background rather than consuming a shell console.
  
<console>
+
== First Project ==
Available versions of the zfs-srm
+
# ##i##equery y zfs-srm
+
  
[I]3.5.0 | o ~ o o o o o o o o o o o | o 3.5.0 | gentoo
+
We will create a single very primitive Zope package, consisting of an Interface for a TODO class, and a TODO class.
</console>
+
  
(These versions match the version of the System Rescue CD).
+
Create the following files and directories relative to your project root:
  
Installing the zfs-srm will automatically pull the '''"bliss-isomaker"''' package which is just a script that assists you with rebuilding the System Rescue CD ISO so that the ISO includes the ZFS srms. The script lets you make a bootable ISO or a bootable USB.
+
* Create the directory <tt>lib/python/example</tt>.
 +
* Create the file <tt>lib/python/example/__init__.py</tt> by typing <tt>touch lib/python/example/__init__.py</tt>.
 +
* Create these files:
  
Once it's installed, switch to the /opt/bliss-isomaker folder
+
=== <tt>etc/package-includes/example-configure.zcml</tt> ===
  
<console>
+
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:
# ##i##cd /opt/bliss-isomaker
+
</console>
+
 
+
You should now see a directory layout that looks similar to this:
+
  
 
<console>
 
<console>
octopus bliss-isomaker # ls -l
+
<include package="example" />
total 100
+
drwxr-xr-x 2 root root    5 May 24 01:41 3.5.0
+
-rw-r--r-- 1 root root 1397 May 24 01:31 LICENSE
+
-rw-r--r-- 1 root root  312 May 24 01:31 README
+
-rw-r--r-- 1 root root  576 May 24 01:31 USAGE
+
-rwxr-xr-x 1 root root 3228 May 24 01:31 create
+
drwxr-xr-x 2 root root    3 May 24 01:41 iso
+
drwxr-xr-x 2 root root    4 May 24 01:41 resources
+
drwxr-xr-x 2 root root    3 May 24 01:41 srm
+
 
</console>
 
</console>
  
The layout is as follows:
+
=== <tt>lib/python/example/interfaces.py</tt> ===
* 3.5.0 - This folder contains the System Rescue CD 3.5.0 specific srms for both the standard and alternate kernel that were installed by emerge.
+
* create - A script to automatically recreate the system rescue cd iso or usb with the zfs stuff included
+
* iso - directory to place your system rescue cd iso in
+
* srm - directory that has the srms
+
* resources - the files in this folder contain function calls that the 'create' script uses. You don't need to worry about these.
+
  
=== Installing the SRM ===
+
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>'':
There are a few ways to do this, you can either use one of the scripts, or you can do it manually. Before anything, make sure to copy the SRMs from the <Version> folder to the srm folder if you are using a prebuilt one:
+
  
 
<console>
 
<console>
# ##i##cp 3.5.0/* srm
+
from zope.interface import Interface
</console>
+
from zope.schema import List, Text, TextLine, Int
 
+
==== Generating a new iso ====
+
If you just want to remake a new iso so that you can burn onto a cd or use in a virtual machine, just copy your iso over to the iso directory, and run the 'create' script. The new iso will be located in the iso directory as well with a -zfs ending.
+
 
+
<console>
+
Running the script with 1 (or iso) chooses to make an iso. You can also pass the version as well.
+
# ##i##./create 1
+
 
+
or
+
  
# ##i##./create iso 3.5.0
+
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)
 
</console>
 
</console>
  
==== Creating a fresh usb ====
+
=== <tt>lib/python/example/TODO.py</tt> ===
If you want to have zfs on a usb with system rescue cd, put the iso in your iso dir, and then run the usb script. It will ask you what usb you want to format (This will delete everything), and then install system rescue cd onto it. Once that is done it will copy the zfs stuff over.
+
 
+
  
 +
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:
 
<console>
 
<console>
Running the script with 2 (or usb) chooses to make an usb. You can also pass the version as well.
+
from persistent import Persistent
# ##i##./create 2
+
from zope.interface import implements
 +
from example.interfaces import ITODO
  
or
+
class TODO(Persistent):
 
+
    implements(ITODO)
# ##i##./create usb 3.5.0
+
    name = u''
 +
    todo = []
 +
    daysleft = 0
 +
    description = u''
 
</console>
 
</console>
  
==== Manual installation onto a usb ====
+
=== <tt>lib/python/example/configure.zcml</tt> ===
Assuming that your installing to a flash drive and that the flash drive is mounted in /mnt
+
 
+
1. Mount your usb drive
+
  
 +
Create an empty ''<tt>configure.zcml</tt>'' configuration file:
 
<console>
 
<console>
# ##i##mount /dev/sdX# /mnt/usbstick
+
<configure xmlns="http://namespaces.zope.org/zope"
 +
    xmlns:five="http://namespaces.zope.org/five"
 +
    xmlns:browser="http://namespaces.zope.org/browser">
 +
</configure>
 
</console>
 
</console>
  
'''Where X# is the letter and number of your device. Immediately after you plug your usb in, type `dmesg | tail` in the console and you should see it.'''
+
== Debug Mode ==
 
+
 
+
2. Copy the zfs .srms to /mnt/usbstick
+
  
 +
We can test our first project by entering debug mode:
 
<console>
 
<console>
# ##i##cp zfs-core-3.4.37-std350-amd64.srm zfs-kmod-3.4.37-std350-amd64.srm zfs-kmod-3.8.4-alt350-amd64.srm /mnt/usbstick
+
$##bl## bin/zopectl debug
 +
Starting debugger (the name "app" is bound to the top-level Zope object)
 
</console>
 
</console>
  
3. List your /mnt/usbstick directory and you should see something similar to the following in your /mnt/usbstick
+
Now, let's try creating a new TODO object and writing it out to a ZODB database:
 
+
 
<console>
 
<console>
octopus 3.5.0 # ls -l /mnt/usbstick
+
>>> from ZODB import FileStorage, DB
total 305028
+
>>> storage = FileStorage.FileStorage('mydatabase.fs')
drwxr-xr-x 3 root root      4096 May 23 20:51 boot
+
>>> db = DB(storage)
drwxr-xr-x 2 root root      4096 May 23 20:51 bootdisk
+
>>> connection = db.open()
drwxr-xr-x 2 root root     4096 May 23 20:51 bootprog
+
>>> import transaction
drwxr-xr-x 3 root root      4096 May 23 20:51 efi
+
>>> root = connection.root()
drwxr-xr-x 2 root root      4096 May 23 20:51 ntpasswd
+
>>> from example.TODO import TODO
-rwxr-xr-x 1 root root      2349 May 23 20:51 readme.txt
+
>>> a = TODO
drwxr-xr-x 3 root root      4096 May 23 20:52 syslinux
+
>>> a.name = u'My TODOs'
-rwxr-xr-x 1 root root 309252096 May 23 20:51 sysrcd.dat
+
>>> a.TODOS = [ u'Do Laundry', u'Wash Dishes' ]
-rwxr-xr-x 1 root root        45 May 23 20:51 sysrcd.md5
+
>>> a.daysleft = 1
drwxr-xr-x 2 root root      4096 May 23 20:51 usb_inst
+
>>> a.description = u'Things I need to do today.'
-rwxr-xr-x 1 root root    15889 May 23 20:51 usb_inst.sh
+
>>> root[u'today'] = a
-rwxr-xr-x 1 root root      877 May 23 20:51 usbstick.htm
+
>>> transaction.commit()
-rwxr-xr-x 1 root root        6 May 23 20:51 version
+
-rwxr-xr-x 1 root root  2068480 May 23 20:51 zfs-core-3.4.37-std350-amd64.srm
+
-rwxr-xr-x 1 root root    483328 May 23 20:51 zfs-kmod-3.4.37-std350-amd64.srm
+
-rwxr-xr-x 1 root root    483328 May 23 20:51 zfs-kmod-3.8.4-alt350-amd64.srm
+
 
</console>
 
</console>
 
Now un-mount your flash drive and boot it into the machine that you want to use ZFS on.
 
 
<console>
 
# ##i##umount /mnt/usbstick
 
</console>
 
 
== Booting into the correct kernel ==
 
'''If you are using the standard srm:'''
 
<console>
 
C) Standard 64bit kernel (rescue64) with more choice... >
 
1. SystemRescueCd with default options
 
</console>
 
 
'''If you are using the alternative srm:'''
 
<console>
 
E) Alternative 64bit kernel (altker64) with more choice... >
 
1. SystemRescueCd with default options
 
</console>
 
 
2. Run 'depmod' so that the new modules can be seen by the kernel.
 
 
<console>
 
# ##i##depmod
 
</console>
 
 
{{fancywarning|You must run '''depmod'''. If you don't, then you will get failed to load the ZFS stack error!}}
 
 
3. Use ZFS as usual. If you type '''zpool status''' and then type '''dmesg | tail''',
 
 
you should see something that says:
 
 
<console>
 
ZFS: Loaded module v0.6.1-1, ZFS pool version 5000, ZFS filesystem version 5
 
</console>
 
 
If you see the above, then the modules loaded successfully!
 
 
Enjoy System Rescue CD with ZFS :)
 
 
 
== Using the premade iso ==
 
 
<big>If you don't want to do any of the above stuff but just want the ISO with the ZFS SRMs already included, simply [http://ftp.osuosl.org/pub/funtoo/distfiles/sysresccd/ Download the ISO].</big>
 
  
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
 +
[[Category:Featured]]

Revision as of 14:21, 13 January 2014

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

Contents

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

#  emerge -av zope

Zope is now installed.

Project Skeleton

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

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()