473,387 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ZODB and Boa

If this is inappropriate here, please advise...

I'm having some difficulty getting ZODB to play nice with Boa.
Specifically, after creating a simple interface with a text field &
btn, I added a python module and imported it into the main (wxFrame)
code:

(python module code)
import ZODB.config
db = ZODB.config.databaseFromURL('calendar.conf')
conn = db.open()
dbroot = conn.root()
dbname = 'calendar_db'
sched = dbroot[dbname]

from persistent import Persistent
#from persistent.list import PersistentList
#from persistent.mapping import PersistentMapping

class Calendr(Persistent):
def __init__(self):
self.date = 0
self.datedata = ()
self.fds = []
self.first = []
self.second = []
self.third = []
self.all = []
self.stats = {}

abc = sched[20050101]
efg = abc.first
print efg
(end code)

When run (from the wxFrame), the textbox value set to 'efg,' an err
msg states that 'first' is not an attribute of Calendr.
When the textbox value is set to str(abc), the err msg states:
<persistent broken __main__.Calendar instance
'\x00\x00\x00\x00\x00\x00\x00\x1c'>

When the python module is run directly (thru Boa), it seems to work
fine, and the print value seen in the code above appears in the Output
section of the Boa Editor frame.

Any direction appreciated.

--
Jul 18 '05 #1
4 1721
Gary wrote:
I'm having some difficulty getting ZODB to play nice with Boa.
Specifically, after creating a simple interface with a text field &
btn, I added a python module and imported it into the main (wxFrame)
code:

(python module code)
import ZODB.config
db = ZODB.config.databaseFromURL('calendar.conf')
conn = db.open()
dbroot = conn.root()
dbname = 'calendar_db'
sched = dbroot[dbname]

from persistent import Persistent
#from persistent.list import PersistentList
#from persistent.mapping import PersistentMapping

class Calendr(Persistent):
def __init__(self):
self.date = 0
self.datedata = ()
self.fds = []
self.first = []
self.second = []
self.third = []
self.all = []
self.stats = {}

abc = sched[20050101]
efg = abc.first
print efg
(end code)

When run (from the wxFrame), the textbox value set to 'efg,' an err
msg states that 'first' is not an attribute of Calendr.
When the textbox value is set to str(abc), the err msg states:
<persistent broken __main__.Calendar instance
'\x00\x00\x00\x00\x00\x00\x00\x1c'>

When the python module is run directly (thru Boa), it seems to work
fine, and the print value seen in the code above appears in the Output
section of the Boa Editor frame.


I encountered similar problems when the objects serialized were imported as
members of a certain module - and then, when that module is not found under
that name when deserializing, the object is broken as yours. So make sure
that if your object is of type foo.Bar, when deserializing import foo,
containing Bar.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
On Wed, 13 Oct 2004 20:39:52 +0200, "Diez B. Roggisch"
<de*********@web.de> , created a minor stir when he wrote:
Gary wrote:
I'm having some difficulty getting ZODB to play nice with Boa.
Specifically, after creating a simple interface with a text field &
btn, I added a python module and imported it into the main (wxFrame)
code:

(python module code)
import ZODB.config
db = ZODB.config.databaseFromURL('calendar.conf')
conn = db.open()
dbroot = conn.root()
dbname = 'calendar_db'
sched = dbroot[dbname]

from persistent import Persistent
#from persistent.list import PersistentList
#from persistent.mapping import PersistentMapping

class Calendr(Persistent):
def __init__(self):
self.date = 0
self.datedata = ()
self.fds = []
self.first = []
self.second = []
self.third = []
self.all = []
self.stats = {}

abc = sched[20050101]
efg = abc.first
print efg
(end code)

When run (from the wxFrame), the textbox value set to 'efg,' an err
msg states that 'first' is not an attribute of Calendr.
When the textbox value is set to str(abc), the err msg states:
<persistent broken __main__.Calendar instance
'\x00\x00\x00\x00\x00\x00\x00\x1c'>

When the python module is run directly (thru Boa), it seems to work
fine, and the print value seen in the code above appears in the Output
section of the Boa Editor frame.


I encountered similar problems when the objects serialized were imported as
members of a certain module - and then, when that module is not found under
that name when deserializing, the object is broken as yours. So make sure
that if your object is of type foo.Bar, when deserializing import foo,
containing Bar.


Thanks for the quick reply.

Excuse my newbiehood/ignorance, I'm not sure I understand your reply.
Would you please elaborate?

When I run the python module stand-alone, or within boa with 'Run
Module,' - no problem. However, when I run it via 'Run Application,'
it first hits this code:

#!/usr/bin/env python
#Boa:App:BoaApp
from wxPython.wx import *

import calFrame1

modules ={'calFrame1': [1, 'Main frame of Application',
'calFrame1.py']}

class BoaApp(wxApp):
def OnInit(self):
wxInitAllImageHandlers()
self.main = calFrame1.create(None)
self.main.Show()
self.SetTopWindow(self.main)
return True

def main():
application = BoaApp(0)
application.MainLoop()

if __name__ == '__main__':
main()
<end code>

....and no cigar.
-Gary
--
Jul 18 '05 #3
Hi,
Excuse my newbiehood/ignorance, I'm not sure I understand your reply.
Would you please elaborate?


I'll try.

From your first post:
<persistent broken __main__.Calendar instance


As you can see, ZODB tries to instanciate a class Calendar, that is supposed
to be defined in the python file that is executed by the interpreter - thus
resulting in the __name__ == "__main__", and no module-name prefixed to the
class name "Calendar".

But I doubt that Calendar is defined there, in fact your seconds post code
showed there is only some gui-stuff - instead it will be located in some
module, maybe the "calFrame1" you imported, or in module "code" from your
previous post. I assume the latter for now.

Now when you run the code that first created and stored Calendar objects,
you did run it directly, resulting in the fully qualified classname beeing

__main__.Calendar

But now running your app, you want it to be code.Calendar. Unfortunately,
there is no way (or at least not known to me) to alter the class name
after it has been stored.

So this might help: Delete the ZODB FileStorage, and then rerun your
program. It will work.

Then look at the module "code". Don't use it as you do now - its generally
not a good idea to let code be executed in a modules rump when its
imported. Instead, rewrite it like this:

class Calendar:
....

def init():
# do the initialization stuff you did before in the rump here

if __name__ == "__main__":
# if executed directly, reimport ourselves under the desired name, and
then run init
import code
code.init()

That should then make things work in both ways.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #4
On Thu, 14 Oct 2004 11:24:41 +0200, "Diez B. Roggisch"
<de*********@web.de> , created a minor stir when he wrote:

<snip>

Well, Diez, thank you for your patience & help.
I don't understand the mechanism very well, but the solution was to
build and populate the database from inside boa; I'd originally done
so through the python interpreter in a stand-alone module. I put the
following code in the 'Frame' module (the one that contains all the
GUI initialization code, the 'App' module is the one I'd printed out
in the last message):

<start code>
import ZODB.config; import cPickle; import datetime

db = ZODB.config.databaseFromURL('calendar.conf')
conn = db.open()
dbroot = conn.root()
from BTrees.OOBTree import OOBTree # --- Removed when run later
dbname = 'calendar_db'
dbroot[dbname] = OOBTree() # --- Removed when run later
sched = dbroot[dbname] # DB reference variable

from persistent import Persistent
from persistent.list import PersistentList
from persistent.mapping import PersistentMapping

class Calendar(Persistent):
def __init__(self):
self.date = 0
self.datedata = ()
self.fds = []
self.first = []
self.second = []
self.third = []
self.all = []

d=datetime.date; t=datetime.timedelta
start = d(2005,1,1); incr = t(days=1)
fname = 'baseschedule.dat'
f = file(fname)
bs = cPickle.load(f)

for ii in range(1,366):
conv = start.strftime("%Y%m%d")
piz = Calendar()
piz.date = int(conv)
piz.fds = bs.get(ii)[4][0]
piz.first = bs.get(ii)[1][1:]
piz.second = bs.get(ii)[2][1:]
piz.third = bs.get(ii)[3][1:]
piz.all = bs.get(ii)[4]
sched[piz.date] = piz
get_transaction().commit()
del(piz)
start = start + incr

db.close()
<end code>

With that done, I moved the code above - minus the OOBTree lines and
the populating sections - into a module named 'aMod.' I added an
import line, 'from aMod import * to the 'Frame' module, then added a
function to the aMod module:

def foob():
squink = sched[20050509]
return squink.first

I then added this to the Frame module:

def OnButton1Button(self, event):
self.stext.SetValue(str(foob()))
event.Skip()

Now when the application is run, a click on the button finally gives
me the list value that was stored in the database earlier.

I've been working with Python since July, Boa a little later and ZODB
since earlier this week. Notwithstanding occasional detours &
hair-pulling, it still beats Access & Visual Basic by a long shot. : )

Thanks again,
Gary
--
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
by: Paul Rubin | last post by:
I've started a few threads before on object persistence in medium to high end server apps. This one is about low end apps, for example, a simple cgi on a personal web site that might get a dozen...
10
by: ls | last post by:
Hi All, I looking for help with ZODB data export to text file. I have file Data.fs (file becomes from Plone CMS) and I have to display content structure, data like intro, body of article, etc...
1
by: Harald Armin Massa | last post by:
Hello, I am using ZODB "standalone" in version 3.3.1 within some application. Now I learn that the 3.3.x branch of ZODB is "retired". No problem so far, everything is running fine. BUT......
3
by: Rene Pijlman | last post by:
I have a productional Linux web server with a Python/Zope/Plone. Now I'd like to install a non-Zope Python/ZODB application on the same server. What is the recommended way of doing that? Option...
2
by: Petra Chong | last post by:
Hello all I am using Python 2.3 and ZODB (without the rest of Zope) with the following pattern: * One process which writes stuff to a ZODB instance (call it test.db) * Another process which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.