~ken-vandine/unity-scope-gdrive/0.3

« back to all changes in this revision

Viewing changes to debian/patches/py3.patch

  • Committer: Ken VanDine
  • Date: 2012-08-23 19:03:57 UTC
  • mfrom: (5.3.4 python3)
  • Revision ID: ken.vandine@canonical.com-20120823190357-ak7uw6i4uspw7ioi
* debian/control
  - updated depends for python3 port

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
=== modified file 'unity-scope-gdocs'
2
2
--- old/unity-scope-gdocs       2012-07-24 12:21:51 +0000
3
 
+++ new/unity-scope-gdocs       2012-08-20 20:26:40 +0000
 
3
+++ new/unity-scope-gdocs       2012-08-23 14:00:30 +0000
4
4
@@ -1,6 +1,8 @@
5
5
-#! /usr/bin/python
6
6
-#
34
34
 
35
35
 #
36
36
 # The primary bus name we grab *must* match what we specify in our .scope file
37
 
@@ -59,16 +60,53 @@
38
 
     self._scopes.append(scope)
39
 
 
40
 
 
 
37
@@ -38,53 +39,15 @@
 
38
 class Daemon:
 
39
 
 
40
   def __init__ (self):
 
41
-    self._scopes = []
 
42
+    self._scope = Unity.Scope.new ("/net/launchpad/unity/scope/gdocs")
 
43
+    self._scope.search_in_global = True;
 
44
+
 
45
+    self._gdocs_accounts = []
 
46
     self._account_manager = Accounts.Manager.new_for_service_type("documents")
 
47
     self._account_manager.connect("enabled-event", self._on_enabled_event);
 
48
     for account in self._account_manager.get_enabled_account_services():
 
49
       self.add_account_service(account)
 
50
 
 
51
-  def _on_enabled_event (self, account_manager, account_id):
 
52
-    account = self._account_manager.get_account(account_id)
 
53
-    for service in account.list_services():
 
54
-      account_service = Accounts.AccountService.new(account, service)
 
55
-      if account_service.get_enabled():
 
56
-        self.add_account_service(account_service)
 
57
-
 
58
-  def add_account_service(self, account_service):
 
59
-    for scope in self._scopes:
 
60
-      if scope.get_account_service() == account_service:
 
61
-        return
 
62
-    scope = UserScope(account_service);
 
63
-    self._scopes.append(scope)
 
64
-
 
65
-
41
66
-class OAuth2Token:
42
67
-  def __init__(self, token):
43
68
-    self._token = token
48
73
-
49
74
-  def __eq__(self, other):
50
75
-    return other and self._token == other._token
 
76
-
 
77
-# Encapsulates searching a single user's GDocs
 
78
-class UserScope:
 
79
-  def __init__ (self, account_service):
 
80
-    self._account_service = account_service
 
81
-    self._account_service.connect("enabled", self._on_account_enabled)
 
82
-    self._enabled = self._account_service.get_enabled()
 
83
-    self._authenticating = False
 
84
-    self._client = gdata.docs.client.DocsClient(source='njpatel-UnityLensGDocs-0.1')
 
85
-    self._client.ssl = True
 
86
-    self._client.http_client.debug = False
 
87
-    self._queued_search = None
 
88
-
 
89
-    self._scope = Unity.Scope.new ("/net/launchpad/unity/scope/gdocs")
 
90
-    self._scope.search_in_global = True;
 
91
-
 
92
     # Listen for changes and requests
 
93
     self._scope.connect ("search-changed", self._on_search_changed)
 
94
 
 
95
@@ -95,100 +58,114 @@
 
96
     self._scope.connect ("filters-changed", self._on_filters_changed);
 
97
     self._scope.export()
 
98
 
 
99
-    # Initiate the login
 
100
-    self.login()
 
101
-
 
102
-  def login(self):
 
103
-    if self._authenticating:
 
104
-      return
 
105
-    print "logging in"
 
106
-    self._authenticating = True
 
107
+  def _on_enabled_event (self, account_manager, account_id):
 
108
+    account = self._account_manager.get_account(account_id)
 
109
+    for service in account.list_services():
 
110
+      account_service = Accounts.AccountService.new(account, service)
 
111
+      if account_service.get_enabled():
 
112
+        self.add_account_service(account_service)
 
113
+
 
114
+  def add_account_service(self, account_service):
 
115
+    for gdocs_account in self._gdocs_accounts:
 
116
+      if gdocs_account.get_account_service() == account_service:
 
117
+        return
 
118
+    gdocs_account = GDocsAccount(self._scope, account_service);
 
119
+    self._gdocs_accounts.append(gdocs_account)
 
120
+
 
121
+  def _on_search_changed (self, scope, search, search_type, cancellable):
 
122
+    search_string = search.props.search_string
 
123
+    results = search.props.results_model
 
124
+    if search_type == Unity.SearchType.GLOBAL:
 
125
+      is_global = True
 
126
+    else:
 
127
+      is_global = False
 
128
+
 
129
+    print("Search changed to: '%s'" % search_string)
 
130
+
 
131
+    results.clear()
 
132
+    for gdocs_account in self._gdocs_accounts:
 
133
+      gdocs_account.update_results_model (search_string, results, is_global)
 
134
+    search.emit("finished")
 
135
+  
 
136
+  def _on_filters_changed (self, scope, param_spec=None):
 
137
+    scope.queue_search_changed(Unity.SearchType.DEFAULT)
 
138
+  
 
139
+
51
140
+class SignOnAuthorizer(GObject.Object, GData.Authorizer):
52
141
+  __g_type_name__ = "SignOnAuthorizer"
53
142
+  def __init__(self, account_service):
63
152
+
64
153
+  def do_refresh_authorization(self, cancellable):
65
154
+    old_token = self._token
66
 
+    # Get the global account settings
67
 
+    auth_data = self._account_service.get_auth_data()
68
 
+    identity = auth_data.get_credentials_id()
69
 
+    session_data = auth_data.get_parameters()
 
155
     # Get the global account settings
 
156
     auth_data = self._account_service.get_auth_data()
 
157
     identity = auth_data.get_credentials_id()
 
158
     session_data = auth_data.get_parameters()
 
159
-    self.auth_session = Signon.AuthSession.new(identity, auth_data.get_method())
 
160
-    self.auth_session.process(session_data,
70
161
+    self._auth_session = Signon.AuthSession.new(identity, auth_data.get_method())
71
162
+    self._main_loop = GObject.MainLoop()
72
163
+    self._auth_session.process(session_data,
73
 
+            auth_data.get_mechanism(),
74
 
+            self.login_cb, None)
 
164
             auth_data.get_mechanism(),
 
165
             self.login_cb, None)
75
166
+    if self._main_loop:
76
167
+      self._main_loop.run()
77
168
+    if self._token == old_token:
80
171
+    else:
81
172
+      print("Got token: %s", (self._token))
82
173
+      return True
83
 
+
84
 
+  def login_cb(self, session, reply, error, user_data):
 
174
 
 
175
   def login_cb(self, session, reply, error, user_data):
 
176
-    print "login finished"
 
177
-    self._authenticating = False
85
178
+    print("login finished")
86
179
+    self._main_loop.quit()
87
180
+    self._main_loop = None
88
 
+    if error:
 
181
     if error:
 
182
-      print >> sys.stderr, "Got authentication error:", error.message
89
183
+      print("Got authentication error:", error.message)
90
 
+      return
91
 
+    if reply.has_key("AuthToken"):
92
 
+      self._token = reply["AuthToken"]
93
 
+    elif reply.has_key("AccessToken"):
94
 
+      self._token = reply["AccessToken"]
95
 
+    else:
96
 
+      print("Didn't find token in session:", reply)
97
 
+
98
 
 
99
 
 # Encapsulates searching a single user's GDocs
100
 
 class UserScope:
101
 
@@ -77,10 +115,9 @@
102
 
     self._account_service.connect("enabled", self._on_account_enabled)
103
 
     self._enabled = self._account_service.get_enabled()
104
 
     self._authenticating = False
105
 
-    self._client = gdata.docs.client.DocsClient(source='njpatel-UnityLensGDocs-0.1')
106
 
-    self._client.ssl = True
107
 
-    self._client.http_client.debug = False
108
 
-    self._queued_search = None
109
 
+    authorizer = SignOnAuthorizer(self._account_service)
110
 
+    authorizer.refresh_authorization(None)
111
 
+    self._client = GData.DocumentsService(authorizer=authorizer)
112
 
 
113
 
     self._scope = Unity.Scope.new ("/net/launchpad/unity/scope/gdocs")
114
 
     self._scope.search_in_global = True;
115
 
@@ -95,48 +132,6 @@
116
 
     self._scope.connect ("filters-changed", self._on_filters_changed);
117
 
     self._scope.export()
118
 
 
119
 
-    # Initiate the login
120
 
-    self.login()
121
 
-
122
 
-  def login(self):
123
 
-    if self._authenticating:
124
 
-      return
125
 
-    print "logging in"
126
 
-    self._authenticating = True
127
 
-    # Get the global account settings
128
 
-    auth_data = self._account_service.get_auth_data()
129
 
-    identity = auth_data.get_credentials_id()
130
 
-    session_data = auth_data.get_parameters()
131
 
-    self.auth_session = Signon.AuthSession.new(identity, auth_data.get_method())
132
 
-    self.auth_session.process(session_data,
133
 
-            auth_data.get_mechanism(),
134
 
-            self.login_cb, None)
135
 
-
136
 
-  def login_cb(self, session, reply, error, user_data):
137
 
-    print "login finished"
138
 
-    self._authenticating = False
139
 
-    if error:
140
 
-      print >> sys.stderr, "Got authentication error:", error.message
141
 
-      return
 
184
       return
142
185
-    old_token = self._client.auth_token
143
186
-    if reply.has_key("AuthToken"):
144
187
-      self._client.auth_token = gdata.gauth.ClientLoginToken(reply["AuthToken"])
147
190
-      #self._client.auth_token = gdata.gauth.OAuth2Token(None, None, None, None,
148
191
-      #    access_token=reply["AccessToken"])
149
192
-      self._client.auth_token = OAuth2Token(reply["AccessToken"])
150
 
-    else:
 
193
+    if "AuthToken" in reply:
 
194
+      self._token = reply["AuthToken"]
 
195
+    elif "AccessToken" in reply:
 
196
+      self._token = reply["AccessToken"]
 
197
     else:
151
198
-      print >> sys.stderr, "Didn't find token in session:", reply
152
199
-
153
200
-    if self._client.auth_token == old_token:
157
204
-    if self._queued_search:
158
205
-      print "Performing queued search"
159
206
-      self._on_search_changed(*self._queued_search)
160
 
-
 
207
+      print("Didn't find token in session:", reply)
 
208
+
 
209
+
 
210
+# Encapsulates searching a single user's GDocs
 
211
+class GDocsAccount:
 
212
+  def __init__ (self, scope, account_service):
 
213
+    self._scope = scope
 
214
+    self._account_service = account_service
 
215
+    self._account_service.connect("enabled", self._on_account_enabled)
 
216
+    self._enabled = self._account_service.get_enabled()
 
217
+    self._authenticating = False
 
218
+    authorizer = SignOnAuthorizer(self._account_service)
 
219
+    authorizer.refresh_authorization(None)
 
220
+    self._client = GData.DocumentsService(authorizer=authorizer)
 
221
 
161
222
   def get_account_service (self):
162
223
     return self._account_service
163
224
 
164
 
@@ -147,11 +142,6 @@
 
225
-  def get_scope (self):
 
226
-    return self._scope;
 
227
-
 
228
   def _on_account_enabled (self, account, enabled):
 
229
+    print("account %s, enabled %s" % (account, enabled))
165
230
     self._enabled = enabled
166
231
 
167
 
   def _on_search_changed (self, scope, search, search_type, cancellable):
 
232
-  def _on_search_changed (self, scope, search, search_type, cancellable):
168
233
-    self._queued_search = (scope, search, search_type, cancellable)
169
234
-    if self._authenticating:
170
235
-      print "authenticating, queuing search"
171
 
-      return
172
 
-
173
 
     search_string = search.props.search_string
174
 
     results = search.props.results_model
175
 
     if search_type == Unity.SearchType.GLOBAL:
176
 
@@ -159,17 +149,12 @@
177
 
     else:
178
 
       is_global = False
179
 
     
 
236
+  def update_results_model (self, search, model, is_global=False):
 
237
+    if not self._enabled:
 
238
       return
 
239
 
 
240
-    search_string = search.props.search_string
 
241
-    results = search.props.results_model
 
242
-    if search_type == Unity.SearchType.GLOBAL:
 
243
-      is_global = True
 
244
-    else:
 
245
-      is_global = False
 
246
-    
180
247
-    print "Search changed to: '%s'" % search_string
181
 
+    print("Search changed to: '%s'" % search_string)
182
 
     
183
 
     if self._enabled:
 
248
-    
 
249
-    if self._enabled:
184
250
-      try:
185
251
-        self._update_results_model (search_string, results, is_global)
186
252
-      except gdata.client.Unauthorized:
187
253
-        self.login()
188
254
-        return
189
 
+      self._update_results_model (search_string, results, is_global)
190
 
     else:
191
 
       results.clear()
 
255
-    else:
 
256
-      results.clear()
192
257
-    self._queued_search = None
193
 
     search.emit("finished")
194
 
   
195
 
   def _on_filters_changed (self, scope, param_spec=None):
196
 
@@ -185,10 +170,7 @@
 
258
-    search.emit("finished")
 
259
-  
 
260
-  def _on_filters_changed (self, scope, param_spec=None):
 
261
-    scope.queue_search_changed(Unity.SearchType.DEFAULT)
 
262
-  
 
263
-  def _update_results_model (self, search, model, is_global=False):
 
264
-    # Clear out the current results in the model as we'll get a new list
 
265
-    # NOTE: We could be clever and only remove/add things entries that have
 
266
-    # changed, however the cost of doing that for a small result set probably
 
267
-    # outweighs the gains. Especially if you consider the complexity,
 
268
-    model.clear ()
 
269
-
197
270
     # Get the list of documents
198
271
     feed = self.get_doc_list(search, is_global);
199
272
     for entry in feed:
205
278
 
206
279
       if is_global:
207
280
         category = 1
208
 
@@ -198,37 +180,33 @@
 
281
@@ -198,37 +175,33 @@
209
282
         else:
210
283
           category = 0
211
284
 
215
288
                    category,
216
289
                    "text/html",
217
290
-                   entry.title.text.encode("UTF-8"),
218
 
+                   entry.props.title.encode("UTF-8"),
 
291
+                   entry.props.title,
219
292
                    rtype,
220
293
-                   entry.link[0].href);
221
294
+                   entry.props.content_uri);
255
328
     f = self._scope.get_filter("modified")
256
329
     if f != None:
257
330
       o = f.get_active_option()
258
 
@@ -242,9 +220,7 @@
 
331
@@ -242,9 +215,7 @@
259
332
           age = 7
260
333
         if age:
261
334
           last_time = datetime.now() - timedelta(age)
266
339
 
267
340
   def filter_results (self, entry):
268
341
     f = self._scope.get_filter("type")
269
 
@@ -253,10 +229,7 @@
 
342
@@ -253,10 +224,7 @@
270
343
     if not f.props.filtering:
271
344
       return True
272
345
 
278
351
 
279
352
     filter_type = TYPE_MAP.get(rtype, "other")
280
353
     return f.get_option(filter_type).props.active
281
 
@@ -278,7 +251,7 @@
 
354
@@ -277,8 +245,10 @@
 
355
       ret = "x-office-spreadsheet"
282
356
     elif doc_type == "folder":
283
357
       ret = "folder"
 
358
+    elif doc_type == "file":
 
359
+      ret = "gnome-fs-regular"
284
360
     else:
285
361
-      print "Unhandled icon type: ", doc_type
286
362
+      print("Unhandled icon type: ", doc_type)
287
363
 
288
364
     return ret;
289
365
 
290
 
@@ -304,7 +277,7 @@
 
366
@@ -304,7 +274,7 @@
291
367
   result = result.unpack()[0]
292
368
   
293
369
   if result != 1 :
297
373
   
298
374
   daemon = Daemon()
299
375
 
 
376
=== modified file 'setup.py'
 
377
--- old/setup.py        2012-08-15 06:14:42 +0000
 
378
+++ new/setup.py        2012-08-23 17:06:33 +0000
 
379
@@ -6,7 +6,7 @@
 
380
 
 
381
 applications_path = subprocess.check_output(['pkg-config',
 
382
     '--variable=applicationfilesdir',
 
383
-    'libaccounts-glib']).rstrip('\n')
 
384
+    'libaccounts-glib']).rstrip().decode()
 
385
 setup(name="unity-scope-gdocs",
 
386
       version="0.1",
 
387
       author="Alberto Mardegan",
 
388