Merge lp:~renatofilho/demo-assets/fix-manage-address-books into lp:demo-assets

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 41
Merged at revision: 41
Proposed branch: lp:~renatofilho/demo-assets/fix-manage-address-books
Merge into: lp:demo-assets
Diff against target: 125 lines (+27/-20)
1 file modified
usr/bin/manage-address-books (+27/-20)
To merge this branch: bzr merge lp:~renatofilho/demo-assets/fix-manage-address-books
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+172434@code.launchpad.net

Commit message

Fixed manage-address-books to work with new EDS 3.8.x API.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good and works as expected.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'usr/bin/manage-address-books'
2--- usr/bin/manage-address-books 2013-05-23 20:29:13 +0000
3+++ usr/bin/manage-address-books 2013-07-01 22:54:26 +0000
4@@ -37,7 +37,7 @@
5 import os.path
6 import base64
7
8-from gi.repository import EBook, EDataServer, Gio, GLib
9+from gi.repository import EBook, EBookContacts, EDataServer, Gio, GLib
10
11 address_book_name = "completed-contacts"
12 source_uid = None
13@@ -93,7 +93,7 @@
14 parts = os.path.splitext(filename)[0].split("_")
15 if int(parts[-1]) == int(facebook_id):
16 f = open("/usr/share/demo-assets/contacts-data/avatars/" + filename, 'rb')
17- p = EBook.ContactPhoto.new()
18+ p = EBookContacts.ContactPhoto.new()
19 p.set_mime_type("image/jpeg")
20 p.set_inlined(f.read())
21 contact.set_property("photo", p)
22@@ -113,7 +113,7 @@
23 client = EBook.BookClient.new(source_match)
24 client.open_sync(False, None)
25
26- query = EBook.book_query_any_field_contains('')
27+ query = EBookContacts.BookQuery.any_field_contains('')
28 success, results = client.get_contacts_sync(query.to_string(), None)
29 if(success and len(results) > 0):
30 print ("Our target addressbook seems to be populated, please first delete contacts before repopulating")
31@@ -122,27 +122,27 @@
32 print("just about to create contacts")
33
34 for c in contacts:
35- vcard = EBook.VCard.new_from_string("BEGIN:VCARD\r\nVERSION:2.1\r\nADR;HOME:{};{};{};{};{};{};{}\r\nEND:VCARD".format(c["poBox"], c["extended address"], c["street address"], c["locality"], c["region"], c["postal code"], c["country name"]))
36+ vcard = EBookContacts.VCard.new_from_string("BEGIN:VCARD\r\nVERSION:2.1\r\nADR;HOME:{};{};{};{};{};{};{}\r\nEND:VCARD".format(c["poBox"], c["extended address"], c["street address"], c["locality"], c["region"], c["postal code"], c["country name"]))
37
38 # There will always be a name
39 # put it in the link field for the other contacts
40- vcard_attr = EBook.VCardAttribute.new('social-networking-attributes', 'X-FOLKS-WEB-SERVICES-IDS')
41- param = EBook.VCardAttributeParam.new('remote-full-name')
42+ vcard_attr = EBookContacts.VCardAttribute.new('social-networking-attributes', 'X-FOLKS-WEB-SERVICES-IDS')
43+ param = EBookContacts.VCardAttributeParam.new('remote-full-name')
44 name = c["Name"]
45 param.add_value(name)
46 vcard_attr.add_param(param);
47 if ("FacebookID" in list(c.keys())):
48- param = EBook.VCardAttributeParam.new('facebook-id')
49+ param = EBookContacts.VCardAttributeParam.new('facebook-id')
50 param.add_value(c["FacebookID"])
51 vcard_attr.add_param(param)
52 vcard.add_attribute(vcard_attr)
53
54 if c["Favorite"] == "1":
55- vcard_attr = EBook.VCardAttribute.new('', 'X-FOLKS-FAVOURITE')
56+ vcard_attr = EBookContacts.VCardAttribute.new('', 'X-FOLKS-FAVOURITE')
57 vcard_attr.add_value("true")
58 vcard.add_attribute(vcard_attr)
59
60- contact = EBook.Contact.new_from_vcard(vcard.to_string(EBook.VCardFormat(1)))
61+ contact = EBookContacts.Contact.new_from_vcard(vcard.to_string(EBookContacts.VCardFormat(1)))
62
63 for key,value in list(c.items()):
64 if key == "Name":
65@@ -169,25 +169,33 @@
66 client.add_contact_sync(contact, None)
67 ml.quit()
68
69-def delete_contacts(source):
70- client = EBook.BookClient.new(source)
71+def delete_contacts(source_uid):
72+ print("Delete contacts")
73+ source_match = source_registry.ref_source(source_uid)
74+
75+ if(source_match is None):
76+ print(("No source match from reg %s", source_uid))
77+ sys.exit()
78+
79+ client = EBook.BookClient.new(source_match)
80 client.open_sync(False, None)
81- if client is None:
82- print("cannot create bookclient!")
83- sys.exit()
84- query = EBook.book_query_any_field_contains('')
85+
86+ query = EBookContacts.BookQuery.any_field_contains('')
87 success, results = client.get_contacts_sync(query.to_string(), None)
88 if not success:
89 log.error('EDS search for delete all contacts failed')
90 sys.exit()
91+
92 print(('Found {} contacts to delete'.format(len(results))))
93 for contact in results:
94 print(('Deleting contact {}'.format(
95 contact.get_property('full-name'))))
96 client.remove_contact_sync(contact, None)
97
98-def create(ml):
99- source_uid = get_source(address_book_name)
100+def create(a_book_name, ml):
101+ book = address_book_name if a_book_name is None else a_book_name
102+ print("create contact on book {}".format(book))
103+ source_uid = get_source(book)
104 prep_data()
105 GLib.timeout_add_seconds(2, create_contacts, source_uid, ml)
106
107@@ -195,8 +203,7 @@
108 book = address_book_name if a_book_name is None else a_book_name
109 source_uid = get_source(book)
110 print("delete book {}".format(book))
111- source_match = source_registry.ref_source(source_uid)
112- delete_contacts(source_match)
113+ delete_contacts(source_uid)
114 ml.quit()
115
116 action = sys.argv[1]
117@@ -215,7 +222,7 @@
118 GLib.idle_add(delete, book_name, ml)
119
120 if action == "create":
121- GLib.idle_add(create, ml)
122+ GLib.idle_add(create, book_name, ml)
123
124 if action == "test":
125 find_and_set_image_path(None, None, "test")

Subscribers

People subscribed via source and target branches