[Zope] How to configure Zope & Python environment

Steve Hunter Steve@hosys.com
Tue, 15 Jun 1999 00:33:03 -0400


Hello,
 I am running Zope on windows using the builtin webserver and attempting to
add a new Product. The way
I've been going about using Zope so far is to install a new "Zope directory"
for each new project...not so
bad until I started trying to "compile" python code. It seems to me I should
create a "default" install of
Zope and point my python path to those directories ?

I am trying to compile the following Product code (below) and get the
following err message:

Traceback (innermost last):
  File
"C:\Tech\Lang\Python\Python152\Pythonwin\pywin\framework\scriptutils.py",
line 237, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Zope\ProjectMgt\lib\python\Products\ProjectMgt\projobjs.py", line
1, in ?
    from Globals import HTMLFile, MessageDialog, Persistent
  File "C:\Zope\ProjectMgt\lib\python\Globals.py", line 90, in ?
    import Acquisition, ComputedAttribute, App.PersistentExtra, os
  File "C:\Zope\ProjectMgt\lib\python\App\PersistentExtra.py", line 87, in ?
    from Persistence import Persistent
ImportError: cannot import name Persistent

My path settings are at the end of the code below.


#-------projobjs.py---------------------------------------------------------
------------------------
from Globals import HTMLFile, MessageDialog, Persistent
import OFS.SimpleItem, Acquisition, AccessControl.Role
import sys,DocumentTemplate

projectDict = {}	#MAPS PROJECT id string to PROJECT  object
taskDict = {}		#MAPS TASK id string to TASK object

class Project(
	OFS.SimpleItem.Item,
        Persistent,
        Acquisition.Implicit,
        AccessControl.Role.RoleManager,
        ):

	index_html =
DocumentTemplate.HTMLFile("c:\Zope\ProjectMgt\lib\python\Products\ProjectMgt
\project.dtml")

	_id = ''
	_name = ''
	_descr = ''
	_tasks = {}    #list of Tasks I contain

	def __init__(self, projectID):
		self._id = projectID

	#setters
	def set_id(self, anID):
		self._id = anID

	def set_name(self, aName):
		self._name = aName

	def set_descr(self, aDescr):
		self._descr = aDescr

	def addTask(self, aTask):
		#require aTask not nul
		self._tasks[aTask.id()] = aTask

	#getters
	def id(self):
		return self._id

	def name(self):
		return self._name

	def descr(self):
		return self._descr


#end class Project



class Task:

	index_html =
DocumentTemplate.HTMLFile("c:/Zope/ProjectMgt/lib/python/Products/ProjectMgt
/task.dtml")

	_id = ''
	_name = ''
	_descr = ''
	_owner = '' #Person responsible for the task
	_project = ''   #the project that contains me
	_budgeted_units = 0
	_budgeted_unit_type = ''
	_budgeted_mhrs = 0

	def __init__(self,ID):
		self._id = ID

	def test(self):
		#dump internals
		print('in Task test')

	#setters
	def set_id(self,anID):
		self._id = anID

	def set_name(self, aName):
		self._name = aName

	def set_descr(self, aDescr):
		self._descr = aDescr

	def set_project(self, aProject):
		#aProject: PROJECT
		self._project = aProject

	def set_budgeted_units(self,aUnits):
		#must match unit type
		self._budgeted_units = aUnits

	def set_budgeted_units__type(self,aUnitType):
		self._budgeted_units_type = aUnitType

	def set_budgeted_mhrs(self,aMHRS):
		self._budgeted_mhrs = aMHRS


	#getters
	def id(self):
		return self._id

	def name(self):
		return self._name

	def descr(self):
		return self._descr

	def budgeted_units(self):
		return self._budgeted_units

	def budgeted_units_type(self):
		return self._budgeted_units_type

	def budgeted_mhrs(self):
		return self._budgeted_mhrs




#end class Task


#---------------Call back functions for GUI------------------------

def addTaskToProject(aTaskID, aProjectID):
	#require valid id's and exist in the dictionaries
	prj = projectDict[aProjectID]
	task = taskDict[aTaskID]
	prj.addTask(task)

#end addTaskToProject

def createNewProject(anID,aName):
	p = Project(anID)
	p.set_name(aName)
	projectDict[p.id()] = p

def createNewTask(anID,aName):
	t = Task(anID)
	t.set_name(aName)
	taskDict[t.id()]= t

def dumpProjectDictContents():
	for prjKey in projectDict.keys():
		print 'project key: ' + prjKey + ' name: ' + projectDict[prjKey].name()


def dumpTaskDictContents():
	for key in taskDict.keys():
		print 'task key: ' + key + ' name: ' + taskDict[key].name()

def projectReport():
	for prjKey in projectDict.keys():
		print 'project key: ' + prjKey + ' name: ' + projectDict[prjKey].name()
		for taskKey in projectDict[prjKey]._tasks.keys():
			print 'task key: ' + taskKey
		taskKey = ''


#end createNewProject

#--------------------------------------------------------------------

def testRun():
	createNewProject('x123','Project A')
	createNewProject('y124','Project B')
	createNewProject('z125','Project C')
#	dumpProjectDictContents()

	createNewTask('t1231','Task A')
	createNewTask('t1232','Task B')
	createNewTask('t1233','Task C')
	createNewTask('t1241','Task D')
	createNewTask('t1242','Task E')
	createNewTask('t1251','Task F')
	createNewTask('t1252','Task G')
#	dumpTaskDictContents()

	addTaskToProject('t1231','x123') #some how all the tasks are added to all
the projects
	addTaskToProject('t1241','y124')

	projectReport()


#end testRun

def testHTML():
	t = Task('123')
	t.set_name('abc')
	t.set_descr('This is task abc easy as 123')
	print t.index_html(t)

	p = Project('456')
	p.set_name('def')
	p.set_descr('This is cool')
	print p.index_html(p)


if __name__ == '__main__':
	#testRun()
	testHTML()





set
PYTHONPATH=.;c:\tech\lang\python\python152\lib;c:\tech\lang\python\python152
\lib-tk;c:\tech\lang\python\tcl\lib;c:\tech\lang\python\tcl\bin
set PYTHONPATH=%PYTHONPATH%;c:\tech\lang\python\zopemodules
set PYTHONPATH=%PYTHONPATH%;c:\tech\lang\python\zopemodules\DocumentTemplate
set PYTHONPATH=%PYTHONPATH%;c:\tech\lang\python\zopemodules\Ofs
set PYTHONPATH=%PYTHONPATH%;c:\tech\lang\python\zopemodules\ZPublisher
set PYTHONPATH=%PYTHONPATH%;c:\tech\lang\python\zopemodules\Shared
set PYTHONPATH=%PYTHONPATH%;c:\tech\lang\python\zopemodules\DateTime


regards,
 Steve