buteo-sync

Attachment 'eds.py'

Download

   1 import sys
   2 from gi.repository import EDataServer
   3 from gi.repository import EBookContacts
   4 from gi.repository import EBook
   5 from gi.repository import GObject
   6 
   7 
   8 def _listSources():
   9     registry  = EDataServer.SourceRegistry.new_sync()
  10     sources = registry.list_sources("Address Book")
  11     for source in sources:
  12         print("%s - %s / %s [%s]" % (source.get_uid(), source.get_display_name(), source.get_parent(), str(source.get_enabled())))
  13 
  14 def _createAggregatorSource():
  15     source = EDataServer.Source.new()
  16     source.set_display_name("AggregatorDisplayName")
  17     source.set_parent("contacts-stub")
  18    
  19     ext = source.get_extension("Address Book")
  20     ext.set_backend_name("aggregator")
  21 
  22     registry  = EDataServer.SourceRegistry.new_sync()
  23     registry.commit_source_sync(source, None)
  24 
  25 def _createSource(sourceName):
  26     source = EDataServer.Source.new()
  27     source.set_display_name(sourceName)
  28     source.set_parent("contacts-stub")
  29     source.set_enabled(False)
  30    
  31     ext = source.get_extension("Address Book")
  32     ext.set_backend_name("local")
  33 
  34     registry = EDataServer.SourceRegistry.new_sync()
  35     registry.commit_source_sync(source, None)
  36 
  37 def _removeSource(sourceUid):
  38     registry  = EDataServer.SourceRegistry.new_sync()
  39     sources = registry.list_sources()
  40     for source in sources:
  41         if source.get_uid() == sourceUid:
  42             source.remove_sync(None)
  43             print("Source removed: %s" % (source.get_display_name()))
  44 
  45 def _enableSource(sourceUid, sourceEnabled):
  46     registry  = EDataServer.SourceRegistry.new_sync()
  47     sources = registry.list_sources()
  48     for source in sources:
  49         if source.get_uid() == sourceUid:
  50             source.set_enabled(sourceEnabled == 'True')
  51             registry = EDataServer.SourceRegistry.new_sync()
  52             registry.commit_source_sync(source, None)
  53             return
  54 
  55 def _startViewOnObjectsAdded(view, objects):
  56     print("Contact added:", objects)
  57 
  58 def _startViewOnProgress(view, percent, message):
  59     print("View progress: %d - %s" % (percent, message))
  60 
  61 def _startViewOnComplete(view, error, mainloop):
  62     print("View complete")
  63     mainloop.quit()
  64 
  65 def _startView(sourceUid):
  66     registry = EDataServer.SourceRegistry.new_sync()
  67     sources = registry.list_sources()
  68     for source in sources:
  69         if source.get_uid() == sourceUid:
  70             mainloop = GObject.MainLoop()
  71 
  72             print("Start view: %s" % source.get_display_name())
  73             client = EBook.BookClient.connect_sync (source, None)
  74             (error, view) = client.get_view_sync ('', None)
  75             view.connect("objects_added", _startViewOnObjectsAdded)
  76             view.connect("progress", _startViewOnProgress)
  77             view.connect("complete", _startViewOnComplete, mainloop)
  78             view.start()
  79 
  80             mainloop.run()
  81             view.stop()
  82             view = None
  83             client = None
  84             return
  85 
  86     
  87         
  88 if __name__ == "__main__":    
  89     print(str(sys.argv))
  90     if '--create-aggregator' in sys.argv:
  91 	    _createAggregatorSource()
  92     if '--list' in sys.argv:
  93         _listSources()
  94     if '--create' in sys.argv:
  95         _createSource(sys.argv[2])
  96     if '--remove' in sys.argv:
  97         _removeSource(sys.argv[2])
  98     if '--enable' in sys.argv:
  99         _enableSource(sys.argv[2], sys.argv[3])       
 100     if '--start-view' in sys.argv:
 101         _startView(sys.argv[2])

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2015-10-14 13:39:01, 3.3 KB) [[attachment:eds.py]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.