~dobey/gwibber/gwibber-keyring-unthreaded

« back to all changes in this revision

Viewing changes to gwibber/microblog/util/couch.py

  • Committer: Ken VanDine
  • Date: 2010-03-23 18:21:34 UTC
  • mfrom: (612.1.1 gwibber)
  • Revision ID: ken.vandine@canonical.com-20100323182134-g16cnzcrdokbtlnw
Use the desktopcouch API for excluding the DB and handle errors

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import desktopcouch, pycurl, oauth, threading, urllib, re, json
5
5
from desktopcouch.records.server import CouchDatabase
6
6
from desktopcouch.records.record import Record as CouchRecord
 
7
from desktopcouch.replication_services import ubuntuone
7
8
from couchdb.design import ViewDefinition as CouchView
8
9
 
9
10
OAUTH_DATA = desktopcouch.local_files.get_oauth_tokens()
110
111
  CouchView.sync_many(database.db, views)
111
112
 
112
113
def exclude_databases(names):
113
 
  db = CouchDatabase("management", create=True)
114
 
  if db.view_exists("ubuntu_one_pair_record", "ubuntu_one_pair_record"):
115
 
    for x in db.execute_view("ubuntu_one_pair_record"):
116
 
      record = db.get_record(x.id)
117
 
      values = dict(record.items())
118
 
      values["excluded_names"] = list(set(values.get("excluded_names", [])) | set(names))
119
 
      db.update_fields(x.id, values)
 
114
  try:  
 
115
    excl = ubuntuone.ReplicationExclusion()
 
116
  except ValueError:
 
117
    excl = None   # We are not an Ubuntu One user.
 
118
 
 
119
  if excl is not None:
 
120
    if "ubuntuone" not in excl.all_exclusions():
 
121
      for name in names:
 
122
        excl.exclude(name)
 
123