Re: [Zope] Acquisition not working as expected

2006-03-03 Thread Roman Klesel
Andrew Milton schrieb:
 
 Perhaps if you describe the problem you're trying to solve, we can actually
 help you.
 

Yes, thank you!

I just want to be able to do what I'm used to do from TTW:

- There is a hirarchy of Folder/File objects
- In the root directory there is an python script (showData.py)
- the python script operates on context eg.

return context.data

From a ZPT I can now loop over a Folder and call the python script on every 
object in the folder:

ul
 li tal:repeat=elem context/objectValues
 tal:content=elem/showDatadata/li
ul

Depending on the URL I call this on I will get a list of data of all files 
present here.

This is just what I want to do in the fs product I'm writing:

I have a folderish object that holds a collection of File objects nicely sorted 
in a hirarchy of Folders objects.
This folderish object has methods to display the data in the File objects 
(underneth it self) in differnt ways eg.

def genGraph(self):
plot graph from self.data and return a png image
...

def getDataMatrix(self):
return self.data as a list of rows where every field is a list element
...

just as in my example above I want to be able to call this methods on any File 
objects from a ZPT like this:

ul
 li tal:repeat=elem context/objectValues
  img tal:attributes=src string: ${elem/absolute_url}/genGraph plot /img
 /li
ul

Therefore I started the thread:
[Zope] context in fs product

The answer I got:

'self' inside the a Zope product is the _same_ as 'context' or 'here' within
ZPT or PythonScripts.

So now I'm stuck.

Of course I could pass the object or its id to the methods as an argument eg.

span tal:define=data python:context.genGraphs(elem)sdf/span

and in the method get the the object with getattr() or something ...

But this wouldn't be nearly as nice and I'd like to avoid this.


(The code examples here might have errors, I just typed them in as an 
illustration of my thougts)

Greetings Roman


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Acquisition not working as expected

2006-03-03 Thread Roman Klesel
Andrew Milton schrieb:
  | ul
 |  li tal:repeat=elem context/objectValues
 |   img tal:attributes=src string: ${elem/absolute_url}/genGraph plot 
 /img
 |  /li
 | ul
 
 In what way doesn't this work? I've certainly used this pattern in my FS
 products without problems.


Hmm? Did I miss something? A few posts above we recoginzed that when I would do:

def genGraph(self):
bla
return self.data

then genGraph would return data from the class where it is defined and not from 
the object acquiring it. So it would fail.

 | 'self' inside the a Zope product is the _same_ as 'context' or 'here' within
 | ZPT or PythonScripts.
 
 It IS in the context of that object. However, if you call a method that is
 acquired, self in that method is the acquired object, not the acquiring 
 object.
 

Yes, this is what I understood (at least I think so) now. So the question is:

How will the method find out what object I want it to operate on if I call it 
in this way

context/genGraphs or objref/genGraphs

I actually want it to operate on the object I called it on, but this is not 
what self inside the method represents.

Roman
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Acquisition not working as expected

2006-03-03 Thread Roman Klesel
Andrew Milton schrieb:
 How about you forget about Acquisition for now.


Well, hmmm ... this will be hard ... I was just about to fall in love with it 
...

 Define the method in the class you want to call it on.

Then I will have to subclass from OFS.Image.File and I was told that this is 
somehow evil. From a previous thread:

Roman Klesel wrote:
 form OFS.Image import File

 - I build a class _File(File):

I really doubt you need to do that...

 - pimped it up a little bit.

What, specifically, did you add?

 - _setObject'ed it

You shouldn't be calling that directly...


 If you CAN'T define the method in the class (not sure why you couldn't), then
 you will have to define a method and pass an instance or a reference.
 

This makes the code in the ZPT all messy...

The third option is to somehow construct the the object the method should 
operate on from self.REQUEST.
I think I will try that ...

I was really hoping to get to understand this acquisition thing.
Am I really that far away from getting it? What does it take to grasp it?

Thanks anyway for your time and efforts!

Roman
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Acquisition not working as expected

2006-03-02 Thread Roman Klesel
Hello,

Roman Klesel schrieb:
  I can call this method on whatever folder inside the product instance I 
  want, it will always return the id of the
 product and not the id of the product I call it on.

In order to make my problem more obvious I created a minimal product. See 
attachmet.

It displays exactly the problem I'm facing:

A method in the base class that returns self.id, returns the id of the base 
class on all subfolders it is called.

Code:

 __doc__=This is Minimal
__version__='0.1'

from Globals import InitializeClass, Persistent
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from AccessControl import ClassSecurityInfo
from Acquisition import Implicit
from OFS.ObjectManager import ObjectManager
from OFS.SimpleItem import SimpleItem
import OFS


class minimal(Persistent,Implicit,ObjectManager,SimpleItem):
minimal object
security = ClassSecurityInfo()
meta_type = 'minimal'

def __init__(self, id):
initialise a new instance of Minimal
self.id = id

index_html=PageTemplateFile('zpt/index.html',globals())

security.declarePublic('sayHello')
def sayHello(self):
just says hello
return 'Hello'
def showId(self):
return self.id

def manage_addMinimal(self, REQUEST=None):
Add a Minimal to a folder.
self._setObject('minimal_id', minimal('minimal_id'))
min_obj = getattr(self,'minimal_id')
min_obj.manage_addFolder('tfolder')
if REQUEST is not None:
try:
destURL=self.DestinationURL()
except:
destURL=REQUEST['URL1']

REQUEST.RESPONSE.redirect(destURL+'/manage_main')   
return ''   

InitializeClass(minimal)


Any ideas anyone?

Greetings Roman



minimal.tar.gz
Description: GNU Zip compressed data
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Acquisition not working as expected

2006-03-01 Thread Roman Klesel
Hello,

sorry to come up with this again. I startet 2 pretty confused threads on the 
same problem allready:

[Zope] Error Value: 'File'  object  has no  attribute   
'manage_fixupOwnershipAfterAdd'
Re: [Zope] context in fs product

Unfortunatly I'm still not getting it right.
I implemeted the good advices I got in the 2 Threads, slept over it a couple of 
nights. Looked at the code again,
cleaned it up ... still: no success.

Here is what I'm doing:

I'm about to write a fs product to report on data generated by the grinder 
load test tool
The load tests produce various log files and sar outputs that will have to be 
parsed and imported into Zope.

The instance of the product is created:

def manage_addZLTMS(self,id,title='',REQUEST=None,submit=None):
Add a ZLMTS to a folder.
id=id.replace(' ','_')
zltmsObj=ZLTMS(id,title)
id=self._setObject(id, zltmsObj)
folder=getattr(self, id)
folder.manage_addFolder(id='LoadTests',title='Collection')

The LoadTest folder is the place where the imported data will be stored.

The base class ...

class ZLTMS(Lasttest,Implicit, Persistent, PropertyManager, ObjectManager, 
SimpleItem):
ZLMTS object

... has an import method

def newLasttest(self, REQUEST=None):
 new 
ltc=getattr(self,'LoadTests')
ltid = self.genId(ltc)
lt=Lasttest()
lt.id=ltid
ltc._setObject(ltid,lt)
self.lt = getattr(ltc,ltid)
self.lt.importData(self.manage_targets)

This generates and instance of the Lasttest() class and imports the data.
Lasttest() subclasses from Folder() and store all imported data in a folder 
hirarchy under itself.

This all works fine and I can browse the imported data in the ZMI. The problems 
start when I want to access the data.

eg.:

In the base class I created a test3() method:

def test3(self):
dsaf
return self.getId()

I can call this method on whatever folder inside the product instance I want, 
it will always return the id of the
product and not the id of the product I call it on.

Why is that?

So I thought for some reasons the objects in the folder hirarchy are not 
acquisition wrapped. So I created another
testspace() method in the base class:

def testspace(self,REQUEST=None):
tests
if hasattr(self, 'aq_base'):
return 'aq wraped'
return 'not aq wraped'

I can call this on any object in the folder hirarchy and it returns:
'aq wrapped'.

Can so. please help me get this straight or hint towards further analysis that 
I can do.

Thanks in advance.

Greetings Roman

BTW: I did not post any code of the Lattest() class since the problem is 
allready present in the folder that holds its
instances. Of course I will post any part of the code you want me to.
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Acquisition not working as expected

2006-03-01 Thread Roman Klesel
Hello Andrew,

Andrew Milton schrieb:
 Are you sure your genId() method works?
 

Well, yes, it does what it's ment to do. It generates an id, a string.

Here it is:

def genId(self,context):
asdf
items = [ int(e[2:]) for e in context.objectIds('Folder') ]
if items == []:
return 'lt10'
return 'lt%s' % str(max(items)+1

 what does return self.id return instead of self.getId() ?
 

I just checked, there is no difference. Both return the id of the product 
instance as string.

Greetings Roman
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Acquisition not working as expected

2006-03-01 Thread Roman Klesel
Andrew Milton schrieb:
 Did you paste this code, because it has errors...

Ahh sorry, I missed the last charakter, a ).

Here it is again:

def genId(self,context):
asdf
items = [ int(e[2:]) for e in context.objectIds('Folder') ]
if items == []:
return 'lt10'
return 'lt%s' % str(max(items)+1)

Greetings Roman
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Acquisition not working as expected

2006-03-01 Thread Roman Klesel
Dieter Maurer schrieb:
I can call this method on whatever folder inside the product instance I want, 
it will always return the id of the
product and not the id of the product I call it on.
 
 
 I fear you will need to more clearly describe what you mean
 with the product (on one hand) and the product I call it on
 (on the other hand).

Yes sorry I got this wrong. The sentence should be like that:

I can call this method on whatever folder inside the product instance (instance 
of the base class ZLTMS) I want, it will
always return the id of the instace of the base class (where the method is 
defined) and not the id of the object (Folder
object or File object) I call it on.

Once again:

The module that holds the base class looks like this:

__doc__=Das ist ZLMTS
__version__='0.1'

from Globals import InitializeClass, Persistent
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from AccessControl import ClassSecurityInfo
from AccessControl.Role import RoleManager
from Acquisition import Implicit
from OFS.SimpleItem import SimpleItem
from OFS.PropertyManager import PropertyManager
from OFS.ObjectManager import ObjectManager
from OFS.Folder import Folder
from Lasttest import Lasttest

manage_addZLTMSForm=PageTemplateFile('zpt/manage_addZLTMSForm',globals())


def manage_addZLTMS(self,id,title='',REQUEST=None,submit=None):
Add a ZLMTS to a folder.

id=id.replace(' ','_')
#Jetzt wird das Product als Instanz erzeugt ...
zltmsObj=ZLTMS(id,title)
#... und persitiert
id=self._setObject(id, zltmsObj)
folder=getattr(self, id)
#Create a container for the Loadtests
folder.manage_addFolder(id='LoadTests',title='Collection')

#irgned ein WODOO falls jemand das PRoduct programmatisch hinzufuegt.
if REQUEST is not None:
try:
destURL=self.DestinationURL()
except:
destURL=REQUEST['URL1']

REQUEST.RESPONSE.redirect(destURL+'/manage_main')   
return ''


class ZLTMS(Lasttest,Implicit, Persistent, PropertyManager, ObjectManager, 
SimpleItem):
ZLMTS object

security = ClassSecurityInfo()
meta_type = 'ZLMTS'

manage_options = ObjectManager.manage_options + (
 {'label' : 'View', 'action' : ''},
 {'label' : 'Settings', 'action' : 
'manage_editSettingsForm'},
 ) + PropertyManager.manage_options + 
SimpleItem.manage_options

_properties=({'id':'title','type':'string','mode':'w'},
 {'id':'description','type':'text','mode':'w'},
 )


def __init__(self, id, title='', description='' ):
initialise a new instance of ZLMTS
self.id=id
self.title=title
self.description=description
self.location_types=['http','path']
self.manage_targets={'gr_sys' : {'name' : '',

 'phy_mem' : '',

 'location_sar' : '',

 'grinder_home' : '',

 'server_start_url' : ''},
 'sys1' : {'name' : '',
   
'phy_mem' : '',
   
'location_sar' : '',
   
'server_start_url' : ''}}

and so on ...
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] context in fs product

2006-02-20 Thread Roman Klesel
Hello,

from doing TTW I'm used to call methods on the object that is passed in by the 
context variable.
I'm just writing my first fs based product and was wondering how I can get 
context from within a method?

Of course I can try to construct it from self.REQUEST, but ... is this _THE_ 
way to do it?

Greetings Roman
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] context in fs product

2006-02-20 Thread Roman Klesel
Lennart Regebro schrieb:
  It's usually called self...


hmmm ... strange ...

in a class:


class Controller(Implicit,ObjectManager, SimpleItem):
asfd

I have a method:

def testspace(self,REQUEST=None):
   tests
   req = self.absolute_url(self)
   return req

and on whatever URL I call it , it returns the base URL of the product instance 
...

All classes in the product subclass form Acquisition.Implicit. What am I 
missing here?

Thanks so far!

Roman


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] context in fs product

2006-02-20 Thread Roman Klesel
Hello,

Andrew Milton schrieb:
 | Thanks so far!
 
 Is it set inside the ZODB yet?


*bling*

yes, that kicked me out of the mental loop.

As you suggested this test class is not in ZODB and therefore the aquisition 
does not work.

Therefore my testcase is useless and I've to investigate my problem in a 
different way.

Thanks
Roman




___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Error Value: 'File' object has no attribute 'manage_fixupOwnershipAfterAdd'

2006-02-20 Thread Roman Klesel
Chris Withers schrieb:
 for id in self.manage_targets.keys():   
 title =
 self.manage_targets[id]['name']   
 self.tgt_folder=Folder()   
 
 
 This is dangerous...

Why is that?

 self._setObject(id,self.tgt_folder)   
 
 
 This is silly...

What's silly about persisting the object I just created?


 Why not just:
 
 self.manage_addFolder(id,title)

Well, the suggestion I got was to do:

self.manage_addProduct['OFSP'].manage_addFolder(...

and this runs in the Error Value: _getProducts
Error.

 
 grinder_home = self.manage_targets['gr_sys']['grinder_home']   
 host_name = self.getHostname(grinder_home)   
 
 
 Okay, what type of object is 'self' here, where did you take this code
 from?

I'm proud to say: I wrote this myself. :-)

self is supposed to be a foldeish object that is supposed to be the container 
for all objects I'm about to create in
this routine.


 system = self.__getitem__(id)   
 
 why not just:
 
 system=self[id]


Great! Didn't know that!



 Also, this will result in system not being acquisition wrapped in some
 circumstances, what you really want is:
 
 system = getattr(self,id)
 
 ...but it really depends on what 'self' is, I'm not sure you have that
 right.

This also works. However to me it looks like, it produces the exact same result 
as __getitem__ and self[id] ...

This  being acquisition wrapped is driving me nuts!
I just don't get it.

And I belive it's the cause for the problems I'm facing ...

Thanks for taking the time analyzing my code!

Greetings Roman
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Error Value: 'File' object has no attribute 'manage_fixupOwnershipAfterAdd'

2006-02-20 Thread Roman Klesel
Hello Sascha,

Sascha Welter schrieb:
 
 manage_addFile (and some others like manage_addFolder, ...) work
 directly without xy.manage_addProduct[...]. 
 
 That part is in the Zope book.
 
 The syntax with manage_addProduct[... is used for filesystem based
 products (like the stuff you have in your instances Products folder).

well, thanks for your consideration, but I'm actually concerned about fs based 
products.
The whole thread is probably totally confusing because I'm totally confused.
I found several inconsistnecies in my code. I'm right now doing a total 
rewright. I'll see it the problems persist.
If so, I'll try to be less confused and decribe the problem more clearly.

Greetings Roman


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Error Value: 'File' object has no attribute 'manage_fixupOwnershipAfterAdd'

2006-02-16 Thread Roman Klesel
Hello,

Jens Vagelpohl schrieb:
 If that object  subclasses
 from the normal Zope Folder class (or is a Zope Folder)  you *will* have
 manage_addProduct.

Yes, actually you guys a right! self.manage_addProduct is available...
Hmmm ... wonder what made me think it's not ...

Still I can't get what I want.

when I now do:

system.manage_addProduct['OFSP'].manage_addFile(fid,
title='',
file=cpu_load,
content_type='text/plain',
precondition='')


I get:

AttributeError: _getProducts

So I poked around and rose an exception like this:

 raise KeyError, 'id: %s object: %s self: %s' % (id, system, self)
KeyError: 'id: gr_sys object: Folder at  self: Lasttest at lasttest55004'

Where
 - id is the id of the folder where I want to create the file in.
 - object is the object reference of the same folder
 - and self ist ... self: a folderish object.

So there seems to be something wrong with object. It's recognized that it is 
a folder but for some reason
it seems that it has no real object reference.

It is created like this:

self.tgt_folder[id]=Folder()
self._setObject(id,self.tgt_folder[id])

Of course I should create it with the managed_addProduct[ ... method, but it 
doesn't work. I again get:
AttributeError: _getProducts

I'm getting more and more confused ...

I mean the whole thing can't be totally wrong since everything worked exept 
for, that the objects that I wanted to
have where of type SimpleItem and not File.

So there seems to be something wrong with by parent obejct ... But again this 
is also not possible since i can add
a File product manually with the ZMI ..


Any light s.o.?

Roman


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Error Value: 'File' object has no attribute 'manage_fixupOwnershipAfterAdd'

2006-02-16 Thread Roman Klesel
Hello,

one more thing ...

Roman Klesel schrieb:
Your error *may* mean that 'system' is not yet wrapped. Are your 
positive that 'system' is a folder that already exists in the ZODB, 
i.e. has already been _setObject'ed?
 
 
 As far as I can tell: Yes!

Actually I'm pretty shure, because as I said:

the whole thing ran successfully with _setObject() but in order to get a File 
Produkt I took the advice
to use manage_addProduct[... and that's where I'm stuck ...

Roman

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Error Value: 'File' object has no attribute 'manage_fixupOwnershipAfterAdd'

2006-02-16 Thread Roman Klesel
Hello again,

I works! I just managed to get everything as I expected it to be.

How I did it:

form OFS.Image import File

- I build a class _File(File):
- pimped it up a little bit.
- instatiated it
- _setObject'ed it

... et voila

I have nice File-objects with nice CMI interface...

Thanks for holding my hand.

Greetings Roman
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] How to get $PRODUCT_HOME

2006-02-07 Thread Roman Klesel
Hello again,

I just started with FS products and have trouble to figure some things out ...

From within zope I would like to call scripts that I provide in the product 
folder on the file system like eg.:

handle = os.popen('gnuplot %s/bin/loadgraphs.gplt' % product_folder, 'r')

How can I get the path to the product folder?
Thanks in advance!

Greetings Roman
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How to get $PRODUCT_HOME

2006-02-07 Thread Roman Klesel
Hello Andrew,

Andrew Milton schrieb:
 | 
 | How can I get the path to the product folder?
 
 from Globals import package_home
 
 package_home(globals())
 
 should give you what you need.
 

yes this does the trick! Thanks!

Greetings Roman
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How to get $PRODUCT_HOME

2006-02-07 Thread Roman Klesel
Hi Tino,

Tino Wildenhain schrieb:
 How can I get the path to the product folder?
 Thanks in advance!
 
 
 see the __file__ variable in your module.
 
 for example via:
 
 os.path.dirname(os.path.abspath(__file__))
 
 you get the absolute path of the directory
 where your module is. Complete it to:
 
 os.path.join(os.path.dirname(os.path.abspath(__file__)),'bin','loadgraphs.gplt')
 
 
 to get the full path of your file os independent
 (e.g. works the same with unix,windows,mac os...)
 

wow, yes also interesting. In case one needs to get the path of an individual 
module.

For my current task I went with Andrew's proposal and used 
package_home(globals()). That seems to work well.
But your suggestion will be helpful in some other thing I have in mind ...

Thanks!

Greetings Roman
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] inheritance and aqusition question

2006-02-03 Thread Roman Klesel

Hello,

im just learning zope and python and find it difficult to get the details of 
aquisition and inheritance.
I have the following problem:

(FS product)

My base class has an attribute manage_editSettingsForm
In its __init__ method I instantiate a contoller class.
In the methods of the controller class can access self.manage_edtiSettingsForm 
(fine)
Now I instantiate a importSingle class in a method of the controller class.
In the methods of the importSingle class I cannot access 
self.manage_edtiSettingsForm (why?)

Controller class:

from Acquisition import Implicit
from Globals import InitializeClass, Persistent
from Products.PythonScripts.Utility import allow_class, allow_module
from AccessControl import ClassSecurityInfo
from OFS.SimpleItem import SimpleItem
from OFS.ObjectManager import ObjectManager
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
from Lasttest import Lasttest
import sys, os, urllib, commands, re, types
import LTimport


allow_module=('Controller')

class Controller(Implicit,ObjectManager, SimpleItem):

-

importSingle Class:

from Globals import InitializeClass
from Acquisition import Implicit
import os,re

class importSingle(Implicit):


I tried subclassing form SimpleItem and ObjectManager but it didn't work.
What is required that inheritance will work?

Greetings Roman

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] inheritance and aqusition question

2006-02-03 Thread Roman Klesel
Hello Andrew,

thanks for your reply.

Andrew Milton schrieb:
 
 One (or more) of the following two;
 
 Your class isn't yet fully instantiated and Acquisition wrapped, this normally
 doesn't occur until your class is inside the ZODB. 

That's true! And it's nor supposed to be. It's only a temporary Object that's 
being destroyed
after the method in which it's created has finished processing.

You generally need to use a
 'post init' method to do a 2-stage init so that subitems can acquire items.
 There are Zope hooks you can use (manage_afterAdd), or you can call your
 own methods in the manage_add Factory method of your product.
 
 If this is what you are doing then it's probably;
 
 The importSingle class must be an attribute of the Controller class for
 Acquisition to work in this way. 

I wouldn't like to do that either, because I don't want that object to persist.

Probably I just do things in the wrong way. What I wnat to do is:

In the temporary object:

try:
   h=open('file',r)
except:
   em = 'File %s does not exist' % file
   return REQUEST.RESPONSE.redirect(self.manage_editSettings(REQUEST), em)

the calling Object then would pass it to the browser ...

... in order to do some exception handling.

is there an other way to redirect to the settigs Form when an error occurs in 
this nonpersistent object?

Greetings Roman

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Newbee interfaces and implementations

2006-01-19 Thread Roman Klesel
bruno modulix schrieb:
 So you recommend that I should just skip them as long as I'm on Zope2?
 
 
 Short answer :  yes. Unless you plan to switch to Zope3 really soon, but
 then, I'd recommand that you skip Zope 2.x !-)

No, I'll be with Zope2 for a while. I'm running an Plone site too and dont't
have the memory to run a second Zope3 instance.

I think my question is answered and I'm a little less confused now. :-)

When I heard the word interface I thought of something like a network 
interface,
which is the communication gateway to the entire machine if you address it from 
network:

- you physically connect it to the network by plugging a cable into the NIC
- you address it by calling an address which is assigned to the NIC.

actually all other devices on the network only see the target machine as a 
network interface
and don't know what kind of system it is plugged into until the methods the 
interface provides
trigger routines that reveal more information.

So, now I understand that interfaces in a the Zope2 context have some different 
meaning.

Maybe I should understand them as pseudo interfaces.

Roman

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Newbee interfaces and implementations

2006-01-18 Thread Roman Klesel
Hello,

I'm in the process of learning to develop fs-zope-products.

The developers guide recommends to write interfaces and implement them in 
classes. Now my question:

When I have an interface:

DoThings

with several methods:

doThis()
doThat()
doThattoo()
...

and I have an implementation:

DoThingsClass

How will I then access the methods e.g. in a Template?

Through the interface:

tal:define=context/DoThings/doThis

or through the implemantation:

tal:define=context/DoThingsClass/doThis

I would think the first one should be the case. But then how does the interface 
know where the implementation of the
method is defined since it doesn't import the implementation?

I'm currently on Zope 2.84.

Please shed some light on me!

Greetings Roman



___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Newbee interfaces and implementations

2006-01-18 Thread Roman Klesel
bruno desthuilliers schrieb:
 Looks like you're newbie to OO too !-)
 
 A class defines a type. You then need to have an instance of that type
 (like, say, 42 is an instance of type integer and 'foo' is an instance
 of type string).
 

Yes, true! :-)

  (Interfaces (I mean, 'explicit' interfaces) defines an 'abstract' type,
 that can be implemented by many classes. With Python's dynamic typing,
 you don't *need* explicit interfaces - at least with Zope 2.x. AFAICT,
 the recommandation to use explicit interfaces is mostly about Zope3
 relying on them to implement some nice features).
 
 So it would be:
 
 tal:define=some_name context/myObject/doThis
 
 As you see, you don't have to worry about interface at this level...

So you recommend that I should just skip them as long as I'm on Zope2?

I would be happy with that. I find them confusing when they don't
really interface with but just document my methods.

Thanks

Roman


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] adding property to new Folder: can't pickle module objects

2005-08-30 Thread Roman Klesel
Hello everyone,

again I'm stuck :-(

I have a python script that looks as follows:

results=[]
for ids in context.objectIds('Folder'):
results.append(ids)

newid = str(int(max(results)) + 1)

context.manage_addProduct['OFSP'].manage_addFolder(newid, title=person)

newaddr=getattr(context, newid)

newaddr.manage_addProperty(test, test, string)

return 0


When I run it it returns the error:

Error Type: TypeError
Error Value: can't pickle module objects



It looks like as if the Folder doesn't get created when the
manage_addProperty() function tries to modify it.

If I comment out the line with the manage_addProperty() function the
folder however gets created and newaddr has as sensible value.

Please help me to clarify this.

Thanks in advance

Roman





___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] passing parameters from form to script

2005-08-29 Thread Roman Klesel
Hello everyone,

I'm dynamically generate a form e.g like this:

form action=paramtest method=post

table class=normal
  tr valign=top align=left
  tal:repeat=item
python:context.Templates.AddressTemplate.propertyIds()

td tal:content=itembla/td
tdinput type=text
   name=item
   value= tal:attributes=name item; value
python:context.Templates.AddressTemplate.getProperty(item)
/td
 /tr
 tr
  td
  input type=submit value=Save
  input type=reset value=Cancel
  /td
 /tr
/table/form


How can I process the parameters with the target script? I don't know how
many parameters will be passed to the script by the form. I also don't
know  their names.

I allready tried various things and did some research in the docs and
lists but can't figure it out.

I thougth of stuffing all the values in one list with the :records option
but couldn't it right.

I tried :

tdinput type=text
   name=item
   value= tal:attributes=name addr.item:records; value
python:context.Templates.AddressTemplate.getProperty(item)
/td

but this also doesn't work.

Will s.o. please help me to get on the right track?

Greetings

Roman

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )