SCM

Forum: pg_proboscis 0.9.4

Posted by: James Pye
Date: 2008-01-24 19:08
Summary:pg_proboscis 0.9.4
Project:Python

Bug fixes, yay. Fixes a problem detecting lost connections and generalizes the exception raised by broken pipes and unexpected EOFs from empty reads(ConnectionFailureError). Fixes the dbapi2 module to pass Stuart Bishop's anal DB-API 2.0 tests. Release published on PyPI. To install, do:

easy_install pg_proboscis

Sponsors Ads

Latest News

v1.0.4 Released

James Pye - 2012-06-22 20:59 -

py-postgresql 1.0 Released

James Pye - 2010-03-30 02:40 -

py-postgresql 0.9.3 released

James Pye - 2010-01-07 23:07 -

py-postgresql 0.9.2 released

James Pye - 2009-12-19 01:49 -
Monitor Forum | Start New Thread Start New Thread
RE: new project, getting started troubles [ reply ]
By: James Pye on 2008-03-01 18:04
[forum:1003238]
easy_install has an option:

--always-unzip (-Z) don't install as a zipfile, no matter what


I imagine this could save you a few lines.

Also:

--old-and-unmanageable Try not to use this!

I think when you give this to `setup.py install` it will install the package as directories and files instead of eggs, which I imagine will let you use pdbtrack.

RE: new project, getting started troubles [ reply ]
By: James Pye on 2008-03-01 00:59
[forum:1003237]
> TypeError: 'socket.SSL' object has only read-only attributes (assign to .raw_socket)

ooh. thanks. I'll look into this.
(i'll get back to your other questions later tonight)

RE: new project, getting started troubles [ reply ]
By: James Pye on 2008-03-01 00:55
[forum:1003236]
> [why greentrunk]

GreenTrunk is more explicit. It isolates interface components as opposed to integrating them. Cursors in dbapi are a means to [implicitly] prepare and execute queries *and* "contain" rows(well, get rows, really), whereas in greentrunk these are all [arguably] independent objects. I always felt this to be a more natural way to interface with a database. Calling a query like a function just makes sense. For cursors, why use the traditional fetch*(), when the standard file interface makes so much sense here(read(), seek(), close(), etc)?

On the point of convenience, it's one of my goals for the interface.

for x, in c.query('select i from table'):
print x

dbapi equiv:

cur = c.cursor()
cur.execute('select i from table')
for x, in cur:
print x

Oh, and that's assuming the driver supports the iterator extension to the DBAPI 2.0 spec. Otherwise, you're stuck with fetch*() in a while loop, iirc.

Transaction blocks in DB-API are more or less implicit. I prefer to be explicit. With that, the transaction interface also provides a method for using savepoints:

with c.xact:
# code in transaction block
with c.xact:
# code in savepoint

GT is being designed with convenience, limited by reason of course, and "nature" in mind. [certainly, from my perspective of things].

(yeah, I'm using 1.0 API here)

RE: new project, getting started troubles [ reply ]
By: Steve Newcomb on 2008-02-29 21:06
[forum:1003235]
Having installed the project via the script I just posted, I ran the script:

#!/usr/bin/python2.5
import postgresql.interface.proboscis.greentrunk as gt
import sys
print sys.path
#sys.exit( 0)
con = gt.connector(user = 'srn', host = 'localhost', port = 5432, database = 'testdb')
## "connector" is now lower case.
c=con()

and the result yields an error with the following traceback report:

% /home/srn/pgpy2/test.py
['/home/srn/pgpy2', '/usr/lib/python2.5/site-packages/pg_typical-1.0dev-py2.5.egg', '/usr/lib/python2.5/site-packages/pg_boss-1.0dev-py2.5.egg', '/usr/lib/python2.5/site-packages/pg_proboscis-1.0dev-py2.5.egg', '/usr/lib/python2.5/site-packages/pytz-2007k-py2.5.egg', '/usr/lib/python2.5/site-packages/pg_greentrunk-1.0dev-py2.5.egg', '/usr/lib/python2.5/site-packages/pg_foundation-1.0dev-py2.5.egg', '/usr/lib/python2.5/site-packages/jwp_terminfo-1.0.4-py2.5.egg', '/usr/lib/python2.5/site-packages/pg_slythe-0.2-py2.5.egg', '/usr/lib/python2.5/site-packages/pg_tin-1.0dev-py2.5.egg', '/usr/lib/python2.5/site-packages/pg_pqueue-1.0dev-py2.5-linux-i686.egg', '/usr/lib/python2.5/site-packages/jwp_python_command-1.1-py2.5.egg', '/usr/local/ch-tools', '/usr/lib/python25.zip', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages/Numeric', '/usr/lib/python2.5/site-packages/gst-0.10', '/var/lib/python-support/python2.5', '/var/lib/python-support/python2.5/gtk-2.0', '/usr/lib/site-python']
Traceback (most recent call last):
File "/home/srn/pgpy2/test.py", line 8, in <module>
c=con()
File "build/bdist.linux-i686/egg/postgresql/interface/proboscis/tracenull.py", line 2488, in __call__
File "build/bdist.linux-i686/egg/postgresql/interface/proboscis/tracenull.py", line 2005, in connect
File "build/bdist.linux-i686/egg/postgresql/interface/proboscis/tracenull.py", line 83, in secure_socket
TypeError: 'socket.SSL' object has only read-only attributes (assign to .raw_socket)

...which reminds me to bring up the question: how to make emacs/pdbtrack work with these eggs? I was hoping that by downloading and making the project myself, I would wind up with an installation that would leave the Python code in condition to work with pdb. Instead, it installs eggs, and pdbtrack can't follow. I'm sure there's something simple to know, here; any clue?


RE: new project, getting started troubles [ reply ]
By: Steve Newcomb on 2008-02-29 20:39
[forum:1003234]
The following crude shell script will presumably install the project if you run it as superuser, in the directory ~/pgpy. It downloads the latest name.jwp.terminfo (just fixed yesterday) and installs that, too, after a fashion.

rm -rf ~/pgpy
mkdir -p ~/pgpy
cd ~/pgpy
cvs -d ':pserver:anonymous:@cvs.pgfoundry.org:/cvsroot/python' co pkg
cd pkg
./configure
wget http://pypi.python.org/packages/source/j/jwp_terminfo/jwp_terminfo-1.0.4.tar.gz#md5=37f4c62868183c604d7e8d4550c907a7
tar xzpf jwp_terminfo-1.0.4.tar.gz
cd jwp_terminfo-1.0.4
python2.5 setup.py install
cd ..
python2.5 setup.py install
export PYTHONPATH=~/pgpy/pkg/jwp_terminfo-1.0.4
./testall

RE: new project, getting started troubles [ reply ]
By: Steve Newcomb on 2008-02-29 16:23
[forum:1003233]
You gave reasons (popularity, establishment) for using DB-API 2.0, but you didn't argue for the greentrunk side. Since you've made a noteworthy personal investment in the latter, it would be interesting to know your motivation. (Full disclosure: personally, I've been attracted to greentrunk on a pure hunch, I guess largely because I like the way you write (very presentably indeed), and because somewhere you wrote "significant convenience for the Python programmer" or something like that. But I would prefer to have explicable reasons for selecting an underdog approach.)

RE: new project, getting started troubles [ reply ]
By: James Pye on 2008-02-29 05:00
[forum:1003232]
> #!/usr/bin/python2.5
> import postgresql.interface.proboscis.greentrunk as gt
> con = gt.Connector(user = 'srn', host = 'localhost', port = 5432, database = 'testdb')
> c=con()
>
> ... I wonder, what now? How does gt.Connector, con, con(), or c give access to the things enumerated in the "Connection API" document, which doesn't mention Connector? I'm sure the answer is too obvious to mention, but it's not obvious to me, unfortunately.

Okay. So ``c`` in the above script is your Connection. That provides the connection API. For the most part, you'll be preparing individual queries with "Query":

q = c.Query("SELECT $1::int")
p = q(900)
p.read()
[(900,)]

The basic idea is, you prepare a query. The query object provides a function-like interface. When you invoke the query, it creates a cursor that you can use like a file object that reads tuples instead of bytes. (Notably, not all file interfaces(seek), are supported).

> make xhtml
/home/srn/pgpy2/doc/src/appendixes/maiden_codes.py work/in/maiden_codes.xml
> Traceback (most recent call last):
> File "/home/srn/pgpy2/doc/src/appendixes/maiden_codes.py", line 6, in ?
> import postgresql.exception.maiden.code as pgxcodes
> ImportError: No module named postgresql.exception.maiden.code
> make: *** [work/in/maiden_codes.xml] Error 1

The documentation is being completely refactored. I'm going to rely on pydoc much more heavily in the future, so this(doc) module is good as dead.


> File "build/bdist.linux-i686/egg/name/jwp/terminfo.py", line 88, in <module>
> NameError: name 'x' is not defined

Fixed. Thanks.

> (1) Should I be committing to pg_proboscis/greentrunk, at least for my experiments, or should I be looking elsewhere?

If you use the DB-API 2.0 interface you'll be fairly safe to switch to other drivers(psycopg2, for instance). [paramstyle might burn you a little, but it'll be easy enough to do substitutions]
However, if you don't like DB-API 2.0, I'm afraid you might be stuck with this, as it's pretty much the only PostgreSQL driver that I know of that attempts a stark contrast from the DBAPI2.0 PEP. ;)

psycopg2 is probably the most popular driver. If you want something more established or widely used, it's probably the driver for you.


> (2) Any working applications to look at?

Hrm. Well, I have some unittests in pg_greentrunk(`ip` module in CVS; postgresql.protocol.greentrunk.test.*). If you are looking for applications written by people other than me, I'm afraid I know of none. =\


> (3) How best to set myself up for the long haul on this project? I'm running Debian Linux. I have devoted a machine to this project, and I can share its desktop, if that's helpful.

It looks like you've made a good start. I use the `pkg` module to manage the many CVS modules. I imagine you might find that easier than running all those checkouts. Tho, it lacks any proper documentation atm(this inspires me to fill out a README).

The mailing list would be a good place to field questions.

new project, getting started troubles [ reply ]
By: Steve Newcomb on 2008-02-28 15:56
[forum:1003230]
I'm making a serious attempt to use pg_proboscis in my long quest to show whether and how it's reasonable to manage diverse subject proxies (ISO 13250-5 Topic Maps Reference Model). Maybe pg_proboscis isn't ready for such an exercise; it's hard for me to tell. Advice pro and/or con would be welcome.

Are there any examples of applications that use pg_proboscis, whose source codes I can examine and learn from? I did find the "Connection API" html document, which is certainly tantalizing. I feel my ignorance acutely when, having read this document and having got the egg-based installation of pg_proboscis 0.9.4 to work, and having made a script that apparently works as far as it goes:

#!/usr/bin/python2.5
import postgresql.interface.proboscis.greentrunk as gt
con = gt.Connector(user = 'srn', host = 'localhost', port = 5432, database = 'testdb')
c=con()

... I wonder, what now? How does gt.Connector, con, con(), or c give access to the things enumerated in the "Connection API" document, which doesn't mention Connector? I'm sure the answer is too obvious to mention, but it's not obvious to me, unfortunately.

I've found that pdbtrack in emacs doesn't work with the egg-based installation. In the hope of giving myself a more helpful development environment, I downloaded the project via cvs -d ':pserver:anonymous:@cvs.pgfoundry.org:/cvsroot/python'
but I was not able to install a working system that way. Here's what happened:

ctl/setup.py worked OK.

fe/setup.py script failed at first, but succeeded later, after other stuff had been installed.

ip/setup.py script failed at first, but succeeded later, after other stuff had been installed.


running make in doc (after altering the makefile so Gnu make could understand it (I replaced 3 instances of the != operator)) failed:

make xhtml
/home/srn/pgpy2/doc/src/appendixes/maiden_codes.py work/in/maiden_codes.xml
Traceback (most recent call last):
File "/home/srn/pgpy2/doc/src/appendixes/maiden_codes.py", line 6, in ?
import postgresql.exception.maiden.code as pgxcodes
ImportError: No module named postgresql.exception.maiden.code
make: *** [work/in/maiden_codes.xml] Error 1

ip/setup.py worked OK, apparently.

lo/setup.py worked OK, apparently

pkg/setup.py failed: Traceback (most recent call last):
File "setup.py", line 11, in <module>
import name.jwp.terminfo as ti
File "build/bdist.linux-i686/egg/name/jwp/terminfo.py", line 88, in <module>
NameError: name 'x' is not defined

pq/setup.py worked OK, apparently.

rc/setup.py worked OK.

tin/setup.py worked ok.

typ/setup.py worked ok.

web/sync didn't work because I don't have the password.

be/setup.py failed: src/heaptuple.c: In function 'tup_length':
src/heaptuple.c:291: error: 'HeapTupleHeaderData' has no member named 't_natts'
src/heaptuple.c: In function 'tup_item':
src/heaptuple.c:305: error: 'HeapTupleHeaderData' has no member named 't_natts'
src/heaptuple.c: In function 'tup_repr':
src/heaptuple.c:526: error: 'HeapTupleHeaderData' has no member named 't_natts'
error: command 'gcc' failed with exit status 1

It would be nice to know how to get the rest of the way to a pg_proboscis that works, that supports pdbtrack, and that I can tweak if necessary.

To sum up, I'm asking 3 things:

(1) Should I be committing to pg_proboscis/greentrunk, at least for my experiments, or should I be looking elsewhere?

(2) Any working applications to look at?

(3) How best to set myself up for the long haul on this project? I'm running Debian Linux. I have devoted a machine to this project, and I can share its desktop, if that's helpful.

Steve Newcomb
+1 910 363 4032






Powered By FusionForge