Re: Any ideas why Axiom is acting odd?

Robert Gravina <[email protected]> Wed, 28 Jun 2006 12:57:45 +0900
Newsgroups gmane.comp.python.quotient.dev
Message-ID <[email protected]>
>> No need to apologize for opening tickets.  I've closed the one you  
>> reopened, and exarkun explained what was going on in the one that  
>> you posted.  Although axiom does work properly, there is an issue  
>> here - it is frequently confusing to people trying out the  
>> examples that Axiom is unhappy with __main__.
>>
>

I tried what you suggested about moving all Items into their own  
module and importing them into main, but the error still persists.  
I've modified the libary.py example (attached) in this way, and still  
get this traceback:

PowerMoko:~/temp rgravina$ python library.py
creating new library
The Dark Tower, Book 7 in library
Guns, Germs, and Steel: The Fates of Human Societies in library
The Lions of al-Rassan in library
Heart of Darkness in library
***
Lending Guns, Germs, and Steel: The Fates of Human Societies to Bob
Traceback (most recent call last):
   File "library.py", line 33, in ?
     s.transact(main, s)
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/axiom/store.py", line 971, in transact
     result = f(*a, **k)
   File "library.py", line 18, in main
     ll.shuffleLending()
   File "/Users/rgravina/temp/library_items.py", line 84, in  
shuffleLending
     book.lentTo = self.getBorrower(borrower)
   File "/Users/rgravina/temp/library_items.py", line 49, in getBorrower
     Borrower.name == name):
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/axiom/store.py", line 239, in __iter__
     sqlResults = self._runQuery('SELECT', self._queryTarget)
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/axiom/store.py", line 220, in _runQuery
     sqlstr, sqlargs = self._sqlAndArgs(verb, subject)
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/axiom/store.py", line 181, in _sqlAndArgs
     self.store.getTypeID(t) # getTypeID is what currently does table
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/axiom/store.py", line 1094, in getTypeID
     self._startup()
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/axiom/store.py", line 593, in _startup
     namedAny(module)
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/twisted/python/reflect.py", line 346, in  
namedAny
     names = name.split('.')
AttributeError: 'NoneType' object has no attribute 'split'
library_items.py (text/x-python-script, 2.5 KB)
import random
from axiom.item import Item
from epsilon import extime
from axiom.attributes import text, timestamp, reference, integer, AND, OR


_d = extime.Time.fromISO8601TimeAndDate

_books = [
    (u'Heart of Darkness', u'Joseph Conrad', u'0486264645', 80, _d('1990-07-01T00:00:00.000001')),
    (u'The Dark Tower, Book 7', u'Stephen King', u'1880418622', 864, _d('2004-11-21T00:00:00.000001')),
    (u'Guns, Germs, and Steel: The Fates of Human Societies', u'Jared Diamond', u'0393317552', 480, _d('1999-04-01T00:00:00.000001')),
    (u'The Lions of al-Rassan', u'Guy Gavriel Kay', u'0060733497', 528, _d('2005-06-28T00:00:00.000001')),
    ]

_borrowers = [u'Anne', u'Bob', u'Carol', u'Dave']


class Borrower(Item):
    typeName = 'borrower'
    schemaVersion = 1
    name = text(indexed=True)

class Book(Item):
    typeName = 'book'
    schemaVersion = 1

    title = text()
    author = text()
    isbn = text()
    pages = integer()
    datePublished = timestamp()

    lentTo = reference()
    library = reference()

class LendingLibrary(Item):
    typeName = 'lending_library'
    schemaVersion = 1

    name = text()

    def books(self):
        return self.store.query(Book,
                                Book.library == self)

    def getBorrower(self, name):
        for b in self.store.query(Borrower,
                                  Borrower.name == name):
            return b
        b = Borrower(name=name,
                     store=self.store)
        return b

    def initialize(self):
        for title, author, isbn, pages, published in _books:
            b = Book(
                title=title,
                author=author,
                isbn=isbn,
                pages=pages,
                datePublished=published,
                library=self,
                store=self.store)


    def displayBooks(self):
        for book in self.books():
            print book.title,
            if book.lentTo is not None:
                print 'lent to', '['+book.lentTo.name+']'
            else:
                print 'in library'

    def shuffleLending(self):
        for book in self.books():
            if book.lentTo is not None:
                print book.lentTo.name, 'returned', book.title
                book.lentTo = None
        for book in self.books():
            if random.choice([True, False]):
                borrower = random.choice(_borrowers)
                print 'Lending', book.title, 'to', borrower
                book.lentTo = self.getBorrower(borrower)
library.py (text/x-python-script, 783 B)
from axiom.store import Store
from library_items import *


def main(s):
    for ll in s.query(LendingLibrary):
        print 'found existing library'
        break
    else:
        print 'creating new library'
        ll = LendingLibrary(store=s)
        ll.initialize()
    ll.displayBooks()
    print '***'
    ll.shuffleLending()
    print '---'
    ll.displayBooks()
    print '***'
    ll.shuffleLending()
    print '---'

    print s.count(Book, AND (Book.author == u'Stephen King',
                             Book.title == u'The Lions of al-Rassan'))
    print s.count(Book, OR (Book.author == u'Stephen King',
                            Book.title == u'The Lions of al-Rassan'))


if __name__ == '__main__':
    s = Store('testdb')
    s.transact(main, s)
    s.close()