[PEAK] bulletins example OF DOOM

Stephen Waterbury golux at comcast.net
Fri Apr 9 03:29:59 EDT 2004


Phillip J. Eby wrote:
> At 02:04 PM 4/8/04 -0400, Stephen C. Waterbury wrote:

>> How about 'pypgsql://...' ?  (Guess I'd have to create a new
>> entry in names config ...?)
> 
> Yes, although you can also do it from inside of the 'bulletins' file, e.g.:
> 
> [peak.naming.schemes]
> pypgsql = "path.to.your.URL.class"
> 
> And then you'll need to implement a URL class and a connection class; 
> they should be fairly easy to crib from the many examples in 
> peak.storage.SQL.  Feel free to contribute your successful result.  :)

I copied bulletins into my sandbox to play with.  I'm attaching
my new 'bulletins' file.  I went ahead and created a 'bulletins'
database using PostgreSQL's createdb from the command line --
was the 'peak runIni bulletins createdb' supposed to do that?
Looking at the code it appears that it just runs the ddl --
i.e., creates the tables -- but for a PostgreSQL user, the
name of the command is somewhat confusing, since the PostgreSQL
command 'createdb' creates the database (i.e. an empty one)
rather than the tables ... maybe the bulletins command should
be called 'createtables' or something.

I modified GenericSQL_URL to include a 'pypgsql' scheme
(see attached version of SQL.py) and added a pyPgSQLConnection
(just a copy of the PsycopgConnection with the DRIVER changed
to "pyPgSQL.PgSQL" -- probably close enough for now).  Since
I use PostgreSQL on a domain socket, there is no 'host', so I
changed the server attribute to just 'Field' instead of
'RequiredField' (which IMO seems more correct, since 'host' is
an optional connection parameter according to the DBAPI spec).

Then I messed around with 'syntax' (somewhat blindly ...
oh, okay, totally blindly :) until I got the traceback I've
included below.  Seems to me like this should work, BUT NO!
Ach.  I feel like I'm really close but still missing something.

As you can see in my bulletins file, I specified the
database URL as 'pypgsql:///bulletins'.  This seemed reasonable
because if I do pyPgSQL interactively, I can connect like:

[waterbug at bigboote bulletins]$ python
Python 2.3.3 (#1, Dec 21 2003, 00:52:10)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> from pyPgSQL import PgSQL
 >>> conn = PgSQL.connect(database='bulletins')
 >>>

... and all is well.  Maybe the GenericSQL_URL scheme doesn't work
with domain sockets?  (I never let PostgreSQL listen on a real
socket; I'm too paranoid.  :)

Anyway, here's my best traceback, and now it's bedtime ...

[waterbug at bigboote bulletins]$ peak runIni bulletins createdb
Apr 09 02:55:29 bigboote bulletins.app[1124]: Creating 
pypgsql:///bulletins using DDL from 
/home/waterbug/sandbox/PEAKsb/bulletins/src/bulletins/sqlite-ddl.sql
Traceback (most recent call last):
   File "/usr/local/bin/peak", line 4, in ?
     commands.runMain( commands.Bootstrap )
   File 
"/usr/local/lib/python2.3/site-packages/peak/running/commands.py", line 
70, in runMain
     result = factory().run()
   File 
"/usr/local/lib/python2.3/site-packages/peak/running/commands.py", line 
211, in run
     return self._run() or 0
   File 
"/home/waterbug/sandbox/PEAKsb/bulletins/src/bulletins/commands.py", 
line 34, in _run
     self.db(ddl)
   File 
"/usr/local/lib/python2.3/site-packages/peak/storage/connections.py", 
line 265, in __call__
     cursor.execute(*args)
   File "/usr/local/lib/python2.3/site-packages/peak/storage/SQL.py", 
line 144, in execute
     self.logger.exception(
   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 112, 
in _once.BaseDescriptor.__get__
   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 100, 
in _once.__get__
   File 
"/usr/local/lib/python2.3/site-packages/peak/binding/components.py", 
line 524, in computeValue
     return self.targetName.findComponent(obj, self.default)
   File "/usr/local/lib/python2.3/site-packages/peak/naming/names.py", 
line 198, in findComponent
     return lookup(
   File "/usr/local/lib/python2.3/site-packages/peak/naming/api.py", 
line 53, in lookup
     return InitialContext(parent, **options).lookup(name,default)
   File "/usr/local/lib/python2.3/site-packages/peak/naming/api.py", 
line 34, in InitialContext
     return spi.getInitialContext(parent, componentName, **options)
   File "/usr/local/lib/python2.3/site-packages/peak/naming/spi.py", 
line 63, in getInitialContext
     return factory(parentComponent, componentName, **options)
   File 
"/usr/local/lib/python2.3/site-packages/peak/binding/components.py", 
line 758, in __init__
     setattr(self,k,v)
   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 52, 
in _once.BaseDescriptor.__set__
   File "/usr/local/lib/python2.3/site-packages/peak/binding/once.py", 
line 406, in onSet
     suggestParentComponent(obj, attrName, value)
   File "/usr/local/lib/python2.3/site-packages/peak/binding/once.py", 
line 197, in suggestParentComponent
     ob = adapt(child,IAttachable,None)
   File "C:\cygwin\home\pje\PyProtocols\src/protocols/_speedups.pyx", 
line 161, in _speedups.adapt
   File "/usr/local/lib/python2.3/site-packages/peak/storage/SQL.py", 
line 75, in __getattr__
     return getattr(self._cursor,attr)
   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 112, 
in _once.BaseDescriptor.__get__
   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 100, 
in _once.__get__
   File "/usr/local/lib/python2.3/site-packages/peak/binding/once.py", 
line 498, in <lambda>
     f = lambda s,d,a: func(s)
   File "/usr/local/lib/python2.3/site-packages/peak/storage/SQL.py", 
line 50, in <lambda>
     _cursor = binding.Make(lambda self: self._conn.cursor())
   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 112, 
in _once.BaseDescriptor.__get__
   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 100, 
in _once.__get__
   File 
"/usr/local/lib/python2.3/site-packages/peak/binding/components.py", 
line 524, in computeValue
     return self.targetName.findComponent(obj, self.default)
   File 
"/usr/local/lib/python2.3/site-packages/peak/binding/components.py", 
line 308, in findComponent
     else:   ob = getattr(ob,attr)
   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 112, 
in _once.BaseDescriptor.__get__
   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 100, 
in _once.__get__
   File "/usr/local/lib/python2.3/site-packages/peak/binding/once.py", 
line 498, in <lambda>
     f = lambda s,d,a: func(s)
   File 
"/usr/local/lib/python2.3/site-packages/peak/storage/connections.py", 
line 172, in <lambda>
     connection = binding.Make(lambda self: self._open())
   File "/usr/local/lib/python2.3/site-packages/peak/storage/SQL.py", 
line 464, in _open
     return self.API.connect(
   File "/usr/local/lib/python2.3/site-packages/pyPgSQL/PgSQL.py", line 
2211, in connect
     return Connection(connInfo, client_encoding, unicode_results)
   File "/usr/local/lib/python2.3/site-packages/pyPgSQL/PgSQL.py", line 
2331, in __init__
     raise DatabaseError, m
libpq.DatabaseError: could not translate host name "dbname=bulletins" to 
address: Name or service not known

-------------- next part --------------
#!/usr/local/bin/peak runIni

[Load Settings From]
# This loads the general program settings - don't change:
file = config.fileNearModule('bulletins', 'bulletins.ini')

# From this point on, you can modify as appropriate:

[peak.naming.schemes]
pypgsql = 'peak.storage.SQL.GenericSQL_URL'

[bulletins]
databaseURL = 'pypgsql:///bulletins'
databaseDDL = config.fileNearModule('bulletins', 'sqlite-ddl.sql')

[peak.logs]
# Set default logging to stderr, DEBUG level
* = logs.LogStream(stream=importString('sys.stderr'), levelName='DEBUG')

-------------- next part --------------
A non-text attachment was scrubbed...
Name: SQL.py
Type: application/python
Size: 19175 bytes
Desc: not available
Url : http://www.eby-sarna.com/pipermail/peak/attachments/20040409/c2046eb1/SQL.bin


More information about the PEAK mailing list