Merge lp://qastaging/~sil/desktopcouch/glib-callback-for-changes into lp://qastaging/desktopcouch

Proposed by Stuart Langridge
Status: Work in progress
Proposed branch: lp://qastaging/~sil/desktopcouch/glib-callback-for-changes
Merge into: lp://qastaging/desktopcouch
Diff against target: 166 lines (+136/-1)
2 files modified
desktopcouch/records/server.py (+97/-1)
desktopcouch/records/tests/test_server.py (+39/-0)
To merge this branch: bzr merge lp://qastaging/~sil/desktopcouch/glib-callback-for-changes
Reviewer Review Type Date Requested Status
dobey (community) Needs Fixing
Vincenzo Di Somma (community) Needs Fixing
Eric Casteleijn (community) Approve
Review via email: mp+40415@code.qastaging.launchpad.net

Commit message

An implementation of glib_callback_for_changes which allows a glib program to attach a callback which is called whenever a change happens in a desktopcouch database.

Description of the change

An implementation of glib_callback_for_changes which allows a glib program to attach a callback which is called whenever a change happens in a desktopcouch database.

Use in a glib program:

def my_callback(data):
    print "a record with id %s was changed" % data["id"]
db = CouchDatabase("whatever")
db.glib_callback_for_changes(my_callback)
gtk.main()

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

I like this functionality, but would like it better if it weren't a member of CouchDatabase (which I would like to remain agnostic of anything platform specific.) My intuition is that it doesn't need to be, since it makes relatively little use of self. I would probably strive for a function called something like 'add_glib_callback' that takes a database object and a callback function.

In addition I'd like a more generic callback function which knows nothing about glib, which could then be used by the glib one.

I know little of glib, so I don't know how realistic these preferences are.

Revision history for this message
Eric Casteleijn (thisfred) wrote :

In addition, I get an import error.

===============================================================================
[ERROR]: desktopcouch.records.tests.test_server.TestCouchDatabase.test_glib_callback_for_changes

Traceback (most recent call last):
Failure: testtools.testresult.real._StringException: Text attachment: traceback
------------
Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/testtools/runtest.py", line 128, in _run_user
    return fn(*args)
  File "/usr/lib/python2.6/dist-packages/testtools/testcase.py", line 368, in _run_test_method
    testMethod()
  File "/home/eric/canonical/desktopcouch/glib-callback-for-changes/desktopcouch/records/tests/test_server.py", line 705, in test_glib_callback_for_changes
    self.database.glib_callback_for_changes(callback)
  File "/home/eric/canonical/desktopcouch/glib-callback-for-changes/desktopcouch/records/server.py", line 121, in glib_callback_for_changes
    from gi.repository import Soup
ImportError: cannot import name Soup

review: Needs Fixing
Revision history for this message
Eric Casteleijn (thisfred) wrote :

After installing gir1.0-soup-2.4 (which points to why I'd like this somewhere separate, since I don't want that as a dependency of the library,) the tests pass, but:

== Pylint notices ==
************* Module desktopcouch.records.server
C0301:179: Line too long (81/80)
R0914:108:CouchDatabase.glib_callback_for_changes: Too many local variables (26/15)
E0611:123:CouchDatabase.glib_callback_for_changes: No name 'repository' in module 'gi'
C0111:129:CouchDatabase.glib_callback_for_changes.got_chunk: Missing docstring
W0613:129:CouchDatabase.glib_callback_for_changes.got_chunk: Unused argument 'msg'
C0111:152:CouchDatabase.glib_callback_for_changes.complete: Missing docstring
W0613:152:CouchDatabase.glib_callback_for_changes.complete: Unused argument 'args'
E1103:176:CouchDatabase.glib_callback_for_changes: Instance of 'Http' has no 'oauth_data' member (but some types could not be inferred)
W0612:180:CouchDatabase.glib_callback_for_changes: Unused variable 'fragment'
W0612:180:CouchDatabase.glib_callback_for_changes: Unused variable 'netloc'
W0612:180:CouchDatabase.glib_callback_for_changes: Unused variable 'path'
W0612:125:CouchDatabase.glib_callback_for_changes: Unused variable 'urllib'
W0612:180:CouchDatabase.glib_callback_for_changes: Unused variable 'schema'
W0201:159:CouchDatabase.glib_callback_for_changes: Attribute '_soupsessions' defined outside __init__
************* Module desktopcouch.records.tests.test_server
W0232:699:TestCouchDatabase.test_glib_callback_for_changes.PythonCannotSetNonGlobalOuterScopeVars: Class has no __init__ method
C0111:699:TestCouchDatabase.test_glib_callback_for_changes.PythonCannotSetNonGlobalOuterScopeVars: Missing docstring
C0321:699:TestCouchDatabase.test_glib_callback_for_changes.PythonCannotSetNonGlobalOuterScopeVars: More than one statement on a single line
R0903:699:TestCouchDatabase.test_glib_callback_for_changes.PythonCannotSetNonGlobalOuterScopeVars: Too few public methods (0/2)
W0201:705:TestCouchDatabase.test_glib_callback_for_changes.callback: Attribute 'success' defined outside __init__
C0111:704:TestCouchDatabase.test_glib_callback_for_changes.callback: Missing docstring
W0613:704:TestCouchDatabase.test_glib_callback_for_changes.callback: Unused argument 'data'
C0111:707:TestCouchDatabase.test_glib_callback_for_changes.timeout: Missing docstring
C0111:709:TestCouchDatabase.test_glib_callback_for_changes.insert_record: Missing docstring

Revision history for this message
Stuart Langridge (sil) wrote :

You'll note that the glib callback function imports the Python gir stuff whe nit's called, not at the top level in the module, precisely so that using gir is not a dependency *unless you use glib_callback_for_changes*. The apt dependency system isn't set up all that well for this; putting this one function in a package all by itself would be daft. I suggest that the resulting package Suggests python-gir-soup as per http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.

The function delves into interior details of CouchDatabase in order to compute a _changes URL. Something external to CouchDatabase should not be using this sort of internal API; it's an implementation detail which we may change.

You're right about the pylint stuff, although I don't understand why I didn't get told the same things when running the tests? What am I doing wrong there?

Revision history for this message
Eric Casteleijn (thisfred) wrote :

> You'll note that the glib callback function imports the Python gir stuff whe
> nit's called, not at the top level in the module, precisely so that using gir
> is not a dependency *unless you use glib_callback_for_changes*. The apt
> dependency system isn't set up all that well for this; putting this one
> function in a package all by itself would be daft. I suggest that the
> resulting package Suggests python-gir-soup as per http://www.debian.org/doc
> /debian-policy/ch-relationships.html#s-binarydeps.

Yeah, I really hate having a function that will break as soon as you call it, though. I don't suggest having this in a separate package, but having it as a top level function won't show it in introspection of CouchDatabase, and allows us to move it into desktopcouch.application, where I think the dependency (or suggestion) is less of a problem.

> The function delves into interior details of CouchDatabase in order to compute
> a _changes URL. Something external to CouchDatabase should not be using this
> sort of internal API; it's an implementation detail which we may change.

If so we can reimplement the function, I don't consider it as big a problem as having a broken method on our most central class.

> You're right about the pylint stuff, although I don't understand why I didn't
> get told the same things when running the tests? What am I doing wrong there?

The preferred way to run the tests now is ./runtests.py which takes care of the python path and everything else. It will run lint on the changed files only unless there are no local changes, and then it will lint every file that was changed in the branch, so if you want to lint the whole branch, make sure all your changes are committed.

201. By Stuart Langridge

bow and scrape before the almighty god pylint

202. By Stuart Langridge

merge from trunk

Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks good now.

review: Approve
203. By Stuart Langridge

correct enable message

Revision history for this message
Vincenzo Di Somma (vds) wrote :

I might be wrong but in Lucid I don't find a package to satisfy the required dependency and the tests break.

===============================================================================
[ERROR]: desktopcouch.records.tests.test_server.TestCouchDatabase.test_glib_callback_for_changes

Traceback (most recent call last):
Failure: testtools.testresult.real._StringException: Text attachment: traceback
------------
Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/testtools/runtest.py", line 128, in _run_user
    return fn(*args)
  File "/usr/lib/python2.6/dist-packages/testtools/testcase.py", line 368, in _run_test_method
    testMethod()
  File "/home/vds/canonical/desktopcouch/glib-callback-for-changes/desktopcouch/records/tests/test_server.py", line 725, in test_glib_callback_for_changes
    self.database.glib_callback_for_changes(callback)
  File "/home/vds/canonical/desktopcouch/glib-callback-for-changes/desktopcouch/records/server.py", line 126, in glib_callback_for_changes
    from gi.repository import Soup # pylint: disable=E0611
ImportError: No module named gi.repository

review: Needs Fixing
Revision history for this message
dobey (dobey) wrote :

Also, please use timeout_add_seconds(X) instead of timeout_add(X * 1000), as it is the preferred way to do timeouts that large.

review: Needs Fixing

Unmerged revisions

203. By Stuart Langridge

correct enable message

202. By Stuart Langridge

merge from trunk

201. By Stuart Langridge

bow and scrape before the almighty god pylint

200. By Stuart Langridge

An implementation of glib_callback_for_changes which allows a glib program to attach a callback which is called whenever a change happens in a desktopcouch database

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches