Merge lp:~statik/ubuntu/maverick/magicicada/zero-one-two into lp:ubuntu/maverick/magicicada
- Maverick (10.10)
- zero-one-two
- Merge into maverick
Proposed by
Elliot Murphy
Status: | Merged |
---|---|
Merged at revision: | 3 |
Proposed branch: | lp:~statik/ubuntu/maverick/magicicada/zero-one-two |
Merge into: | lp:ubuntu/maverick/magicicada |
Diff against target: |
3256 lines (+1233/-512) 17 files modified
PKG-INFO (+3/-3) README.txt (+13/-0) bin/magicicada (+17/-13) data/ui/gui.glade (+70/-8) debian/changelog (+6/-0) magicicada/__init__.py (+129/-33) magicicada/cmd_pof.py (+0/-190) magicicada/dbusiface.py (+58/-10) magicicada/helpers.py (+38/-24) magicicada/logger.py (+0/-1) magicicada/magicicadaconfig.py (+5/-6) magicicada/syncdaemon.py (+48/-26) magicicada/tests/helpers.py (+7/-3) magicicada/tests/test_dbusiface.py (+160/-49) magicicada/tests/test_magicicada.py (+502/-87) magicicada/tests/test_syncdaemon.py (+152/-41) setup.py (+25/-18) |
To merge this branch: | bzr merge lp:~statik/ubuntu/maverick/magicicada/zero-one-two |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu branches | Pending | ||
Review via email: mp+29596@code.launchpad.net |
Commit message
Description of the change
New upstream release of Magicicada. I've testbuilt and installed, and it upgrades and runs just fine.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'PKG-INFO' | |||
2 | --- PKG-INFO 2010-06-08 10:53:02 +0000 | |||
3 | +++ PKG-INFO 2010-07-09 18:33:43 +0000 | |||
4 | @@ -1,7 +1,7 @@ | |||
5 | 1 | Metadata-Version: 1.1 | 1 | Metadata-Version: 1.1 |
6 | 2 | Name: magicicada | 2 | Name: magicicada |
9 | 3 | Version: 0.1.1 | 3 | Version: 0.1.2 |
10 | 4 | Summary: A GTK+ frontend for the "Chicharra" part of Ubuntu One client. | 4 | Summary: A GTK+ frontend for the "Chicharra" part of Ubuntu One. |
11 | 5 | Home-page: https://launchpad.net/magicicada | 5 | Home-page: https://launchpad.net/magicicada |
12 | 6 | Author: Natalia Bidart | 6 | Author: Natalia Bidart |
13 | 7 | Author-email: natalia.bidart@ubuntu.com | 7 | Author-email: natalia.bidart@ubuntu.com |
14 | @@ -14,6 +14,6 @@ | |||
15 | 14 | Requires: pango | 14 | Requires: pango |
16 | 15 | Requires: twisted.internet | 15 | Requires: twisted.internet |
17 | 16 | Requires: twisted.trial.unittest | 16 | Requires: twisted.trial.unittest |
19 | 17 | Requires: ubuntuone.syncdaemon | 17 | Requires: ubuntuone.syncdaemon.tools |
20 | 18 | Requires: xdg.BaseDirectory | 18 | Requires: xdg.BaseDirectory |
21 | 19 | Provides: magicicada | 19 | Provides: magicicada |
22 | 20 | 20 | ||
23 | === modified file 'README.txt' | |||
24 | --- README.txt 2010-06-08 10:53:02 +0000 | |||
25 | +++ README.txt 2010-07-09 18:33:43 +0000 | |||
26 | @@ -1,3 +1,16 @@ | |||
27 | 1 | This is Magicicada! | 1 | This is Magicicada! |
28 | 2 | 2 | ||
29 | 3 | A GTK+ frontend for the "Chicharra" part of Ubuntu One client. | 3 | A GTK+ frontend for the "Chicharra" part of Ubuntu One client. |
30 | 4 | |||
31 | 5 | ----------- | ||
32 | 6 | HOWTO do a source release: | ||
33 | 7 | |||
34 | 8 | * edit setup.py and increment the version number. | ||
35 | 9 | * 'python setup.py sdist' | ||
36 | 10 | * look at the contents of the tarball created in dist/ to be sure they are ok | ||
37 | 11 | * sign the tarball by a command like: | ||
38 | 12 | gpg -a --detach-sign magicicada-0.2.tar.gz | ||
39 | 13 | this should create a file like magicicada-0.2.tar.gz.asc | ||
40 | 14 | * Upload the new release to launchpad with a command like: | ||
41 | 15 | lp-project-upload magicicada 0.2 magicicada-0.2.tar.gz | ||
42 | 16 | * Announce the release, ping someone to build updated packages for the PPA and Ubuntu. | ||
43 | 4 | 17 | ||
44 | === modified file 'bin/magicicada' | |||
45 | --- bin/magicicada 2010-06-08 10:53:02 +0000 | |||
46 | +++ bin/magicicada 2010-07-09 18:33:43 +0000 | |||
47 | @@ -1,8 +1,21 @@ | |||
48 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/python |
49 | 2 | # -*- coding: utf-8 -*- | 2 | # -*- coding: utf-8 -*- |
53 | 3 | ### BEGIN LICENSE | 3 | # |
54 | 4 | # This file is in the public domain | 4 | # Copyright 2010 Chicharreros |
55 | 5 | ### END LICENSE | 5 | # |
56 | 6 | # This program is free software: you can redistribute it and/or modify it | ||
57 | 7 | # under the terms of the GNU General Public License version 3, as published | ||
58 | 8 | # by the Free Software Foundation. | ||
59 | 9 | # | ||
60 | 10 | # This program is distributed in the hope that it will be useful, but | ||
61 | 11 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
62 | 12 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
63 | 13 | # PURPOSE. See the GNU General Public License for more details. | ||
64 | 14 | # | ||
65 | 15 | # You should have received a copy of the GNU General Public License along | ||
66 | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
67 | 17 | |||
68 | 18 | """Script to run Magicicada.""" | ||
69 | 6 | 19 | ||
70 | 7 | import sys | 20 | import sys |
71 | 8 | import os | 21 | import os |
72 | @@ -11,14 +24,6 @@ | |||
73 | 11 | from gettext import gettext as _ | 24 | from gettext import gettext as _ |
74 | 12 | gettext.textdomain('magicicada') | 25 | gettext.textdomain('magicicada') |
75 | 13 | 26 | ||
76 | 14 | # optional Launchpad integration | ||
77 | 15 | # this shouldn't crash if not found as it is simply used for bug reporting | ||
78 | 16 | try: | ||
79 | 17 | import LaunchpadIntegration | ||
80 | 18 | launchpad_available = True | ||
81 | 19 | except: | ||
82 | 20 | launchpad_available = False | ||
83 | 21 | |||
84 | 22 | # Add project root directory (enable symlink, and trunk execution). | 27 | # Add project root directory (enable symlink, and trunk execution). |
85 | 23 | PROJECT_ROOT_DIRECTORY = os.path.abspath( | 28 | PROJECT_ROOT_DIRECTORY = os.path.abspath( |
86 | 24 | os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))) | 29 | os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))) |
87 | @@ -48,6 +53,5 @@ | |||
88 | 48 | from twisted.internet import reactor | 53 | from twisted.internet import reactor |
89 | 49 | 54 | ||
90 | 50 | # Run the application. | 55 | # Run the application. |
93 | 51 | window = MagicicadaUI(launchpad_available=launchpad_available, | 56 | window = MagicicadaUI(on_destroy=lambda *a, **kw: reactor.stop()) |
92 | 52 | on_destroy=lambda *a, **kw: reactor.stop()) | ||
94 | 53 | reactor.run() | 57 | reactor.run() |
95 | 54 | 58 | ||
96 | === added symlink 'data/media/icon.png' | |||
97 | === target is u'logo-032.png' | |||
98 | === added directory 'data/tests' | |||
99 | === added file 'data/tests/metadata-test.txt' | |||
100 | === modified file 'data/ui/gui.glade' | |||
101 | --- data/ui/gui.glade 2010-06-08 10:53:02 +0000 | |||
102 | +++ data/ui/gui.glade 2010-07-09 18:33:43 +0000 | |||
103 | @@ -257,6 +257,7 @@ | |||
104 | 257 | </child> | 257 | </child> |
105 | 258 | <child> | 258 | <child> |
106 | 259 | <object class="GtkToolButton" id="raw_metadata"> | 259 | <object class="GtkToolButton" id="raw_metadata"> |
107 | 260 | <property name="visible">True</property> | ||
108 | 260 | <property name="sensitive">False</property> | 261 | <property name="sensitive">False</property> |
109 | 261 | <property name="label" translatable="yes">Metadata</property> | 262 | <property name="label" translatable="yes">Metadata</property> |
110 | 262 | <property name="use_underline">True</property> | 263 | <property name="use_underline">True</property> |
111 | @@ -384,7 +385,7 @@ | |||
112 | 384 | <child> | 385 | <child> |
113 | 385 | <object class="GtkCellRendererText" id="cellrenderertext1"/> | 386 | <object class="GtkCellRendererText" id="cellrenderertext1"/> |
114 | 386 | <attributes> | 387 | <attributes> |
116 | 387 | <attribute name="text">0</attribute> | 388 | <attribute name="markup">0</attribute> |
117 | 388 | </attributes> | 389 | </attributes> |
118 | 389 | </child> | 390 | </child> |
119 | 390 | </object> | 391 | </object> |
120 | @@ -396,7 +397,7 @@ | |||
121 | 396 | <child> | 397 | <child> |
122 | 397 | <object class="GtkCellRendererText" id="cellrenderertext2"/> | 398 | <object class="GtkCellRendererText" id="cellrenderertext2"/> |
123 | 398 | <attributes> | 399 | <attributes> |
125 | 399 | <attribute name="text">1</attribute> | 400 | <attribute name="markup">1</attribute> |
126 | 400 | </attributes> | 401 | </attributes> |
127 | 401 | </child> | 402 | </child> |
128 | 402 | </object> | 403 | </object> |
129 | @@ -408,7 +409,7 @@ | |||
130 | 408 | <child> | 409 | <child> |
131 | 409 | <object class="GtkCellRendererText" id="cellrenderertext4"/> | 410 | <object class="GtkCellRendererText" id="cellrenderertext4"/> |
132 | 410 | <attributes> | 411 | <attributes> |
134 | 411 | <attribute name="text">2</attribute> | 412 | <attribute name="markup">2</attribute> |
135 | 412 | </attributes> | 413 | </attributes> |
136 | 413 | </child> | 414 | </child> |
137 | 414 | </object> | 415 | </object> |
138 | @@ -420,7 +421,7 @@ | |||
139 | 420 | <child> | 421 | <child> |
140 | 421 | <object class="GtkCellRendererText" id="cellrenderertext3"/> | 422 | <object class="GtkCellRendererText" id="cellrenderertext3"/> |
141 | 422 | <attributes> | 423 | <attributes> |
143 | 423 | <attribute name="text">3</attribute> | 424 | <attribute name="markup">3</attribute> |
144 | 424 | </attributes> | 425 | </attributes> |
145 | 425 | </child> | 426 | </child> |
146 | 426 | </object> | 427 | </object> |
147 | @@ -476,7 +477,7 @@ | |||
148 | 476 | <child> | 477 | <child> |
149 | 477 | <object class="GtkCellRendererText" id="cellrenderertext5"/> | 478 | <object class="GtkCellRendererText" id="cellrenderertext5"/> |
150 | 478 | <attributes> | 479 | <attributes> |
152 | 479 | <attribute name="text">0</attribute> | 480 | <attribute name="markup">0</attribute> |
153 | 480 | </attributes> | 481 | </attributes> |
154 | 481 | </child> | 482 | </child> |
155 | 482 | </object> | 483 | </object> |
156 | @@ -488,7 +489,7 @@ | |||
157 | 488 | <child> | 489 | <child> |
158 | 489 | <object class="GtkCellRendererText" id="cellrenderertext6"/> | 490 | <object class="GtkCellRendererText" id="cellrenderertext6"/> |
159 | 490 | <attributes> | 491 | <attributes> |
161 | 491 | <attribute name="text">1</attribute> | 492 | <attribute name="markup">1</attribute> |
162 | 492 | </attributes> | 493 | </attributes> |
163 | 493 | </child> | 494 | </child> |
164 | 494 | </object> | 495 | </object> |
165 | @@ -500,7 +501,7 @@ | |||
166 | 500 | <child> | 501 | <child> |
167 | 501 | <object class="GtkCellRendererText" id="cellrenderertext8"/> | 502 | <object class="GtkCellRendererText" id="cellrenderertext8"/> |
168 | 502 | <attributes> | 503 | <attributes> |
170 | 503 | <attribute name="text">2</attribute> | 504 | <attribute name="markup">2</attribute> |
171 | 504 | </attributes> | 505 | </attributes> |
172 | 505 | </child> | 506 | </child> |
173 | 506 | </object> | 507 | </object> |
174 | @@ -512,7 +513,7 @@ | |||
175 | 512 | <child> | 513 | <child> |
176 | 513 | <object class="GtkCellRendererText" id="cellrenderertext7"/> | 514 | <object class="GtkCellRendererText" id="cellrenderertext7"/> |
177 | 514 | <attributes> | 515 | <attributes> |
179 | 515 | <attribute name="text">3</attribute> | 516 | <attribute name="markup">3</attribute> |
180 | 516 | </attributes> | 517 | </attributes> |
181 | 517 | </child> | 518 | </child> |
182 | 518 | </object> | 519 | </object> |
183 | @@ -1051,4 +1052,65 @@ | |||
184 | 1051 | <action-widget response="0">shares_to_others_close</action-widget> | 1052 | <action-widget response="0">shares_to_others_close</action-widget> |
185 | 1052 | </action-widgets> | 1053 | </action-widgets> |
186 | 1053 | </object> | 1054 | </object> |
187 | 1055 | <object class="GtkFileChooserDialog" id="file_chooser"> | ||
188 | 1056 | <property name="border_width">5</property> | ||
189 | 1057 | <property name="type_hint">normal</property> | ||
190 | 1058 | <property name="has_separator">False</property> | ||
191 | 1059 | <property name="create_folders">False</property> | ||
192 | 1060 | <signal name="file_activated" handler="on_file_chooser_open_clicked"/> | ||
193 | 1061 | <child internal-child="vbox"> | ||
194 | 1062 | <object class="GtkVBox" id="dialog-vbox7"> | ||
195 | 1063 | <property name="visible">True</property> | ||
196 | 1064 | <property name="spacing">2</property> | ||
197 | 1065 | <child> | ||
198 | 1066 | <placeholder/> | ||
199 | 1067 | </child> | ||
200 | 1068 | <child internal-child="action_area"> | ||
201 | 1069 | <object class="GtkHButtonBox" id="dialog-action_area7"> | ||
202 | 1070 | <property name="visible">True</property> | ||
203 | 1071 | <property name="layout_style">end</property> | ||
204 | 1072 | <child> | ||
205 | 1073 | <object class="GtkButton" id="file_chooser_cancel"> | ||
206 | 1074 | <property name="label">gtk-cancel</property> | ||
207 | 1075 | <property name="visible">True</property> | ||
208 | 1076 | <property name="can_focus">True</property> | ||
209 | 1077 | <property name="receives_default">True</property> | ||
210 | 1078 | <property name="use_stock">True</property> | ||
211 | 1079 | </object> | ||
212 | 1080 | <packing> | ||
213 | 1081 | <property name="expand">False</property> | ||
214 | 1082 | <property name="fill">False</property> | ||
215 | 1083 | <property name="position">0</property> | ||
216 | 1084 | </packing> | ||
217 | 1085 | </child> | ||
218 | 1086 | <child> | ||
219 | 1087 | <object class="GtkButton" id="file_chooser_open"> | ||
220 | 1088 | <property name="label">gtk-open</property> | ||
221 | 1089 | <property name="visible">True</property> | ||
222 | 1090 | <property name="can_focus">True</property> | ||
223 | 1091 | <property name="receives_default">True</property> | ||
224 | 1092 | <property name="use_stock">True</property> | ||
225 | 1093 | <signal name="clicked" handler="on_file_chooser_open_clicked"/> | ||
226 | 1094 | <signal name="activate" handler="on_file_chooser_open_clicked"/> | ||
227 | 1095 | </object> | ||
228 | 1096 | <packing> | ||
229 | 1097 | <property name="expand">False</property> | ||
230 | 1098 | <property name="fill">False</property> | ||
231 | 1099 | <property name="position">1</property> | ||
232 | 1100 | </packing> | ||
233 | 1101 | </child> | ||
234 | 1102 | </object> | ||
235 | 1103 | <packing> | ||
236 | 1104 | <property name="expand">False</property> | ||
237 | 1105 | <property name="pack_type">end</property> | ||
238 | 1106 | <property name="position">0</property> | ||
239 | 1107 | </packing> | ||
240 | 1108 | </child> | ||
241 | 1109 | </object> | ||
242 | 1110 | </child> | ||
243 | 1111 | <action-widgets> | ||
244 | 1112 | <action-widget response="-6">file_chooser_cancel</action-widget> | ||
245 | 1113 | <action-widget response="0">file_chooser_open</action-widget> | ||
246 | 1114 | </action-widgets> | ||
247 | 1115 | </object> | ||
248 | 1054 | </interface> | 1116 | </interface> |
249 | 1055 | 1117 | ||
250 | === modified file 'debian/changelog' | |||
251 | --- debian/changelog 2010-06-08 10:53:02 +0000 | |||
252 | +++ debian/changelog 2010-07-09 18:33:43 +0000 | |||
253 | @@ -1,3 +1,9 @@ | |||
254 | 1 | magicicada (0.1.2-0ubuntu1) maverick; urgency=low | ||
255 | 2 | |||
256 | 3 | * New upstream release. | ||
257 | 4 | |||
258 | 5 | -- Elliot Murphy <elliot@ubuntu.com> Fri, 09 Jul 2010 14:14:53 -0400 | ||
259 | 6 | |||
260 | 1 | magicicada (0.1.1-0ubuntu1) maverick; urgency=low | 7 | magicicada (0.1.1-0ubuntu1) maverick; urgency=low |
261 | 2 | 8 | ||
262 | 3 | [ Elliot Murphy ] | 9 | [ Elliot Murphy ] |
263 | 4 | 10 | ||
264 | === modified file 'magicicada/__init__.py' | |||
265 | --- magicicada/__init__.py 2010-06-08 10:53:02 +0000 | |||
266 | +++ magicicada/__init__.py 2010-07-09 18:33:43 +0000 | |||
267 | @@ -18,33 +18,52 @@ | |||
268 | 18 | 18 | ||
269 | 19 | """Magicicada.""" | 19 | """Magicicada.""" |
270 | 20 | 20 | ||
273 | 21 | import gtk | 21 | import logging |
274 | 22 | import sys | 22 | import os |
275 | 23 | 23 | ||
276 | 24 | import gettext | 24 | import gettext |
278 | 25 | from gettext import gettext as _ | 25 | _ = gettext.gettext |
279 | 26 | gettext.textdomain('magicicada') | 26 | gettext.textdomain('magicicada') |
280 | 27 | 27 | ||
282 | 28 | from twisted.internet import gtk2reactor # for gtk-2.0 | 28 | import gtk |
283 | 29 | |||
284 | 30 | # optional Launchpad integration | ||
285 | 31 | # this shouldn't crash if not found as it is simply used for bug reporting | ||
286 | 32 | try: | ||
287 | 33 | import LaunchpadIntegration | ||
288 | 34 | launchpad_available = True | ||
289 | 35 | except ImportError: | ||
290 | 36 | launchpad_available = False | ||
291 | 37 | |||
292 | 38 | from twisted.internet import gtk2reactor # for gtk-2.0 | ||
293 | 29 | gtk2reactor.install() | 39 | gtk2reactor.install() |
294 | 30 | 40 | ||
297 | 31 | from magicicada import syncdaemon, logger | 41 | from magicicada import syncdaemon, logger as logger_helper |
298 | 32 | from magicicada.helpers import humanize_bytes, get_data_file, get_builder, NO_OP | 42 | from magicicada.helpers import humanize_bytes, get_data_file, get_builder, \ |
299 | 43 | log, NO_OP | ||
300 | 33 | 44 | ||
301 | 34 | CONTENT_QUEUE = 'content' | 45 | CONTENT_QUEUE = 'content' |
302 | 35 | META_QUEUE = 'meta' | 46 | META_QUEUE = 'meta' |
303 | 47 | UBUNTU_ONE_ROOT = os.path.expanduser('~/Ubuntu One') | ||
304 | 36 | 48 | ||
305 | 37 | # set up the logging for all the project | 49 | # set up the logging for all the project |
307 | 38 | logger.set_up() | 50 | logger_helper.set_up() |
308 | 51 | logger = logging.getLogger('magicicada.ui') | ||
309 | 52 | console = logging.StreamHandler() | ||
310 | 53 | console.setLevel(logging.DEBUG) | ||
311 | 54 | #logger.addHandler(console) | ||
312 | 55 | |||
313 | 39 | 56 | ||
314 | 40 | class MagicicadaUI(object): | 57 | class MagicicadaUI(object): |
315 | 58 | """Magicicada GUI main class.""" | ||
316 | 41 | 59 | ||
318 | 42 | STATUS_JOINER = " - " | 60 | CURRENT_ROW = '<b><span foreground="#000099">%s</span></b>' |
319 | 61 | STATUS_JOINER = ' - ' | ||
320 | 43 | STATUS = { | 62 | STATUS = { |
321 | 44 | 'initial': _('Service is not started, click Start to continue.'), | 63 | 'initial': _('Service is not started, click Start to continue.'), |
322 | 45 | } | 64 | } |
323 | 46 | 65 | ||
325 | 47 | def __init__(self, launchpad_available=False, on_destroy=NO_OP, | 66 | def __init__(self, on_destroy=NO_OP, |
326 | 48 | syncdaemon_class=syncdaemon.SyncDaemon): | 67 | syncdaemon_class=syncdaemon.SyncDaemon): |
327 | 49 | """Init.""" | 68 | """Init.""" |
328 | 50 | self.builder = get_builder('gui.glade') | 69 | self.builder = get_builder('gui.glade') |
329 | @@ -66,27 +85,28 @@ | |||
330 | 66 | self.active_indicator = gtk.gdk.pixbuf_new_from_file(active_filename) | 85 | self.active_indicator = gtk.gdk.pixbuf_new_from_file(active_filename) |
331 | 67 | 86 | ||
332 | 68 | widgets = ( | 87 | widgets = ( |
335 | 69 | 'start', 'stop', 'connect', 'disconnect', # toolbar buttons | 88 | 'start', 'stop', 'connect', 'disconnect', # toolbar buttons |
336 | 70 | 'folders', 'folders_dialog', # folders | 89 | 'folders', 'folders_dialog', # folders |
337 | 71 | 'folders_store', 'folders_close', | 90 | 'folders_store', 'folders_close', |
339 | 72 | 'shares_to_me', 'shares_to_me_dialog', # shares_to_me | 91 | 'shares_to_me', 'shares_to_me_dialog', # shares_to_me |
340 | 73 | 'shares_to_me_store', 'shares_to_me_close', | 92 | 'shares_to_me_store', 'shares_to_me_close', |
342 | 74 | 'shares_to_others', 'shares_to_others_dialog', # shares_to_others | 93 | 'shares_to_others', 'shares_to_others_dialog', # shares_to_others |
343 | 75 | 'shares_to_others_store', 'shares_to_others_close', | 94 | 'shares_to_others_store', 'shares_to_others_close', |
353 | 76 | 'is_started', 'is_connected', 'is_online', # status bar images | 95 | 'raw_metadata', # raw metadata |
354 | 77 | 'status_label', 'status_icon', # status label and systray icon | 96 | 'is_started', 'is_connected', 'is_online', # status bar images |
355 | 78 | 'metaq_view', 'contentq_view', # queues tree views | 97 | 'status_label', 'status_icon', # status label and systray icon |
356 | 79 | 'metaq_store', 'contentq_store', # queues list stores | 98 | 'metaq_view', 'contentq_view', # queues tree views |
357 | 80 | 'metaq_label', 'contentq_label', # queues labels | 99 | 'metaq_store', 'contentq_store', # queues list stores |
358 | 81 | 'raw_metadata', # raw metadata | 100 | 'metaq_label', 'contentq_label', # queues labels |
359 | 82 | 'about_dialog', # dialogs | 101 | 'file_chooser', 'file_chooser_open', 'file_chooser_cancel', |
360 | 83 | 'main_window' | 102 | 'about_dialog', 'main_window') |
361 | 84 | ) | 103 | |
362 | 85 | for widget in widgets: | 104 | for widget in widgets: |
363 | 86 | obj = self.builder.get_object(widget) | 105 | obj = self.builder.get_object(widget) |
364 | 87 | setattr(self, widget, obj) | 106 | setattr(self, widget, obj) |
365 | 88 | assert obj is not None, '%s must not be None' % widget | 107 | assert obj is not None, '%s must not be None' % widget |
366 | 89 | 108 | ||
367 | 109 | self.raw_metadata_dialog = self._new_metadata_dialog() | ||
368 | 90 | self.volumes = (self.folders, self.shares_to_me, self.shares_to_others) | 110 | self.volumes = (self.folders, self.shares_to_me, self.shares_to_others) |
369 | 91 | self.windows = (self.main_window, self.about_dialog, | 111 | self.windows = (self.main_window, self.about_dialog, |
370 | 92 | self.folders_dialog) | 112 | self.folders_dialog) |
371 | @@ -97,8 +117,8 @@ | |||
372 | 97 | for w in self.windows: | 117 | for w in self.windows: |
373 | 98 | w.set_icon(self._icon) | 118 | w.set_icon(self._icon) |
374 | 99 | 119 | ||
377 | 100 | about_filename = get_data_file('media', 'logo-128.png') | 120 | about_fname = get_data_file('media', 'logo-128.png') |
378 | 101 | self.about_dialog.set_logo(gtk.gdk.pixbuf_new_from_file(about_filename)) | 121 | self.about_dialog.set_logo(gtk.gdk.pixbuf_new_from_file(about_fname)) |
379 | 102 | 122 | ||
380 | 103 | self.sd = syncdaemon_class() | 123 | self.sd = syncdaemon_class() |
381 | 104 | self.sd.on_started_callback = self.on_started | 124 | self.sd.on_started_callback = self.on_started |
382 | @@ -110,13 +130,44 @@ | |||
383 | 110 | self.sd.status_changed_callback = self.on_status_changed | 130 | self.sd.status_changed_callback = self.on_status_changed |
384 | 111 | self.sd.content_queue_changed_callback = self.on_content_queue_changed | 131 | self.sd.content_queue_changed_callback = self.on_content_queue_changed |
385 | 112 | self.sd.meta_queue_changed_callback = self.on_meta_queue_changed | 132 | self.sd.meta_queue_changed_callback = self.on_meta_queue_changed |
386 | 133 | self.sd.on_metadata_ready_callback = self.on_metadata_ready | ||
387 | 113 | 134 | ||
388 | 114 | self.widget_is_visible = lambda w: w.get_property('visible') | 135 | self.widget_is_visible = lambda w: w.get_property('visible') |
389 | 115 | self.widget_enabled = lambda w: self.widget_is_visible(w) and \ | 136 | self.widget_enabled = lambda w: self.widget_is_visible(w) and \ |
390 | 116 | w.is_sensitive() | 137 | w.is_sensitive() |
392 | 117 | 138 | self.file_chooser.set_current_folder(UBUNTU_ONE_ROOT) | |
393 | 139 | self.last_metadata_path = None | ||
394 | 118 | self.update() | 140 | self.update() |
395 | 119 | 141 | ||
396 | 142 | def _new_metadata_dialog(self): | ||
397 | 143 | """Return a new metadata dialog.""" | ||
398 | 144 | dialog = gtk.Dialog(title='Raw metadata', parent=self.main_window, | ||
399 | 145 | flags=gtk.DIALOG_NO_SEPARATOR, | ||
400 | 146 | buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) | ||
401 | 147 | dialog.set_size_request(600, 300) | ||
402 | 148 | dialog.set_position(gtk.WIN_POS_CENTER) | ||
403 | 149 | setattr(self, 'raw_metadata_dialog', dialog) | ||
404 | 150 | |||
405 | 151 | close_button = dialog.action_area.get_children()[-1] | ||
406 | 152 | close_button.connect('clicked', self.on_raw_metadata_close_clicked) | ||
407 | 153 | close_button.connect('activate', self.on_raw_metadata_close_clicked) | ||
408 | 154 | setattr(self, 'raw_metadata_close', close_button) | ||
409 | 155 | |||
410 | 156 | image = gtk.Image() | ||
411 | 157 | image.set_from_animation(self.loading_animation) | ||
412 | 158 | setattr(self, 'raw_metadata_image', image) | ||
413 | 159 | |||
414 | 160 | dialog.get_child().add(image) | ||
415 | 161 | |||
416 | 162 | text_view = gtk.TextView() | ||
417 | 163 | text_view.set_editable(False) | ||
418 | 164 | text_view.set_wrap_mode(gtk.WRAP_WORD) | ||
419 | 165 | dialog.get_child().add(text_view) | ||
420 | 166 | setattr(self, 'raw_metadata_view', text_view) | ||
421 | 167 | |||
422 | 168 | dialog.hide() # XXX to be fixed later | ||
423 | 169 | return dialog | ||
424 | 170 | |||
425 | 120 | # GTK callbacks | 171 | # GTK callbacks |
426 | 121 | 172 | ||
427 | 122 | def on_main_window_destroy(self, widget, data=None): | 173 | def on_main_window_destroy(self, widget, data=None): |
428 | @@ -131,7 +182,7 @@ | |||
429 | 131 | 182 | ||
430 | 132 | def on_about_activate(self, widget, data=None): | 183 | def on_about_activate(self, widget, data=None): |
431 | 133 | """Display the about box.""" | 184 | """Display the about box.""" |
433 | 134 | response = self.about_dialog.run() | 185 | self.about_dialog.run() |
434 | 135 | self.about_dialog.hide() | 186 | self.about_dialog.hide() |
435 | 136 | 187 | ||
436 | 137 | def on_start_clicked(self, widget, data=None): | 188 | def on_start_clicked(self, widget, data=None): |
437 | @@ -144,6 +195,7 @@ | |||
438 | 144 | """Stop syncdaemon.""" | 195 | """Stop syncdaemon.""" |
439 | 145 | for v in self.volumes: | 196 | for v in self.volumes: |
440 | 146 | v.set_sensitive(False) | 197 | v.set_sensitive(False) |
441 | 198 | self.raw_metadata.set_sensitive(False) | ||
442 | 147 | 199 | ||
443 | 148 | if self.widget_enabled(self.disconnect): | 200 | if self.widget_enabled(self.disconnect): |
444 | 149 | self.on_disconnect_clicked(self.disconnect) | 201 | self.on_disconnect_clicked(self.disconnect) |
445 | @@ -179,13 +231,14 @@ | |||
446 | 179 | item.subscribed, item.volume) | 231 | item.subscribed, item.volume) |
447 | 180 | self.folders_store.append(row) | 232 | self.folders_store.append(row) |
448 | 181 | 233 | ||
450 | 182 | res = self.folders_dialog.run() | 234 | self.folders_dialog.run() |
451 | 183 | self.folders_dialog.hide() | 235 | self.folders_dialog.hide() |
452 | 184 | 236 | ||
453 | 185 | def on_shares_to_me_close_clicked(self, widget, data=None): | 237 | def on_shares_to_me_close_clicked(self, widget, data=None): |
454 | 186 | """Close the shares_to_me dialog.""" | 238 | """Close the shares_to_me dialog.""" |
455 | 187 | self.shares_to_me_dialog.response(gtk.RESPONSE_CLOSE) | 239 | self.shares_to_me_dialog.response(gtk.RESPONSE_CLOSE) |
456 | 188 | 240 | ||
457 | 241 | @log(logger) | ||
458 | 189 | def _on_shares_clicked(self, items, store, dialog): | 242 | def _on_shares_clicked(self, items, store, dialog): |
459 | 190 | """List shares to the user or to others.""" | 243 | """List shares to the user or to others.""" |
460 | 191 | if items is None: | 244 | if items is None: |
461 | @@ -201,7 +254,7 @@ | |||
462 | 201 | item.path, item.volume_id) | 254 | item.path, item.volume_id) |
463 | 202 | store.append(row) | 255 | store.append(row) |
464 | 203 | 256 | ||
466 | 204 | res = dialog.run() | 257 | dialog.run() |
467 | 205 | dialog.hide() | 258 | dialog.hide() |
468 | 206 | 259 | ||
469 | 207 | def on_shares_to_me_clicked(self, widget, data=None): | 260 | def on_shares_to_me_clicked(self, widget, data=None): |
470 | @@ -220,8 +273,27 @@ | |||
471 | 220 | self.shares_to_others_store, | 273 | self.shares_to_others_store, |
472 | 221 | self.shares_to_others_dialog) | 274 | self.shares_to_others_dialog) |
473 | 222 | 275 | ||
474 | 276 | def on_file_chooser_open_clicked(self, widget, data=None): | ||
475 | 277 | """Close the file_chooser dialog.""" | ||
476 | 278 | self.file_chooser.response(gtk.FILE_CHOOSER_ACTION_OPEN) | ||
477 | 279 | |||
478 | 280 | def on_raw_metadata_close_clicked(self, widget, data=None): | ||
479 | 281 | """Close the raw_metadata dialog.""" | ||
480 | 282 | self.raw_metadata_dialog.hide() | ||
481 | 283 | |||
482 | 223 | def on_raw_metadata_clicked(self, widget, data=None): | 284 | def on_raw_metadata_clicked(self, widget, data=None): |
483 | 224 | """Show raw metadata for a path choosen by the user.""" | 285 | """Show raw metadata for a path choosen by the user.""" |
484 | 286 | res = self.file_chooser.run() | ||
485 | 287 | self.file_chooser.hide() | ||
486 | 288 | if res != gtk.FILE_CHOOSER_ACTION_OPEN: | ||
487 | 289 | return | ||
488 | 290 | |||
489 | 291 | self.last_metadata_path = self.file_chooser.get_filename() | ||
490 | 292 | self.sd.get_metadata(path=self.last_metadata_path) | ||
491 | 293 | self.raw_metadata_view.hide() | ||
492 | 294 | self.raw_metadata_image.show() | ||
493 | 295 | self._start_loading(self.raw_metadata_image) | ||
494 | 296 | self.raw_metadata_dialog.show() | ||
495 | 225 | 297 | ||
496 | 226 | def on_status_icon_activate(self, widget, data=None): | 298 | def on_status_icon_activate(self, widget, data=None): |
497 | 227 | """Systray icon was clicked.""" | 299 | """Systray icon was clicked.""" |
498 | @@ -242,6 +314,7 @@ | |||
499 | 242 | 314 | ||
500 | 243 | for v in self.volumes: | 315 | for v in self.volumes: |
501 | 244 | v.set_sensitive(True) | 316 | v.set_sensitive(True) |
502 | 317 | self.raw_metadata.set_sensitive(True) | ||
503 | 245 | 318 | ||
504 | 246 | self._update_queues_and_status(self.sd.current_state) | 319 | self._update_queues_and_status(self.sd.current_state) |
505 | 247 | 320 | ||
506 | @@ -285,6 +358,7 @@ | |||
507 | 285 | """Callback'ed when syncadaemon is offline.""" | 358 | """Callback'ed when syncadaemon is offline.""" |
508 | 286 | self._activate_indicator(self.is_online, sensitive=False) | 359 | self._activate_indicator(self.is_online, sensitive=False) |
509 | 287 | 360 | ||
510 | 361 | @log(logger) | ||
511 | 288 | def on_status_changed(self, name=None, description=None, | 362 | def on_status_changed(self, name=None, description=None, |
512 | 289 | is_error=False, is_connected=True, is_online=True, | 363 | is_error=False, is_connected=True, is_online=True, |
513 | 290 | queues=None, connection=None): | 364 | queues=None, connection=None): |
514 | @@ -295,17 +369,22 @@ | |||
515 | 295 | text = self.STATUS['initial'] | 369 | text = self.STATUS['initial'] |
516 | 296 | self.status_label.set_text(text) | 370 | self.status_label.set_text(text) |
517 | 297 | 371 | ||
519 | 298 | def _on_queue_changed(self, queue_name, items, *args, **kwargs): | 372 | @log(logger) |
520 | 373 | def _on_queue_changed(self, queue_name, items, must_highlight): | ||
521 | 299 | """Callback'ed when a queue changed.""" | 374 | """Callback'ed when a queue changed.""" |
522 | 300 | if items is None: | 375 | if items is None: |
523 | 301 | items = [] | 376 | items = [] |
524 | 302 | 377 | ||
525 | 378 | markup = lambda value: self.CURRENT_ROW % value \ | ||
526 | 379 | if must_highlight and value is not None else value | ||
527 | 303 | queue_label = getattr(self, '%sq_label' % queue_name) | 380 | queue_label = getattr(self, '%sq_label' % queue_name) |
528 | 304 | queue_view = getattr(self, '%sq_view' % queue_name) | 381 | queue_view = getattr(self, '%sq_view' % queue_name) |
529 | 305 | queue_store = getattr(self, '%sq_store' % queue_name) | 382 | queue_store = getattr(self, '%sq_store' % queue_name) |
530 | 306 | queue_store.clear() | 383 | queue_store.clear() |
532 | 307 | for item in items: | 384 | for i, item in enumerate(items): |
533 | 308 | row = (item.operation, item.path, item.share, item.node) | 385 | row = (item.operation, item.path, item.share, item.node) |
534 | 386 | if i == 0: | ||
535 | 387 | row = map(markup, row) | ||
536 | 309 | queue_store.append(row) | 388 | queue_store.append(row) |
537 | 310 | 389 | ||
538 | 311 | items_len = len(items) | 390 | items_len = len(items) |
539 | @@ -317,11 +396,27 @@ | |||
540 | 317 | 396 | ||
541 | 318 | def on_content_queue_changed(self, items, *args, **kwargs): | 397 | def on_content_queue_changed(self, items, *args, **kwargs): |
542 | 319 | """Callback'ed when syncadaemon's content queue changed.""" | 398 | """Callback'ed when syncadaemon's content queue changed.""" |
544 | 320 | self._on_queue_changed(CONTENT_QUEUE, items, args, kwargs) | 399 | state = self.sd.current_state |
545 | 400 | highlight = state.processing_content and state.is_online | ||
546 | 401 | self._on_queue_changed(CONTENT_QUEUE, items, highlight) | ||
547 | 321 | 402 | ||
548 | 322 | def on_meta_queue_changed(self, items, *args, **kwargs): | 403 | def on_meta_queue_changed(self, items, *args, **kwargs): |
549 | 323 | """Callback'ed when syncadaemon's meta queue changed.""" | 404 | """Callback'ed when syncadaemon's meta queue changed.""" |
551 | 324 | self._on_queue_changed(META_QUEUE, items, args, kwargs) | 405 | state = self.sd.current_state |
552 | 406 | highlight = state.processing_meta and state.is_online | ||
553 | 407 | self._on_queue_changed(META_QUEUE, items, highlight) | ||
554 | 408 | |||
555 | 409 | @log(logger) | ||
556 | 410 | def on_metadata_ready(self, path, metadata): | ||
557 | 411 | """Lower layer has the requested metadata for 'path'.""" | ||
558 | 412 | logger.debug('on_metadata_ready: path: %r, last_metadata_path: %r', | ||
559 | 413 | path, self.last_metadata_path) | ||
560 | 414 | if path != self.last_metadata_path: | ||
561 | 415 | return | ||
562 | 416 | self.raw_metadata_image.hide() | ||
563 | 417 | self.raw_metadata_view.show() | ||
564 | 418 | text = '\n'.join('%s: %s' % i for i in metadata.iteritems()) | ||
565 | 419 | self.raw_metadata_view.get_buffer().set_text(text) | ||
566 | 325 | 420 | ||
567 | 326 | # custom | 421 | # custom |
568 | 327 | 422 | ||
569 | @@ -340,7 +435,8 @@ | |||
570 | 340 | self.on_meta_queue_changed(self.sd.meta_queue) | 435 | self.on_meta_queue_changed(self.sd.meta_queue) |
571 | 341 | self.on_content_queue_changed(self.sd.content_queue) | 436 | self.on_content_queue_changed(self.sd.content_queue) |
572 | 342 | self.on_status_changed(name=state.name, description=state.description, | 437 | self.on_status_changed(name=state.name, description=state.description, |
574 | 343 | queues=state.queues, connection=state.connection) | 438 | queues=state.queues, |
575 | 439 | connection=state.connection) | ||
576 | 344 | 440 | ||
577 | 345 | def update(self): | 441 | def update(self): |
578 | 346 | """Update UI based on SD current state.""" | 442 | """Update UI based on SD current state.""" |
579 | 347 | 443 | ||
580 | === removed file 'magicicada/cmd_pof.py' | |||
581 | --- magicicada/cmd_pof.py 2010-06-08 10:53:02 +0000 | |||
582 | +++ magicicada/cmd_pof.py 1970-01-01 00:00:00 +0000 | |||
583 | @@ -1,190 +0,0 @@ | |||
584 | 1 | # DISCLAIMER: this is a proof of concept, we need tests for this! | ||
585 | 2 | # Author: Facundo Batista | ||
586 | 3 | |||
587 | 4 | # this always first | ||
588 | 5 | from twisted.internet import glib2reactor | ||
589 | 6 | glib2reactor.install() | ||
590 | 7 | |||
591 | 8 | import functools | ||
592 | 9 | import re | ||
593 | 10 | import time | ||
594 | 11 | |||
595 | 12 | import dbus | ||
596 | 13 | from dbus.mainloop.glib import DBusGMainLoop | ||
597 | 14 | from twisted.internet import reactor | ||
598 | 15 | |||
599 | 16 | from ubuntuone.syncdaemon import tools | ||
600 | 17 | |||
601 | 18 | # main connected stuff | ||
602 | 19 | loop = DBusGMainLoop(set_as_default=True) | ||
603 | 20 | bus = dbus.SessionBus(mainloop=loop) | ||
604 | 21 | sync_daemon_tool = tools.SyncDaemonTool(bus) | ||
605 | 22 | |||
606 | 23 | DATE_FMT = "%Y-%m-%d" | ||
607 | 24 | TIME_FMT = "%H:%M:%S" | ||
608 | 25 | |||
609 | 26 | RE_OP_LISTDIR = re.compile("ListDir\(share_id=(.*?), node_id=(.*?), .*") | ||
610 | 27 | RE_OP_UNLINK = re.compile("Unlink\(share_id=(.*?), node_id=(.*?), .*") | ||
611 | 28 | RE_OP_MAKEFILE = re.compile( | ||
612 | 29 | "MakeFile\(share_id=(.*?), parent_id=(.*?), name=(.*?), .*") | ||
613 | 30 | |||
614 | 31 | class DBusHandler(object): | ||
615 | 32 | def __init__(self): | ||
616 | 33 | # status changed | ||
617 | 34 | bus.add_signal_receiver(self.on_status_changed, | ||
618 | 35 | dbus_interface='com.ubuntuone.SyncDaemon.Status', | ||
619 | 36 | signal_name='StatusChanged') | ||
620 | 37 | # content queue changed | ||
621 | 38 | bus.add_signal_receiver(self.on_CQ_changed, | ||
622 | 39 | dbus_interface='com.ubuntuone.SyncDaemon.Status', | ||
623 | 40 | signal_name='ContentQueueChanged') | ||
624 | 41 | |||
625 | 42 | # upload or download | ||
626 | 43 | for s in ('DownloadStarted', 'DownloadFinished', | ||
627 | 44 | 'UploadStarted', 'UploadFinished'): | ||
628 | 45 | bus.add_signal_receiver(functools.partial(self.on_updown_activ, s), | ||
629 | 46 | signal_name=s) | ||
630 | 47 | |||
631 | 48 | # get the first one | ||
632 | 49 | d = sync_daemon_tool.get_status() | ||
633 | 50 | d.addCallback(self.on_status_changed) | ||
634 | 51 | |||
635 | 52 | self._date = None | ||
636 | 53 | self._last_CQ_data = None | ||
637 | 54 | self._last_MQ_data = None | ||
638 | 55 | self._state = None | ||
639 | 56 | self._mqcaller = None | ||
640 | 57 | |||
641 | 58 | def on_updown_activ(self, signal, *data): | ||
642 | 59 | """Upload or download activity.""" | ||
643 | 60 | path = data[0] | ||
644 | 61 | if signal in ('UploadStarted', 'DownloadStarted'): | ||
645 | 62 | self._show("{0}: {1}".format(signal, path)) | ||
646 | 63 | else: | ||
647 | 64 | self._show("{0}: {1}".format(signal, path)) | ||
648 | 65 | |||
649 | 66 | def on_CQ_changed(self, data): | ||
650 | 67 | """Content Queue changed, update it.""" | ||
651 | 68 | def show_cq(data): | ||
652 | 69 | """Show the CONTENT queue.""" | ||
653 | 70 | if data == self._last_CQ_data: | ||
654 | 71 | return | ||
655 | 72 | |||
656 | 73 | # it changed! | ||
657 | 74 | self._last_CQ_data = data | ||
658 | 75 | self._show("Content Queue:") | ||
659 | 76 | if data: | ||
660 | 77 | for d in data: | ||
661 | 78 | print " ", self._format_CQ_data(d) | ||
662 | 79 | else: | ||
663 | 80 | print " (empty)" | ||
664 | 81 | |||
665 | 82 | d = sync_daemon_tool.waiting_content() | ||
666 | 83 | d.addCallback(show_cq) | ||
667 | 84 | |||
668 | 85 | def _show(self, message): | ||
669 | 86 | date = time.strftime(DATE_FMT) | ||
670 | 87 | if date != self._date: | ||
671 | 88 | self._date = date | ||
672 | 89 | print "-- {0} --".format(self._date) | ||
673 | 90 | |||
674 | 91 | now = time.strftime(TIME_FMT) | ||
675 | 92 | print "{0} {1}".format(now, message) | ||
676 | 93 | |||
677 | 94 | def _format_MQ_data(self, data): | ||
678 | 95 | """Format the meta queue information.""" | ||
679 | 96 | if data.startswith("ListDir"): | ||
680 | 97 | m = RE_OP_LISTDIR.match(data) | ||
681 | 98 | if not m: | ||
682 | 99 | m = "Got a ListDir, but failed to match: %r" % (data,) | ||
683 | 100 | raise ValueError(m) | ||
684 | 101 | share_id, node_id = m.groups() | ||
685 | 102 | name = self._find_out_path(share_id, node_id) | ||
686 | 103 | return "ListDir: {0} ({1}:{2})".format(name, share_id, node_id) | ||
687 | 104 | |||
688 | 105 | if data.startswith("Unlink"): | ||
689 | 106 | m = RE_OP_UNLINK.match(data) | ||
690 | 107 | if not m: | ||
691 | 108 | m = "Got an Unlink, but failed to match: %r" % (data,) | ||
692 | 109 | raise ValueError(m) | ||
693 | 110 | share_id, node_id = m.groups() | ||
694 | 111 | name = self._find_out_path(share_id, node_id) | ||
695 | 112 | return "Unlink: {0} ({1}:{2})".format(name, share_id, node_id) | ||
696 | 113 | |||
697 | 114 | if data.startswith("MakeFile"): | ||
698 | 115 | m = RE_OP_MAKEFILE.match(data) | ||
699 | 116 | if not m: | ||
700 | 117 | m = "Got a Makefile, but failed to match: %r" % (data,) | ||
701 | 118 | raise ValueError(m) | ||
702 | 119 | share_id, parent_id, name = m.groups() | ||
703 | 120 | parent = self._find_out_path(share_id, parent_id) | ||
704 | 121 | return "MakeFile: {0} (in {1})".format(name, parent) | ||
705 | 122 | |||
706 | 123 | # these operations are very simple | ||
707 | 124 | if data in ('GetPublicFiles', 'AccountInquiry', 'FreeSpaceInquiry', | ||
708 | 125 | 'ListVolumes', 'ListShares'): | ||
709 | 126 | return data | ||
710 | 127 | |||
711 | 128 | return "Op? {0}".format(data) | ||
712 | 129 | |||
713 | 130 | def _format_CQ_data(self, data): | ||
714 | 131 | """Format the content queue information.""" | ||
715 | 132 | return "{operation}: {path} ({share}:{node})".format(**data) | ||
716 | 133 | |||
717 | 134 | def _find_out_path(self, share_id, node_id): | ||
718 | 135 | """Curse the destiny!""" | ||
719 | 136 | return "?" | ||
720 | 137 | |||
721 | 138 | def on_status_changed(self, state): | ||
722 | 139 | """Show the state nicely.""" | ||
723 | 140 | self._state = state | ||
724 | 141 | if state["is_error"]: | ||
725 | 142 | print "State: Error!" | ||
726 | 143 | return | ||
727 | 144 | |||
728 | 145 | # normal | ||
729 | 146 | self._show("State: {name} Q: {queues} C: {connection}".format( | ||
730 | 147 | **state)) | ||
731 | 148 | self._check_MQ() | ||
732 | 149 | |||
733 | 150 | def _check_MQ(self): | ||
734 | 151 | """Check MQ if we should.""" | ||
735 | 152 | # check if we have something to show in MQ! | ||
736 | 153 | if self._state['name'] != 'QUEUE_MANAGER' or self._state['queues'] \ | ||
737 | 154 | not in ('WORKING_ON_METADATA', 'WORKING_ON_BOTH'): | ||
738 | 155 | return | ||
739 | 156 | |||
740 | 157 | # we have a previous call later running? | ||
741 | 158 | if self._mqcaller is not None and self._mqcaller.active(): | ||
742 | 159 | self._mqcaller.cancel() | ||
743 | 160 | |||
744 | 161 | def show_mq(data): | ||
745 | 162 | """Show the META queue.""" | ||
746 | 163 | if data == self._last_MQ_data: | ||
747 | 164 | return | ||
748 | 165 | |||
749 | 166 | # it changed! | ||
750 | 167 | self._last_MQ_data = data | ||
751 | 168 | self._show("Meta Queue:") | ||
752 | 169 | if data: | ||
753 | 170 | for d in data: | ||
754 | 171 | print " ", self._format_MQ_data(d) | ||
755 | 172 | else: | ||
756 | 173 | print " (empty)" | ||
757 | 174 | |||
758 | 175 | d = sync_daemon_tool.waiting_metadata() | ||
759 | 176 | d.addCallback(show_mq) | ||
760 | 177 | |||
761 | 178 | self._mqcaller = reactor.callLater(1, self._check_MQ) | ||
762 | 179 | |||
763 | 180 | def main(): | ||
764 | 181 | print "Check if it's running..." | ||
765 | 182 | if not tools.is_running(): | ||
766 | 183 | print "ERROR: SD is not running!" | ||
767 | 184 | reactor.stop() | ||
768 | 185 | |||
769 | 186 | sh = DBusHandler() | ||
770 | 187 | |||
771 | 188 | if __name__ == "__main__": | ||
772 | 189 | reactor.callWhenRunning(main) | ||
773 | 190 | reactor.run() | ||
774 | 191 | 0 | ||
775 | === modified file 'magicicada/dbusiface.py' | |||
776 | --- magicicada/dbusiface.py 2010-06-08 10:53:02 +0000 | |||
777 | +++ magicicada/dbusiface.py 2010-07-09 18:33:43 +0000 | |||
778 | @@ -32,6 +32,8 @@ | |||
779 | 32 | # log! | 32 | # log! |
780 | 33 | logger = logging.getLogger('magicicada.dbusiface') | 33 | logger = logging.getLogger('magicicada.dbusiface') |
781 | 34 | 34 | ||
782 | 35 | # we use here camel case names, because this variables are used later as | ||
783 | 36 | # classes, so pylint: disable-msg=C0103 | ||
784 | 35 | QueueData = collections.namedtuple('QueueData', 'operation path share node') | 37 | QueueData = collections.namedtuple('QueueData', 'operation path share node') |
785 | 36 | FolderData = collections.namedtuple('FolderData', | 38 | FolderData = collections.namedtuple('FolderData', |
786 | 37 | 'node path suggested_path subscribed volume') | 39 | 'node path suggested_path subscribed volume') |
787 | @@ -50,14 +52,23 @@ | |||
788 | 50 | "(Move)\(share_id=(.*?), node_id=(.*?), old_parent_id=(.*?), " | 52 | "(Move)\(share_id=(.*?), node_id=(.*?), old_parent_id=(.*?), " |
789 | 51 | "new_parent_id=(.*?), new_name=(.*?)\)") | 53 | "new_parent_id=(.*?), new_name=(.*?)\)") |
790 | 52 | 54 | ||
791 | 55 | # DBus exceptions store the type inside, as a string :| | ||
792 | 56 | DBUSERR_NOREPLY = 'org.freedesktop.DBus.Error.NoReply' | ||
793 | 57 | DBUSERR_NAMENOOWNER = 'org.freedesktop.DBus.Error.NameHasNoOwner' | ||
794 | 58 | DBUSERR_PYKEYERROR = 'org.freedesktop.DBus.Python.KeyError' | ||
795 | 59 | |||
796 | 60 | # some constants | ||
797 | 61 | NOT_SYNCHED_PATH = "Not a valid path!" | ||
798 | 62 | |||
799 | 53 | 63 | ||
800 | 54 | def _is_retry_exception(err): | 64 | def _is_retry_exception(err): |
801 | 55 | """Check if the exception is a retry one.""" | 65 | """Check if the exception is a retry one.""" |
802 | 56 | if isinstance(err, dbus.exceptions.DBusException): | 66 | if isinstance(err, dbus.exceptions.DBusException): |
804 | 57 | if err.get_dbus_name() == 'org.freedesktop.DBus.Error.NoReply': | 67 | if err.get_dbus_name() == DBUSERR_NOREPLY: |
805 | 58 | return True | 68 | return True |
806 | 59 | return False | 69 | return False |
807 | 60 | 70 | ||
808 | 71 | |||
809 | 61 | def retryable(func): | 72 | def retryable(func): |
810 | 62 | """Call the function until its deferred succeed (max 5 times).""" | 73 | """Call the function until its deferred succeed (max 5 times).""" |
811 | 63 | 74 | ||
812 | @@ -68,7 +79,7 @@ | |||
813 | 68 | while opportunities: | 79 | while opportunities: |
814 | 69 | try: | 80 | try: |
815 | 70 | res = yield func(*a, **k) | 81 | res = yield func(*a, **k) |
817 | 71 | except Exception, err: | 82 | except Exception, err: # pylint: disable-msg=W0703 |
818 | 72 | opportunities -= 1 | 83 | opportunities -= 1 |
819 | 73 | if opportunities == 0 or not _is_retry_exception(err): | 84 | if opportunities == 0 or not _is_retry_exception(err): |
820 | 74 | raise | 85 | raise |
821 | @@ -99,6 +110,8 @@ | |||
822 | 99 | (self._on_name_owner_changed, None, 'NameOwnerChanged'), | 110 | (self._on_name_owner_changed, None, 'NameOwnerChanged'), |
823 | 100 | (self._on_folder_created, 'Folders', 'FolderCreated'), | 111 | (self._on_folder_created, 'Folders', 'FolderCreated'), |
824 | 101 | (self._on_folder_deleted, 'Folders', 'FolderDeleted'), | 112 | (self._on_folder_deleted, 'Folders', 'FolderDeleted'), |
825 | 113 | (self._on_folder_subscribed, 'Folders', 'FolderSubscribed'), | ||
826 | 114 | (self._on_folder_unsubscribed, 'Folders', 'FolderUnSubscribed'), | ||
827 | 102 | (self._on_share_created, 'Shares', 'ShareCreated'), | 115 | (self._on_share_created, 'Shares', 'ShareCreated'), |
828 | 103 | (self._on_share_deleted, 'Shares', 'ShareDeleted'), | 116 | (self._on_share_deleted, 'Shares', 'ShareDeleted'), |
829 | 104 | (self._on_share_changed, 'Shares', 'ShareChanged'), | 117 | (self._on_share_changed, 'Shares', 'ShareChanged'), |
830 | @@ -114,7 +127,6 @@ | |||
831 | 114 | signal_name=signal_name) | 127 | signal_name=signal_name) |
832 | 115 | self._dbus_matches.append((match, dbus_interface, signal_name)) | 128 | self._dbus_matches.append((match, dbus_interface, signal_name)) |
833 | 116 | 129 | ||
834 | 117 | |||
835 | 118 | def shutdown(self): | 130 | def shutdown(self): |
836 | 119 | """Shut down the SyncDaemon.""" | 131 | """Shut down the SyncDaemon.""" |
837 | 120 | logger.info("DBus interface going down") | 132 | logger.info("DBus interface going down") |
838 | @@ -180,6 +192,16 @@ | |||
839 | 180 | logger.info("Received Folder deleted") | 192 | logger.info("Received Folder deleted") |
840 | 181 | self.msd.on_sd_folders_changed() | 193 | self.msd.on_sd_folders_changed() |
841 | 182 | 194 | ||
842 | 195 | def _on_folder_subscribed(self, _): | ||
843 | 196 | """Call the SD callback.""" | ||
844 | 197 | logger.info("Received Folder subscribed") | ||
845 | 198 | self.msd.on_sd_folders_changed() | ||
846 | 199 | |||
847 | 200 | def _on_folder_unsubscribed(self, _): | ||
848 | 201 | """Call the SD callback.""" | ||
849 | 202 | logger.info("Received Folder unsubscribed") | ||
850 | 203 | self.msd.on_sd_folders_changed() | ||
851 | 204 | |||
852 | 183 | def _on_share_created(self, _): | 205 | def _on_share_created(self, _): |
853 | 184 | """Call the SD callback.""" | 206 | """Call the SD callback.""" |
854 | 185 | logger.info("Received Share created") | 207 | logger.info("Received Share created") |
855 | @@ -198,6 +220,7 @@ | |||
856 | 198 | @retryable | 220 | @retryable |
857 | 199 | def get_content_queue(self): | 221 | def get_content_queue(self): |
858 | 200 | """Get the content queue from SDT.""" | 222 | """Get the content queue from SDT.""" |
859 | 223 | |||
860 | 201 | def process(data): | 224 | def process(data): |
861 | 202 | """Enhance data format.""" | 225 | """Enhance data format.""" |
862 | 203 | logger.info("Processing Content Queue items (%d)", len(data)) | 226 | logger.info("Processing Content Queue items (%d)", len(data)) |
863 | @@ -217,31 +240,32 @@ | |||
864 | 217 | def _parse_mq(self, data): | 240 | def _parse_mq(self, data): |
865 | 218 | """Parse MetaQueue string to extract its data.""" | 241 | """Parse MetaQueue string to extract its data.""" |
866 | 219 | if data in ('AccountInquiry', 'FreeSpaceInquiry', 'GetPublicFiles', | 242 | if data in ('AccountInquiry', 'FreeSpaceInquiry', 'GetPublicFiles', |
868 | 220 | 'ListShares', 'ListVolumes', 'Query'): | 243 | 'ListShares', 'ListVolumes', 'Query', |
869 | 244 | 'ChangePublicAccess', 'AnswerShare'): | ||
870 | 221 | return QueueData(operation=data, path=None, node=None, share=None) | 245 | return QueueData(operation=data, path=None, node=None, share=None) |
871 | 222 | 246 | ||
872 | 223 | m = RE_OP_LISTDIR.match(data) | 247 | m = RE_OP_LISTDIR.match(data) |
873 | 224 | if m: | 248 | if m: |
874 | 225 | op, share, node = m.groups() | 249 | op, share, node = m.groups() |
876 | 226 | path = '?' # we should get the real path, no API now | 250 | path = '?' # we should get the real path, no API now |
877 | 227 | return QueueData(operation=op, path=path, node=node, share=share) | 251 | return QueueData(operation=op, path=path, node=node, share=share) |
878 | 228 | 252 | ||
879 | 229 | m = RE_OP_MAKEFILE.match(data) | 253 | m = RE_OP_MAKEFILE.match(data) |
880 | 230 | if m: | 254 | if m: |
881 | 231 | op, share, parent, name = m.groups() | 255 | op, share, parent, name = m.groups() |
883 | 232 | path = '/?.../' + name # we should get the real path, no API now | 256 | path = '/?.../' + name # we should get the real path, no API now |
884 | 233 | return QueueData(operation=op, path=path, node=None, share=share) | 257 | return QueueData(operation=op, path=path, node=None, share=share) |
885 | 234 | 258 | ||
886 | 235 | m = RE_OP_MAKEDIR.match(data) | 259 | m = RE_OP_MAKEDIR.match(data) |
887 | 236 | if m: | 260 | if m: |
888 | 237 | op, share, parent, name = m.groups() | 261 | op, share, parent, name = m.groups() |
890 | 238 | path = '/?.../' + name # we should get the real path, no API now | 262 | path = '/?.../' + name # we should get the real path, no API now |
891 | 239 | return QueueData(operation=op, path=path, node=None, share=share) | 263 | return QueueData(operation=op, path=path, node=None, share=share) |
892 | 240 | 264 | ||
893 | 241 | m = RE_OP_UNLINK.match(data) | 265 | m = RE_OP_UNLINK.match(data) |
894 | 242 | if m: | 266 | if m: |
895 | 243 | op, share, node, = m.groups() | 267 | op, share, node, = m.groups() |
897 | 244 | path = '?' # we should get the real path, no API now | 268 | path = '?' # we should get the real path, no API now |
898 | 245 | return QueueData(operation=op, path=path, node=node, share=share) | 269 | return QueueData(operation=op, path=path, node=node, share=share) |
899 | 246 | 270 | ||
900 | 247 | m = RE_OP_MOVE.match(data) | 271 | m = RE_OP_MOVE.match(data) |
901 | @@ -262,6 +286,7 @@ | |||
902 | 262 | @retryable | 286 | @retryable |
903 | 263 | def get_meta_queue(self): | 287 | def get_meta_queue(self): |
904 | 264 | """Get the meta queue from SDT.""" | 288 | """Get the meta queue from SDT.""" |
905 | 289 | |||
906 | 265 | def process(data): | 290 | def process(data): |
907 | 266 | """Enhance data format.""" | 291 | """Enhance data format.""" |
908 | 267 | logger.info("Processing Meta Queue items (%d)", len(data)) | 292 | logger.info("Processing Meta Queue items (%d)", len(data)) |
909 | @@ -280,6 +305,7 @@ | |||
910 | 280 | @retryable | 305 | @retryable |
911 | 281 | def get_folders(self): | 306 | def get_folders(self): |
912 | 282 | """Get the folders info from SDT.""" | 307 | """Get the folders info from SDT.""" |
913 | 308 | |||
914 | 283 | def process(data): | 309 | def process(data): |
915 | 284 | """Enhance data format.""" | 310 | """Enhance data format.""" |
916 | 285 | logger.info("Processing Folders items (%d)", len(data)) | 311 | logger.info("Processing Folders items (%d)", len(data)) |
917 | @@ -323,8 +349,7 @@ | |||
918 | 323 | try: | 349 | try: |
919 | 324 | self._bus.get_name_owner('com.ubuntuone.SyncDaemon') | 350 | self._bus.get_name_owner('com.ubuntuone.SyncDaemon') |
920 | 325 | except dbus.exceptions.DBusException, err: | 351 | except dbus.exceptions.DBusException, err: |
923 | 326 | if err.get_dbus_name() != \ | 352 | if err.get_dbus_name() != DBUSERR_NAMENOOWNER: |
922 | 327 | 'org.freedesktop.DBus.Error.NameHasNoOwner': | ||
924 | 328 | raise | 353 | raise |
925 | 329 | started = False | 354 | started = False |
926 | 330 | else: | 355 | else: |
927 | @@ -359,6 +384,7 @@ | |||
928 | 359 | @retryable | 384 | @retryable |
929 | 360 | def get_shares_to_me(self): | 385 | def get_shares_to_me(self): |
930 | 361 | """Get the shares to me ('shares') info from SDT.""" | 386 | """Get the shares to me ('shares') info from SDT.""" |
931 | 387 | |||
932 | 362 | def process(data): | 388 | def process(data): |
933 | 363 | """Enhance data format.""" | 389 | """Enhance data format.""" |
934 | 364 | logger.info("Processing Shares To Me items (%d)", len(data)) | 390 | logger.info("Processing Shares To Me items (%d)", len(data)) |
935 | @@ -372,6 +398,7 @@ | |||
936 | 372 | @retryable | 398 | @retryable |
937 | 373 | def get_shares_to_others(self): | 399 | def get_shares_to_others(self): |
938 | 374 | """Get the shares to others ('shared') info from SDT.""" | 400 | """Get the shares to others ('shared') info from SDT.""" |
939 | 401 | |||
940 | 375 | def process(data): | 402 | def process(data): |
941 | 376 | """Enhance data format.""" | 403 | """Enhance data format.""" |
942 | 377 | logger.info("Processing Shares To Others items (%d)", len(data)) | 404 | logger.info("Processing Shares To Others items (%d)", len(data)) |
943 | @@ -381,3 +408,24 @@ | |||
944 | 381 | d = self.sync_daemon_tool.list_shared() | 408 | d = self.sync_daemon_tool.list_shared() |
945 | 382 | d.addCallback(process) | 409 | d.addCallback(process) |
946 | 383 | return d | 410 | return d |
947 | 411 | |||
948 | 412 | @retryable | ||
949 | 413 | def get_metadata(self, path): | ||
950 | 414 | """Return the raw metadata.""" | ||
951 | 415 | logger.info("Getting metadata for %r", path) | ||
952 | 416 | |||
953 | 417 | def fix_failure(failure): | ||
954 | 418 | """Get the failure and return a nice message.""" | ||
955 | 419 | if failure.check(dbus.exceptions.DBusException): | ||
956 | 420 | if failure.value.get_dbus_name() == DBUSERR_PYKEYERROR: | ||
957 | 421 | return NOT_SYNCHED_PATH | ||
958 | 422 | return failure | ||
959 | 423 | |||
960 | 424 | def process(metadata): | ||
961 | 425 | """Process the metadata.""" | ||
962 | 426 | logger.debug("Got metadata for path %r: %r", path, metadata) | ||
963 | 427 | return dict(metadata) | ||
964 | 428 | |||
965 | 429 | d = self.sync_daemon_tool.get_metadata(path) | ||
966 | 430 | d.addCallbacks(process, fix_failure) | ||
967 | 431 | return d | ||
968 | 384 | 432 | ||
969 | === modified file 'magicicada/helpers.py' | |||
970 | --- magicicada/helpers.py 2010-06-08 10:53:02 +0000 | |||
971 | +++ magicicada/helpers.py 2010-07-09 18:33:43 +0000 | |||
972 | @@ -13,18 +13,15 @@ | |||
973 | 13 | 13 | ||
974 | 14 | import gtk | 14 | import gtk |
975 | 15 | import os | 15 | import os |
976 | 16 | import sys | ||
977 | 17 | 16 | ||
978 | 18 | from functools import wraps | 17 | from functools import wraps |
979 | 19 | 18 | ||
980 | 20 | from magicicada.magicicadaconfig import get_data_file | 19 | from magicicada.magicicadaconfig import get_data_file |
981 | 21 | 20 | ||
982 | 22 | import gettext | ||
983 | 23 | from gettext import gettext as _ | ||
984 | 24 | gettext.textdomain('magicicada') | ||
985 | 25 | 21 | ||
986 | 26 | NO_OP = lambda *a, **kw: None | 22 | NO_OP = lambda *a, **kw: None |
987 | 27 | 23 | ||
988 | 24 | |||
989 | 28 | def get_builder(builder_file_name): | 25 | def get_builder(builder_file_name): |
990 | 29 | """Return a fully-instantiated gtk.Builder instance from specified ui file. | 26 | """Return a fully-instantiated gtk.Builder instance from specified ui file. |
991 | 30 | 27 | ||
992 | @@ -41,21 +38,37 @@ | |||
993 | 41 | builder.add_from_file(ui_filename) | 38 | builder.add_from_file(ui_filename) |
994 | 42 | return builder | 39 | return builder |
995 | 43 | 40 | ||
1011 | 44 | def print_debug(f): | 41 | |
1012 | 45 | """Print debug info for 'f'.""" | 42 | def log(logger): |
1013 | 46 | 43 | """Log input/ouput info for 'f' using 'logger'.""" | |
1014 | 47 | @wraps(f) | 44 | |
1015 | 48 | def inner(*args, **kwargs): | 45 | def decorator(f): |
1016 | 49 | """Wrap f.""" | 46 | """The decorator per se.""" |
1017 | 50 | sys.stderr.write('Calling %s %s %s\n' % (f.__name__, args, kwargs)) | 47 | |
1018 | 51 | result = f(*args, **kwargs) | 48 | @wraps(f) |
1019 | 52 | return result | 49 | def inner(*args, **kwargs): |
1020 | 53 | 50 | """Wrap 'f', log input args and result using 'logger'.""" | |
1021 | 54 | return inner | 51 | name = f.__name__ |
1022 | 55 | 52 | result = None | |
1023 | 56 | # from | 53 | logger.debug("Calling '%s' with args '%s' and kwargs '%s'.", |
1024 | 57 | # http://code.activestate.com/recipes/577081-humanized-representation-of-a-number-of-bytes/ | 54 | name, args, kwargs) |
1025 | 58 | def humanize_bytes(bytes, precision=1): | 55 | try: |
1026 | 56 | result = f(*args, **kwargs) | ||
1027 | 57 | except Exception: # pylint: disable-msg=W0703 | ||
1028 | 58 | logger.exception('%s failed with exception:', name) | ||
1029 | 59 | logger.debug("Returning from '%s' with result '%s'.", name, result) | ||
1030 | 60 | return result | ||
1031 | 61 | |||
1032 | 62 | return inner | ||
1033 | 63 | |||
1034 | 64 | return decorator | ||
1035 | 65 | |||
1036 | 66 | |||
1037 | 67 | # from http://code.activestate.com/recipes/ | ||
1038 | 68 | # 577081-humanized-representation-of-a-number-of-bytes/ | ||
1039 | 69 | |||
1040 | 70 | |||
1041 | 71 | def humanize_bytes(numbytes, precision=1): | ||
1042 | 59 | """Return a humanized string representation of a number of bytes. | 72 | """Return a humanized string representation of a number of bytes. |
1043 | 60 | 73 | ||
1044 | 61 | Assumes `from __future__ import division`. | 74 | Assumes `from __future__ import division`. |
1045 | @@ -83,11 +96,12 @@ | |||
1046 | 83 | (1<<30L, 'GB'), | 96 | (1<<30L, 'GB'), |
1047 | 84 | (1<<20L, 'MB'), | 97 | (1<<20L, 'MB'), |
1048 | 85 | (1<<10L, 'kB'), | 98 | (1<<10L, 'kB'), |
1052 | 86 | (1, 'bytes') | 99 | (1, 'bytes')) |
1053 | 87 | ) | 100 | |
1054 | 88 | if bytes == 1: | 101 | if numbytes == 1: |
1055 | 89 | return '1 byte' | 102 | return '1 byte' |
1056 | 90 | for factor, suffix in abbrevs: | 103 | for factor, suffix in abbrevs: |
1058 | 91 | if bytes >= factor: | 104 | if numbytes >= factor: |
1059 | 92 | break | 105 | break |
1061 | 93 | return '%.*f %s' % (precision, bytes / factor, suffix) | 106 | # pylint: disable-msg=W0631 |
1062 | 107 | return '%.*f %s' % (precision, numbytes / factor, suffix) | ||
1063 | 94 | 108 | ||
1064 | === modified file 'magicicada/logger.py' | |||
1065 | --- magicicada/logger.py 2010-06-08 10:53:02 +0000 | |||
1066 | +++ magicicada/logger.py 2010-07-09 18:33:43 +0000 | |||
1067 | @@ -53,4 +53,3 @@ | |||
1068 | 53 | '%Y-%m-%d %H:%M:%S') | 53 | '%Y-%m-%d %H:%M:%S') |
1069 | 54 | handler.setFormatter(formatter) | 54 | handler.setFormatter(formatter) |
1070 | 55 | logger.setLevel(logging.DEBUG) | 55 | logger.setLevel(logging.DEBUG) |
1071 | 56 | |||
1072 | 57 | 56 | ||
1073 | === modified file 'magicicada/magicicadaconfig.py' | |||
1074 | --- magicicada/magicicadaconfig.py 2010-06-08 10:53:02 +0000 | |||
1075 | +++ magicicada/magicicadaconfig.py 2010-07-09 18:33:43 +0000 | |||
1076 | @@ -3,13 +3,15 @@ | |||
1077 | 3 | # This file is in the public domain | 3 | # This file is in the public domain |
1078 | 4 | ### END LICENSE | 4 | ### END LICENSE |
1079 | 5 | 5 | ||
1080 | 6 | """Magicicada configuration file.""" | ||
1081 | 7 | |||
1082 | 6 | # THIS IS Magicicada CONFIGURATION FILE | 8 | # THIS IS Magicicada CONFIGURATION FILE |
1083 | 7 | # YOU CAN PUT THERE SOME GLOBAL VALUE | 9 | # YOU CAN PUT THERE SOME GLOBAL VALUE |
1084 | 8 | # Do not touch unless you know what you're doing. | 10 | # Do not touch unless you know what you're doing. |
1085 | 9 | # you're warned :) | 11 | # you're warned :) |
1086 | 10 | 12 | ||
1087 | 11 | __all__ = [ | 13 | __all__ = [ |
1089 | 12 | 'project_path_not_found', | 14 | 'ProjectPathNotFound', |
1090 | 13 | 'get_data_file', | 15 | 'get_data_file', |
1091 | 14 | 'get_data_path', | 16 | 'get_data_path', |
1092 | 15 | ] | 17 | ] |
1093 | @@ -21,11 +23,8 @@ | |||
1094 | 21 | 23 | ||
1095 | 22 | import os | 24 | import os |
1096 | 23 | 25 | ||
1097 | 24 | import gettext | ||
1098 | 25 | from gettext import gettext as _ | ||
1099 | 26 | gettext.textdomain('magicicada') | ||
1100 | 27 | 26 | ||
1102 | 28 | class project_path_not_found(Exception): | 27 | class ProjectPathNotFound(Exception): |
1103 | 29 | """Raised when we can't find the project directory.""" | 28 | """Raised when we can't find the project directory.""" |
1104 | 30 | 29 | ||
1105 | 31 | 30 | ||
1106 | @@ -53,6 +52,6 @@ | |||
1107 | 53 | 52 | ||
1108 | 54 | abs_data_path = os.path.abspath(path) | 53 | abs_data_path = os.path.abspath(path) |
1109 | 55 | if not os.path.exists(abs_data_path): | 54 | if not os.path.exists(abs_data_path): |
1111 | 56 | raise project_path_not_found | 55 | raise ProjectPathNotFound |
1112 | 57 | 56 | ||
1113 | 58 | return abs_data_path | 57 | return abs_data_path |
1114 | 59 | 58 | ||
1115 | === modified file 'magicicada/syncdaemon.py' | |||
1116 | --- magicicada/syncdaemon.py 2010-06-08 10:53:02 +0000 | |||
1117 | +++ magicicada/syncdaemon.py 2010-07-09 18:33:43 +0000 | |||
1118 | @@ -25,14 +25,19 @@ | |||
1119 | 25 | from magicicada.dbusiface import DBusInterface | 25 | from magicicada.dbusiface import DBusInterface |
1120 | 26 | from magicicada.helpers import NO_OP | 26 | from magicicada.helpers import NO_OP |
1121 | 27 | 27 | ||
1122 | 28 | |||
1123 | 28 | # log! | 29 | # log! |
1124 | 29 | logger = logging.getLogger('magicicada.syncdaemon') | 30 | logger = logging.getLogger('magicicada.syncdaemon') |
1125 | 30 | 31 | ||
1126 | 31 | 32 | ||
1127 | 32 | class State(object): | 33 | class State(object): |
1128 | 33 | """Hold the state of SD.""" | 34 | """Hold the state of SD.""" |
1131 | 34 | _attrs = ['name', 'description', 'is_error', 'is_connected', | 35 | |
1132 | 35 | 'is_online', 'queues', 'connection', 'is_started'] | 36 | _attrs = ['name', 'description', 'is_error', 'is_connected', |
1133 | 37 | 'is_online', 'queues', 'connection', 'is_started'] | ||
1134 | 38 | |||
1135 | 39 | _meta = ('WORKING_ON_METADATA', 'WORKING_ON_BOTH') | ||
1136 | 40 | _content = ('WORKING_ON_CONTENT', 'WORKING_ON_BOTH') | ||
1137 | 36 | 41 | ||
1138 | 37 | def __init__(self): | 42 | def __init__(self): |
1139 | 38 | # starting defaults | 43 | # starting defaults |
1140 | @@ -47,12 +52,16 @@ | |||
1141 | 47 | 52 | ||
1142 | 48 | def __getattribute__(self, name): | 53 | def __getattribute__(self, name): |
1143 | 49 | """Return the value if there.""" | 54 | """Return the value if there.""" |
1145 | 50 | if name[0] == "_": | 55 | if name[0] == "_" or name == 'set': |
1146 | 51 | return object.__getattribute__(self, name) | 56 | return object.__getattribute__(self, name) |
1147 | 57 | elif name == 'processing_meta': | ||
1148 | 58 | return self.__dict__['queues'] in self._meta | ||
1149 | 59 | elif name == 'processing_content': | ||
1150 | 60 | return self.__dict__['queues'] in self._content | ||
1151 | 52 | else: | 61 | else: |
1152 | 53 | return self.__dict__[name] | 62 | return self.__dict__[name] |
1153 | 54 | 63 | ||
1155 | 55 | def _set(self, **data): | 64 | def set(self, **data): |
1156 | 56 | """Set the attributes from data, if allowed.""" | 65 | """Set the attributes from data, if allowed.""" |
1157 | 57 | for name, value in data.iteritems(): | 66 | for name, value in data.iteritems(): |
1158 | 58 | if name not in self._attrs: | 67 | if name not in self._attrs: |
1159 | @@ -97,6 +106,7 @@ | |||
1160 | 97 | self.on_folders_changed_callback = NO_OP | 106 | self.on_folders_changed_callback = NO_OP |
1161 | 98 | self.on_shares_to_me_changed_callback = NO_OP | 107 | self.on_shares_to_me_changed_callback = NO_OP |
1162 | 99 | self.on_shares_to_others_changed_callback = NO_OP | 108 | self.on_shares_to_others_changed_callback = NO_OP |
1163 | 109 | self.on_metadata_ready_callback = None # mandatory | ||
1164 | 100 | 110 | ||
1165 | 101 | # mq needs to be polled to know progress | 111 | # mq needs to be polled to know progress |
1166 | 102 | self._mqcaller = None | 112 | self._mqcaller = None |
1167 | @@ -104,11 +114,10 @@ | |||
1168 | 104 | 114 | ||
1169 | 105 | # load initial data if ubuntuone-client already started | 115 | # load initial data if ubuntuone-client already started |
1170 | 106 | if self.dbus.is_sd_started(): | 116 | if self.dbus.is_sd_started(): |
1172 | 107 | self.current_state._set(is_started=True) | 117 | self.current_state.set(is_started=True) |
1173 | 108 | self._get_initial_data() | 118 | self._get_initial_data() |
1174 | 109 | else: | 119 | else: |
1177 | 110 | self.current_state._set(is_started=False) | 120 | self.current_state.set(is_started=False) |
1176 | 111 | |||
1178 | 112 | 121 | ||
1179 | 113 | def shutdown(self): | 122 | def shutdown(self): |
1180 | 114 | """Shut down the SyncDaemon.""" | 123 | """Shut down the SyncDaemon.""" |
1181 | @@ -165,14 +174,14 @@ | |||
1182 | 165 | def on_sd_name_owner_changed(self, now_active): | 174 | def on_sd_name_owner_changed(self, now_active): |
1183 | 166 | """SyncDaemon name owner changed.""" | 175 | """SyncDaemon name owner changed.""" |
1184 | 167 | logger.info("SD Name Owner changed: %s", now_active) | 176 | logger.info("SD Name Owner changed: %s", now_active) |
1186 | 168 | self.current_state._set(is_started=now_active) | 177 | self.current_state.set(is_started=now_active) |
1187 | 169 | 178 | ||
1188 | 170 | def set_status(name, description): | 179 | def set_status(name, description): |
1189 | 171 | """Set status after the name owner change.""" | 180 | """Set status after the name owner change.""" |
1190 | 172 | d = dict(name=name, description=description, is_error=False, | 181 | d = dict(name=name, description=description, is_error=False, |
1191 | 173 | is_connected=False, is_online=False, queues='', | 182 | is_connected=False, is_online=False, queues='', |
1192 | 174 | connection='') | 183 | connection='') |
1194 | 175 | self.current_state._set(**d) | 184 | self.current_state.set(**d) |
1195 | 176 | 185 | ||
1196 | 177 | if now_active: | 186 | if now_active: |
1197 | 178 | set_status('STARTED', 'ubuntuone-client just started') | 187 | set_status('STARTED', 'ubuntuone-client just started') |
1198 | @@ -189,6 +198,7 @@ | |||
1199 | 189 | 198 | ||
1200 | 190 | def _send_status_changed(self, name, description, is_error, is_connected, | 199 | def _send_status_changed(self, name, description, is_error, is_connected, |
1201 | 191 | is_online, queues, connection): | 200 | is_online, queues, connection): |
1202 | 201 | """Send status changed signal.""" | ||
1203 | 192 | logger.debug(" new status: name=%r, description=%r, is_error=%s, " | 202 | logger.debug(" new status: name=%r, description=%r, is_error=%s, " |
1204 | 193 | "is_connected=%s, is_online=%s, queues=%r, connection=%r", | 203 | "is_connected=%s, is_online=%s, queues=%r, connection=%r", |
1205 | 194 | name, description, is_error, is_connected, is_online, | 204 | name, description, is_error, is_connected, is_online, |
1206 | @@ -205,7 +215,7 @@ | |||
1207 | 205 | self.on_offline_callback() | 215 | self.on_offline_callback() |
1208 | 206 | 216 | ||
1209 | 207 | # set current state to new values and call status changed cb | 217 | # set current state to new values and call status changed cb |
1211 | 208 | self.current_state._set(name=name, description=description, | 218 | self.current_state.set(name=name, description=description, |
1212 | 209 | is_error=is_error, is_connected=is_connected, | 219 | is_error=is_error, is_connected=is_connected, |
1213 | 210 | is_online=is_online, queues=queues, | 220 | is_online=is_online, queues=queues, |
1214 | 211 | connection=connection) | 221 | connection=connection) |
1215 | @@ -213,7 +223,8 @@ | |||
1216 | 213 | is_online, queues, connection) | 223 | is_online, queues, connection) |
1217 | 214 | 224 | ||
1218 | 215 | # if corresponds, supervise MQ | 225 | # if corresponds, supervise MQ |
1220 | 216 | self._check_mq() | 226 | if self._mqcaller is None: |
1221 | 227 | self._check_mq() | ||
1222 | 217 | 228 | ||
1223 | 218 | @defer.inlineCallbacks | 229 | @defer.inlineCallbacks |
1224 | 219 | def on_sd_content_queue_changed(self): | 230 | def on_sd_content_queue_changed(self): |
1225 | @@ -226,27 +237,30 @@ | |||
1226 | 226 | self.content_queue_changed_callback(new_cq) | 237 | self.content_queue_changed_callback(new_cq) |
1227 | 227 | 238 | ||
1228 | 228 | @defer.inlineCallbacks | 239 | @defer.inlineCallbacks |
1229 | 240 | def _get_mq_data(self): | ||
1230 | 241 | """Get MQ info and call back if needed.""" | ||
1231 | 242 | new_mq = yield self.dbus.get_meta_queue() | ||
1232 | 243 | if new_mq != self.meta_queue: | ||
1233 | 244 | logger.info("SD Meta Queue changed: %d items", len(new_mq)) | ||
1234 | 245 | self.meta_queue = new_mq | ||
1235 | 246 | self.meta_queue_changed_callback(new_mq) | ||
1236 | 247 | |||
1237 | 229 | def _check_mq(self): | 248 | def _check_mq(self): |
1238 | 230 | """Check MQ if we should.""" | 249 | """Check MQ if we should.""" |
1242 | 231 | state = self.current_state | 250 | # cancel previous (if any) and check again later |
1243 | 232 | if state.queues not in ('WORKING_ON_METADATA', 'WORKING_ON_BOTH'): | 251 | if self._mqcaller is not None and self._mqcaller.active(): |
1244 | 233 | logger.info("Check MQ called but States not in MQ") | 252 | self._mqcaller.cancel() |
1245 | 253 | |||
1246 | 254 | if not self.current_state.processing_meta: | ||
1247 | 255 | logger.info("Check MQ called, States not in MQ, call a last time") | ||
1248 | 256 | self._mqcaller = None | ||
1249 | 257 | self._get_mq_data() | ||
1250 | 234 | else: | 258 | else: |
1251 | 235 | logger.info("Asking for MQ information") | 259 | logger.info("Asking for MQ information") |
1252 | 236 | 260 | ||
1253 | 237 | # have we a previous call later still running? | ||
1254 | 238 | if self._mqcaller is not None and self._mqcaller.active(): | ||
1255 | 239 | self._mqcaller.cancel() | ||
1256 | 240 | |||
1257 | 241 | # get the info | 261 | # get the info |
1266 | 242 | new_mq = yield self.dbus.get_meta_queue() | 262 | self._get_mq_data() |
1267 | 243 | 263 | ||
1260 | 244 | if new_mq != self.meta_queue: | ||
1261 | 245 | logger.info("SD Meta Queue changed: %d items", len(new_mq)) | ||
1262 | 246 | self.meta_queue = new_mq | ||
1263 | 247 | self.meta_queue_changed_callback(new_mq) | ||
1264 | 248 | |||
1265 | 249 | # check again later | ||
1268 | 250 | self._mqcaller = reactor.callLater(self._mq_poll_time, | 264 | self._mqcaller = reactor.callLater(self._mq_poll_time, |
1269 | 251 | self._check_mq) | 265 | self._check_mq) |
1270 | 252 | 266 | ||
1271 | @@ -270,3 +284,11 @@ | |||
1272 | 270 | """Tell the SyncDaemon that the user wants it to disconnect.""" | 284 | """Tell the SyncDaemon that the user wants it to disconnect.""" |
1273 | 271 | logger.info("Telling u1.SD to disconnect") | 285 | logger.info("Telling u1.SD to disconnect") |
1274 | 272 | self.dbus.disconnect() | 286 | self.dbus.disconnect() |
1275 | 287 | |||
1276 | 288 | def get_metadata(self, path): | ||
1277 | 289 | """Get the metadata for given path.""" | ||
1278 | 290 | if self.on_metadata_ready_callback is None: | ||
1279 | 291 | raise ValueError("Missing the mandatory cback for get_metadata.") | ||
1280 | 292 | |||
1281 | 293 | d = self.dbus.get_metadata(path) | ||
1282 | 294 | d.addCallback(lambda resp: self.on_metadata_ready_callback(path, resp)) | ||
1283 | 273 | 295 | ||
1284 | === modified file 'magicicada/tests/helpers.py' | |||
1285 | --- magicicada/tests/helpers.py 2010-06-08 10:53:02 +0000 | |||
1286 | +++ magicicada/tests/helpers.py 2010-07-09 18:33:43 +0000 | |||
1287 | @@ -36,14 +36,18 @@ | |||
1288 | 36 | def check(self, level, msg): | 36 | def check(self, level, msg): |
1289 | 37 | """Check that something is logged.""" | 37 | """Check that something is logged.""" |
1290 | 38 | for rec in self.records: | 38 | for rec in self.records: |
1292 | 39 | if rec.levelname == level and rec.message == msg: | 39 | if rec.levelname == level and str(msg) in rec.message: |
1293 | 40 | return True | 40 | return True |
1294 | 41 | return False | 41 | return False |
1295 | 42 | 42 | ||
1297 | 43 | def check_inf(self, msg): | 43 | def check_error(self, msg): |
1298 | 44 | """Shortcut for ERROR check.""" | ||
1299 | 45 | return self.check('ERROR', msg) | ||
1300 | 46 | |||
1301 | 47 | def check_info(self, msg): | ||
1302 | 44 | """Shortcut for INFO check.""" | 48 | """Shortcut for INFO check.""" |
1303 | 45 | return self.check('INFO', msg) | 49 | return self.check('INFO', msg) |
1304 | 46 | 50 | ||
1306 | 47 | def check_dbg(self, msg): | 51 | def check_debug(self, msg): |
1307 | 48 | """Shortcut for DEBUG check.""" | 52 | """Shortcut for DEBUG check.""" |
1308 | 49 | return self.check('DEBUG', msg) | 53 | return self.check('DEBUG', msg) |
1309 | 50 | 54 | ||
1310 | === modified file 'magicicada/tests/test_dbusiface.py' | |||
1311 | --- magicicada/tests/test_dbusiface.py 2010-06-08 10:53:02 +0000 | |||
1312 | +++ magicicada/tests/test_dbusiface.py 2010-07-09 18:33:43 +0000 | |||
1313 | @@ -28,8 +28,13 @@ | |||
1314 | 28 | from magicicada.tests.helpers import MementoHandler | 28 | from magicicada.tests.helpers import MementoHandler |
1315 | 29 | 29 | ||
1316 | 30 | 30 | ||
1317 | 31 | # It's ok to access private data in the test suite | ||
1318 | 32 | # pylint: disable-msg=W0212 | ||
1319 | 33 | |||
1320 | 34 | |||
1321 | 31 | class FakeSessionBus(object): | 35 | class FakeSessionBus(object): |
1322 | 32 | """Fake Session Bus.""" | 36 | """Fake Session Bus.""" |
1323 | 37 | |||
1324 | 33 | def __init__(self, **kwargs): | 38 | def __init__(self, **kwargs): |
1325 | 34 | self._callbacks = {} | 39 | self._callbacks = {} |
1326 | 35 | self.fake_name_owner = "foo" | 40 | self.fake_name_owner = "foo" |
1327 | @@ -43,8 +48,12 @@ | |||
1328 | 43 | del self._callbacks[(dbus_interface, signal_name)] | 48 | del self._callbacks[(dbus_interface, signal_name)] |
1329 | 44 | 49 | ||
1330 | 45 | def get_name_owner(self, name): | 50 | def get_name_owner(self, name): |
1332 | 46 | """Fakes the response of the method.""" | 51 | """Fake the response of the method.""" |
1333 | 47 | assert name == 'com.ubuntuone.SyncDaemon' | 52 | assert name == 'com.ubuntuone.SyncDaemon' |
1334 | 53 | |||
1335 | 54 | # will return a string, or raise an exception instance, never | ||
1336 | 55 | # raise a string | ||
1337 | 56 | # pylint: disable-msg=W0701 | ||
1338 | 48 | if isinstance(self.fake_name_owner, str): | 57 | if isinstance(self.fake_name_owner, str): |
1339 | 49 | return self.fake_name_owner | 58 | return self.fake_name_owner |
1340 | 50 | else: | 59 | else: |
1341 | @@ -53,6 +62,7 @@ | |||
1342 | 53 | 62 | ||
1343 | 54 | class CallLoguer(object): | 63 | class CallLoguer(object): |
1344 | 55 | """Class that logs the methods called.""" | 64 | """Class that logs the methods called.""" |
1345 | 65 | |||
1346 | 56 | def __init__(self): | 66 | def __init__(self): |
1347 | 57 | self._called_method = None, () | 67 | self._called_method = None, () |
1348 | 58 | self._fake_response = None | 68 | self._fake_response = None |
1349 | @@ -62,19 +72,25 @@ | |||
1350 | 62 | if name[0] == "_": | 72 | if name[0] == "_": |
1351 | 63 | return object.__getattribute__(self, name) | 73 | return object.__getattribute__(self, name) |
1352 | 64 | else: | 74 | else: |
1353 | 75 | |||
1354 | 65 | def f(*args): | 76 | def f(*args): |
1355 | 77 | """Fake function.""" | ||
1356 | 66 | setattr(self, "_called_method", (name, args)) | 78 | setattr(self, "_called_method", (name, args)) |
1357 | 67 | if self._fake_response is None: | 79 | if self._fake_response is None: |
1358 | 68 | # no hurt in returning a deferred, it may be needed | 80 | # no hurt in returning a deferred, it may be needed |
1359 | 69 | return defer.Deferred() | 81 | return defer.Deferred() |
1360 | 70 | methname, response = self._fake_response | 82 | methname, response = self._fake_response |
1361 | 71 | assert methname == name | 83 | assert methname == name |
1363 | 72 | return response | 84 | if isinstance(response, Exception): |
1364 | 85 | return defer.fail(response) | ||
1365 | 86 | else: | ||
1366 | 87 | return defer.succeed(response) | ||
1367 | 73 | return f | 88 | return f |
1368 | 74 | 89 | ||
1369 | 75 | 90 | ||
1370 | 76 | class FakeSDTool(CallLoguer): | 91 | class FakeSDTool(CallLoguer): |
1371 | 77 | """Fake real SyncDaemonTool.""" | 92 | """Fake real SyncDaemonTool.""" |
1372 | 93 | |||
1373 | 78 | def __init__(self, _): | 94 | def __init__(self, _): |
1374 | 79 | CallLoguer.__init__(self) | 95 | CallLoguer.__init__(self) |
1375 | 80 | 96 | ||
1376 | @@ -104,9 +120,9 @@ | |||
1377 | 104 | return called_args | 120 | return called_args |
1378 | 105 | 121 | ||
1379 | 106 | def fake_sdt_response(self, method_name, response): | 122 | def fake_sdt_response(self, method_name, response): |
1383 | 107 | """Fakes SDT answer in deferred mode.""" | 123 | """Fake SDT answer in deferred mode.""" |
1384 | 108 | self.dbus.sync_daemon_tool._fake_response = (method_name, | 124 | self.dbus.sync_daemon_tool._fake_response = (method_name, response) |
1385 | 109 | defer.succeed(response)) | 125 | |
1386 | 110 | 126 | ||
1387 | 111 | class TestSignalHooking(SafeTests): | 127 | class TestSignalHooking(SafeTests): |
1388 | 112 | """Signal hooking tests. | 128 | """Signal hooking tests. |
1389 | @@ -114,6 +130,7 @@ | |||
1390 | 114 | We can not check if the methods are really called, because DBus holds the | 130 | We can not check if the methods are really called, because DBus holds the |
1391 | 115 | method object itself, so no chance in monkeypatching. | 131 | method object itself, so no chance in monkeypatching. |
1392 | 116 | """ | 132 | """ |
1393 | 133 | |||
1394 | 117 | def _get_hooked(self, iface, signal): | 134 | def _get_hooked(self, iface, signal): |
1395 | 118 | """Return the hooked method if any.""" | 135 | """Return the hooked method if any.""" |
1396 | 119 | if iface is None: | 136 | if iface is None: |
1397 | @@ -152,6 +169,16 @@ | |||
1398 | 152 | self.assertEqual(self._get_hooked('Folders', 'FolderDeleted'), | 169 | self.assertEqual(self._get_hooked('Folders', 'FolderDeleted'), |
1399 | 153 | self.dbus._on_folder_deleted) | 170 | self.dbus._on_folder_deleted) |
1400 | 154 | 171 | ||
1401 | 172 | def test_folder_subscribed_changed(self): | ||
1402 | 173 | """Test folder subscribed changed callback.""" | ||
1403 | 174 | self.assertEqual(self._get_hooked('Folders', 'FolderSubscribed'), | ||
1404 | 175 | self.dbus._on_folder_subscribed) | ||
1405 | 176 | |||
1406 | 177 | def test_folder_unsubscribed_changed(self): | ||
1407 | 178 | """Test folder unsubscribed changed callback.""" | ||
1408 | 179 | self.assertEqual(self._get_hooked('Folders', 'FolderUnSubscribed'), | ||
1409 | 180 | self.dbus._on_folder_unsubscribed) | ||
1410 | 181 | |||
1411 | 155 | def test_share_created(self): | 182 | def test_share_created(self): |
1412 | 156 | """Test share created callback.""" | 183 | """Test share created callback.""" |
1413 | 157 | self.assertEqual(self._get_hooked('Shares', 'ShareCreated'), | 184 | self.assertEqual(self._get_hooked('Shares', 'ShareCreated'), |
1414 | @@ -188,7 +215,7 @@ | |||
1415 | 188 | 215 | ||
1416 | 189 | 216 | ||
1417 | 190 | class TestDataProcessingStatus(SafeTests): | 217 | class TestDataProcessingStatus(SafeTests): |
1419 | 191 | """Processes Status before sending it to SyncDaemon.""" | 218 | """Process Status before sending it to SyncDaemon.""" |
1420 | 192 | 219 | ||
1421 | 193 | @defer.inlineCallbacks | 220 | @defer.inlineCallbacks |
1422 | 194 | def test_get_status(self): | 221 | def test_get_status(self): |
1423 | @@ -224,7 +251,7 @@ | |||
1424 | 224 | 251 | ||
1425 | 225 | 252 | ||
1426 | 226 | class TestDataProcessingNameOwner(SafeTests): | 253 | class TestDataProcessingNameOwner(SafeTests): |
1428 | 227 | """Processes Name Owner data before sending it to SyncDaemon.""" | 254 | """Process Name Owner data before sending it to SyncDaemon.""" |
1429 | 228 | 255 | ||
1430 | 229 | def test_name_owner_changed_no_syncdaemon(self): | 256 | def test_name_owner_changed_no_syncdaemon(self): |
1431 | 230 | """Test name owner changed callback.""" | 257 | """Test name owner changed callback.""" |
1432 | @@ -245,7 +272,7 @@ | |||
1433 | 245 | 272 | ||
1434 | 246 | 273 | ||
1435 | 247 | class TestDataProcessingCQ(SafeTests): | 274 | class TestDataProcessingCQ(SafeTests): |
1437 | 248 | """Processes CQ data before sending it to SyncDaemon.""" | 275 | """Process CQ data before sending it to SyncDaemon.""" |
1438 | 249 | 276 | ||
1439 | 250 | @defer.inlineCallbacks | 277 | @defer.inlineCallbacks |
1440 | 251 | def test_nodata(self): | 278 | def test_nodata(self): |
1441 | @@ -288,7 +315,7 @@ | |||
1442 | 288 | 315 | ||
1443 | 289 | 316 | ||
1444 | 290 | class TestDataProcessingMQ(SafeTests): | 317 | class TestDataProcessingMQ(SafeTests): |
1446 | 291 | """Processes MQ data before sending it to SyncDaemon.""" | 318 | """Process MQ data before sending it to SyncDaemon.""" |
1447 | 292 | 319 | ||
1448 | 293 | @defer.inlineCallbacks | 320 | @defer.inlineCallbacks |
1449 | 294 | def test_nodata(self): | 321 | def test_nodata(self): |
1450 | @@ -461,9 +488,33 @@ | |||
1451 | 461 | self.assertEqual(data.share, 'a') | 488 | self.assertEqual(data.share, 'a') |
1452 | 462 | self.assertEqual(data.node, 'b') | 489 | self.assertEqual(data.node, 'b') |
1453 | 463 | 490 | ||
1454 | 491 | @defer.inlineCallbacks | ||
1455 | 492 | def test_ChangePublicAccess(self): | ||
1456 | 493 | """Test meta with ChangePublicAccess.""" | ||
1457 | 494 | cmd = 'ChangePublicAccess' | ||
1458 | 495 | self.fake_sdt_response('waiting_metadata', [cmd]) | ||
1459 | 496 | rcv = yield self.dbus.get_meta_queue() | ||
1460 | 497 | data = rcv[0] | ||
1461 | 498 | self.assertEqual(data.operation, 'ChangePublicAccess') | ||
1462 | 499 | self.assertEqual(data.path, None) | ||
1463 | 500 | self.assertEqual(data.share, None) | ||
1464 | 501 | self.assertEqual(data.node, None) | ||
1465 | 502 | |||
1466 | 503 | @defer.inlineCallbacks | ||
1467 | 504 | def test_AnswerShare(self): | ||
1468 | 505 | """Test meta with AnswerShare.""" | ||
1469 | 506 | cmd = 'AnswerShare' | ||
1470 | 507 | self.fake_sdt_response('waiting_metadata', [cmd]) | ||
1471 | 508 | rcv = yield self.dbus.get_meta_queue() | ||
1472 | 509 | data = rcv[0] | ||
1473 | 510 | self.assertEqual(data.operation, 'AnswerShare') | ||
1474 | 511 | self.assertEqual(data.path, None) | ||
1475 | 512 | self.assertEqual(data.share, None) | ||
1476 | 513 | self.assertEqual(data.node, None) | ||
1477 | 514 | |||
1478 | 464 | 515 | ||
1479 | 465 | class TestDataProcessingFolders(SafeTests): | 516 | class TestDataProcessingFolders(SafeTests): |
1481 | 466 | """Processes Folders data before sending it to SyncDaemon.""" | 517 | """Process Folders data before sending it to SyncDaemon.""" |
1482 | 467 | 518 | ||
1483 | 468 | @defer.inlineCallbacks | 519 | @defer.inlineCallbacks |
1484 | 469 | def test_nodata(self): | 520 | def test_nodata(self): |
1485 | @@ -520,10 +571,40 @@ | |||
1486 | 520 | self.dbus._on_folder_deleted(None) | 571 | self.dbus._on_folder_deleted(None) |
1487 | 521 | self.get_msd_called("on_sd_folders_changed") | 572 | self.get_msd_called("on_sd_folders_changed") |
1488 | 522 | 573 | ||
1489 | 574 | def test_folders_changed_from_subscribed(self): | ||
1490 | 575 | """Test folders changed callback from subscribed.""" | ||
1491 | 576 | self.dbus._on_folder_subscribed(None) | ||
1492 | 577 | self.get_msd_called("on_sd_folders_changed") | ||
1493 | 578 | |||
1494 | 579 | def test_folders_changed_from_unsubscribed(self): | ||
1495 | 580 | """Test folders changed callback from unsubscribed.""" | ||
1496 | 581 | self.dbus._on_folder_unsubscribed(None) | ||
1497 | 582 | self.get_msd_called("on_sd_folders_changed") | ||
1498 | 583 | |||
1499 | 584 | |||
1500 | 585 | class TestDataProcessingMetadata(SafeTests): | ||
1501 | 586 | """Process Metadata data before sending it to SyncDaemon.""" | ||
1502 | 587 | |||
1503 | 588 | @defer.inlineCallbacks | ||
1504 | 589 | def test_info_ok(self): | ||
1505 | 590 | """Test get metadata and see response.""" | ||
1506 | 591 | md = dbus.Dictionary({'a': 3, 'c': 4}, signature=dbus.Signature('ss')) | ||
1507 | 592 | self.fake_sdt_response('get_metadata', md) | ||
1508 | 593 | rcv = yield self.dbus.get_metadata('path') | ||
1509 | 594 | self.assertEqual(rcv, dict(a=3, c=4)) | ||
1510 | 595 | |||
1511 | 596 | @defer.inlineCallbacks | ||
1512 | 597 | def test_info_bad(self): | ||
1513 | 598 | """Test get metadata and get the error.""" | ||
1514 | 599 | exc = dbus.exceptions.DBusException( | ||
1515 | 600 | name='org.freedesktop.DBus.Python.KeyError') | ||
1516 | 601 | self.fake_sdt_response('get_metadata', exc) | ||
1517 | 602 | rcv = yield self.dbus.get_metadata('not a real path') | ||
1518 | 603 | self.assertEqual(rcv, dbusiface.NOT_SYNCHED_PATH) | ||
1519 | 523 | 604 | ||
1520 | 524 | 605 | ||
1521 | 525 | class TestDataProcessingShares(SafeTests): | 606 | class TestDataProcessingShares(SafeTests): |
1523 | 526 | """Processes Shares data before sending it to SyncDaemon.""" | 607 | """Process Shares data before sending it to SyncDaemon.""" |
1524 | 527 | 608 | ||
1525 | 528 | @defer.inlineCallbacks | 609 | @defer.inlineCallbacks |
1526 | 529 | def test_sharestome_nodata(self): | 610 | def test_sharestome_nodata(self): |
1527 | @@ -693,68 +774,74 @@ | |||
1528 | 693 | 774 | ||
1529 | 694 | def test_instancing(self): | 775 | def test_instancing(self): |
1530 | 695 | """Just logged SD instancing.""" | 776 | """Just logged SD instancing.""" |
1532 | 696 | self.assertTrue(self.handler.check_inf("DBus interface starting")) | 777 | self.assertTrue(self.handler.check_info("DBus interface starting")) |
1533 | 697 | 778 | ||
1534 | 698 | def test_shutdown(self): | 779 | def test_shutdown(self): |
1535 | 699 | """Log when SD shutdowns.""" | 780 | """Log when SD shutdowns.""" |
1536 | 700 | self.dbus.shutdown() | 781 | self.dbus.shutdown() |
1538 | 701 | self.assertTrue(self.handler.check_inf("DBus interface going down")) | 782 | self.assertTrue(self.handler.check_info("DBus interface going down")) |
1539 | 702 | 783 | ||
1540 | 703 | def test_waiting_content(self): | 784 | def test_waiting_content(self): |
1541 | 704 | """Test call to waiting content.""" | 785 | """Test call to waiting content.""" |
1542 | 705 | self.dbus.get_content_queue() | 786 | self.dbus.get_content_queue() |
1544 | 706 | self.assertTrue(self.handler.check_inf("Getting content queue")) | 787 | self.assertTrue(self.handler.check_info("Getting content queue")) |
1545 | 707 | 788 | ||
1546 | 708 | def test_waiting_meta(self): | 789 | def test_waiting_meta(self): |
1547 | 709 | """Test call to waiting meta.""" | 790 | """Test call to waiting meta.""" |
1548 | 710 | self.dbus.get_meta_queue() | 791 | self.dbus.get_meta_queue() |
1550 | 711 | self.assertTrue(self.handler.check_inf("Getting meta queue")) | 792 | self.assertTrue(self.handler.check_info("Getting meta queue")) |
1551 | 712 | 793 | ||
1552 | 713 | def test_get_status(self): | 794 | def test_get_status(self): |
1553 | 714 | """Test call to status.""" | 795 | """Test call to status.""" |
1554 | 715 | self.dbus.get_status() | 796 | self.dbus.get_status() |
1556 | 716 | self.assertTrue(self.handler.check_inf("Getting status")) | 797 | self.assertTrue(self.handler.check_info("Getting status")) |
1557 | 717 | 798 | ||
1558 | 718 | def test_get_folders(self): | 799 | def test_get_folders(self): |
1559 | 719 | """Test call to folders.""" | 800 | """Test call to folders.""" |
1560 | 720 | self.dbus.get_folders() | 801 | self.dbus.get_folders() |
1562 | 721 | self.assertTrue(self.handler.check_inf("Getting folders")) | 802 | self.assertTrue(self.handler.check_info("Getting folders")) |
1563 | 803 | |||
1564 | 804 | def test_get_metadata(self): | ||
1565 | 805 | """Test call to metadata.""" | ||
1566 | 806 | self.dbus.get_metadata('path') | ||
1567 | 807 | msg = "Getting metadata for u'path'" | ||
1568 | 808 | self.assertTrue(self.handler.check_info(msg)) | ||
1569 | 722 | 809 | ||
1570 | 723 | def test_get_shares_to_me(self): | 810 | def test_get_shares_to_me(self): |
1571 | 724 | """Test call to shares to me.""" | 811 | """Test call to shares to me.""" |
1572 | 725 | self.dbus.get_shares_to_me() | 812 | self.dbus.get_shares_to_me() |
1574 | 726 | self.assertTrue(self.handler.check_inf("Getting shares to me")) | 813 | self.assertTrue(self.handler.check_info("Getting shares to me")) |
1575 | 727 | 814 | ||
1576 | 728 | def test_get_shares_to_other(self): | 815 | def test_get_shares_to_other(self): |
1577 | 729 | """Test call to shares to others.""" | 816 | """Test call to shares to others.""" |
1578 | 730 | self.dbus.get_shares_to_others() | 817 | self.dbus.get_shares_to_others() |
1580 | 731 | self.assertTrue(self.handler.check_inf("Getting shares to others")) | 818 | self.assertTrue(self.handler.check_info("Getting shares to others")) |
1581 | 732 | 819 | ||
1582 | 733 | def test_is_sd_started(self): | 820 | def test_is_sd_started(self): |
1583 | 734 | """Test call to is_sd_started.""" | 821 | """Test call to is_sd_started.""" |
1584 | 735 | self.dbus.is_sd_started() | 822 | self.dbus.is_sd_started() |
1586 | 736 | self.assertTrue(self.handler.check_inf( | 823 | self.assertTrue(self.handler.check_info( |
1587 | 737 | "Checking if SD is started: True")) | 824 | "Checking if SD is started: True")) |
1588 | 738 | 825 | ||
1589 | 739 | def test_start(self): | 826 | def test_start(self): |
1590 | 740 | """Test call to start.""" | 827 | """Test call to start.""" |
1591 | 741 | self.dbus.start() | 828 | self.dbus.start() |
1593 | 742 | self.assertTrue(self.handler.check_inf("Calling start")) | 829 | self.assertTrue(self.handler.check_info("Calling start")) |
1594 | 743 | 830 | ||
1595 | 744 | def test_quit(self): | 831 | def test_quit(self): |
1596 | 745 | """Test call to quit.""" | 832 | """Test call to quit.""" |
1597 | 746 | self.dbus.quit() | 833 | self.dbus.quit() |
1599 | 747 | self.assertTrue(self.handler.check_inf("Calling quit")) | 834 | self.assertTrue(self.handler.check_info("Calling quit")) |
1600 | 748 | 835 | ||
1601 | 749 | def test_connect(self): | 836 | def test_connect(self): |
1602 | 750 | """Test call to connect.""" | 837 | """Test call to connect.""" |
1603 | 751 | self.dbus.connect() | 838 | self.dbus.connect() |
1605 | 752 | self.assertTrue(self.handler.check_inf("Calling connect")) | 839 | self.assertTrue(self.handler.check_info("Calling connect")) |
1606 | 753 | 840 | ||
1607 | 754 | def test_disconnect(self): | 841 | def test_disconnect(self): |
1608 | 755 | """Test call to disconnect.""" | 842 | """Test call to disconnect.""" |
1609 | 756 | self.dbus.disconnect() | 843 | self.dbus.disconnect() |
1611 | 757 | self.assertTrue(self.handler.check_inf("Calling disconnect")) | 844 | self.assertTrue(self.handler.check_info("Calling disconnect")) |
1612 | 758 | 845 | ||
1613 | 759 | def test_status_changed(self): | 846 | def test_status_changed(self): |
1614 | 760 | """Test status changed callback.""" | 847 | """Test status changed callback.""" |
1615 | @@ -762,58 +849,71 @@ | |||
1616 | 762 | is_connected='True', is_online='', queues='queues', | 849 | is_connected='True', is_online='', queues='queues', |
1617 | 763 | connection='connection') | 850 | connection='connection') |
1618 | 764 | self.dbus._on_status_changed(d) | 851 | self.dbus._on_status_changed(d) |
1621 | 765 | self.assertTrue(self.handler.check_inf("Received Status changed")) | 852 | self.assertTrue(self.handler.check_info("Received Status changed")) |
1622 | 766 | self.assertTrue(self.handler.check_dbg("Status changed data: %r" % d)) | 853 | msg = "Status changed data: %r" % d |
1623 | 854 | self.assertTrue(self.handler.check_debug(msg)) | ||
1624 | 767 | 855 | ||
1625 | 768 | def test_content_queue_changed(self): | 856 | def test_content_queue_changed(self): |
1626 | 769 | """Test content queue changed callback.""" | 857 | """Test content queue changed callback.""" |
1627 | 770 | self.dbus._on_content_queue_changed("foo") | 858 | self.dbus._on_content_queue_changed("foo") |
1629 | 771 | self.assertTrue(self.handler.check_inf( | 859 | self.assertTrue(self.handler.check_info( |
1630 | 772 | "Received Content Queue changed")) | 860 | "Received Content Queue changed")) |
1631 | 773 | 861 | ||
1632 | 774 | def test_name_owner_changed_other(self): | 862 | def test_name_owner_changed_other(self): |
1633 | 775 | """Test name owner changed callback, no SD.""" | 863 | """Test name owner changed callback, no SD.""" |
1634 | 776 | self.dbus._on_name_owner_changed("other", "", "T") | 864 | self.dbus._on_name_owner_changed("other", "", "T") |
1636 | 777 | self.assertFalse(self.handler.check_inf("Received Name Owner changed")) | 865 | msg = "Received Name Owner changed" |
1637 | 866 | self.assertFalse(self.handler.check_info(msg)) | ||
1638 | 778 | 867 | ||
1639 | 779 | def test_name_owner_changed_syncdaemon(self): | 868 | def test_name_owner_changed_syncdaemon(self): |
1640 | 780 | """Test name owner changed callback, SD value ok.""" | 869 | """Test name owner changed callback, SD value ok.""" |
1641 | 781 | self.dbus._on_name_owner_changed("com.ubuntuone.SyncDaemon", "", "T") | 870 | self.dbus._on_name_owner_changed("com.ubuntuone.SyncDaemon", "", "T") |
1644 | 782 | self.assertTrue(self.handler.check_inf("Received Name Owner changed")) | 871 | self.assertTrue(self.handler.check_info("Received Name Owner changed")) |
1645 | 783 | self.assertTrue(self.handler.check_dbg("Name Owner data: u'' u'T'")) | 872 | self.assertTrue(self.handler.check_debug("Name Owner data: u'' u'T'")) |
1646 | 784 | 873 | ||
1647 | 785 | def test_name_owner_changed_yes_syncdaemon_TF(self): | 874 | def test_name_owner_changed_yes_syncdaemon_TF(self): |
1648 | 786 | """Test name owner changed callback, SD value bad.""" | 875 | """Test name owner changed callback, SD value bad.""" |
1649 | 787 | self.dbus._on_name_owner_changed("com.ubuntuone.SyncDaemon", "F", "T") | 876 | self.dbus._on_name_owner_changed("com.ubuntuone.SyncDaemon", "F", "T") |
1652 | 788 | self.assertTrue(self.handler.check_inf("Received Name Owner changed")) | 877 | self.assertTrue(self.handler.check_info("Received Name Owner changed")) |
1653 | 789 | self.assertTrue(self.handler.check_dbg("Name Owner data: u'F' u'T'")) | 878 | self.assertTrue(self.handler.check_debug("Name Owner data: u'F' u'T'")) |
1654 | 790 | self.assertTrue(self.handler.check("ERROR", | 879 | self.assertTrue(self.handler.check("ERROR", |
1655 | 791 | "Name Owner invalid data: Same bool in old and new!")) | 880 | "Name Owner invalid data: Same bool in old and new!")) |
1656 | 792 | 881 | ||
1657 | 793 | def test_folder_created_changed(self): | 882 | def test_folder_created_changed(self): |
1658 | 794 | """Test folder created changed callback.""" | 883 | """Test folder created changed callback.""" |
1659 | 795 | self.dbus._on_folder_created("foo") | 884 | self.dbus._on_folder_created("foo") |
1661 | 796 | self.assertTrue(self.handler.check_inf("Received Folder created")) | 885 | self.assertTrue(self.handler.check_info("Received Folder created")) |
1662 | 797 | 886 | ||
1663 | 798 | def test_folder_deleted_changed(self): | 887 | def test_folder_deleted_changed(self): |
1664 | 799 | """Test folder deleted changed callback.""" | 888 | """Test folder deleted changed callback.""" |
1665 | 800 | self.dbus._on_folder_deleted("foo") | 889 | self.dbus._on_folder_deleted("foo") |
1667 | 801 | self.assertTrue(self.handler.check_inf("Received Folder deleted")) | 890 | self.assertTrue(self.handler.check_info("Received Folder deleted")) |
1668 | 891 | |||
1669 | 892 | def test_folder_subscribed_changed(self): | ||
1670 | 893 | """Test folder subscribed changed callback.""" | ||
1671 | 894 | self.dbus._on_folder_subscribed("foo") | ||
1672 | 895 | self.assertTrue(self.handler.check_info("Received Folder subscribed")) | ||
1673 | 896 | |||
1674 | 897 | def test_folder_unsubscribed_changed(self): | ||
1675 | 898 | """Test folder unsubscribed changed callback.""" | ||
1676 | 899 | self.dbus._on_folder_unsubscribed("foo") | ||
1677 | 900 | self.assertTrue(self.handler.check_info( | ||
1678 | 901 | "Received Folder unsubscribed")) | ||
1679 | 802 | 902 | ||
1680 | 803 | def test_share_created(self): | 903 | def test_share_created(self): |
1681 | 804 | """Test share created callback.""" | 904 | """Test share created callback.""" |
1682 | 805 | self.dbus._on_share_created("foo") | 905 | self.dbus._on_share_created("foo") |
1684 | 806 | self.assertTrue(self.handler.check_inf("Received Share created")) | 906 | self.assertTrue(self.handler.check_info("Received Share created")) |
1685 | 807 | 907 | ||
1686 | 808 | def test_share_deleted(self): | 908 | def test_share_deleted(self): |
1687 | 809 | """Test share deleted callback.""" | 909 | """Test share deleted callback.""" |
1688 | 810 | self.dbus._on_share_deleted("foo") | 910 | self.dbus._on_share_deleted("foo") |
1690 | 811 | self.assertTrue(self.handler.check_inf("Received Share deleted")) | 911 | self.assertTrue(self.handler.check_info("Received Share deleted")) |
1691 | 812 | 912 | ||
1692 | 813 | def test_share__changed(self): | 913 | def test_share__changed(self): |
1693 | 814 | """Test share changed callback.""" | 914 | """Test share changed callback.""" |
1694 | 815 | self.dbus._on_share_changed("foo") | 915 | self.dbus._on_share_changed("foo") |
1696 | 816 | self.assertTrue(self.handler.check_inf("Received Share changed")) | 916 | self.assertTrue(self.handler.check_info("Received Share changed")) |
1697 | 817 | 917 | ||
1698 | 818 | @defer.inlineCallbacks | 918 | @defer.inlineCallbacks |
1699 | 819 | def test_content_queue_processing(self): | 919 | def test_content_queue_processing(self): |
1700 | @@ -821,9 +921,9 @@ | |||
1701 | 821 | c = dict(operation='oper', path='path', share='share', node='node') | 921 | c = dict(operation='oper', path='path', share='share', node='node') |
1702 | 822 | self.fake_sdt_response('waiting_content', [c]) | 922 | self.fake_sdt_response('waiting_content', [c]) |
1703 | 823 | yield self.dbus.get_content_queue() | 923 | yield self.dbus.get_content_queue() |
1705 | 824 | self.assertTrue(self.handler.check_inf( | 924 | self.assertTrue(self.handler.check_info( |
1706 | 825 | "Processing Content Queue items (1)")) | 925 | "Processing Content Queue items (1)")) |
1708 | 826 | self.assertTrue(self.handler.check_dbg( | 926 | self.assertTrue(self.handler.check_debug( |
1709 | 827 | " Content Queue data: %s" % c)) | 927 | " Content Queue data: %s" % c)) |
1710 | 828 | 928 | ||
1711 | 829 | @defer.inlineCallbacks | 929 | @defer.inlineCallbacks |
1712 | @@ -831,9 +931,9 @@ | |||
1713 | 831 | """Test with one item in the queue.""" | 931 | """Test with one item in the queue.""" |
1714 | 832 | self.fake_sdt_response('waiting_metadata', ['ListShares']) | 932 | self.fake_sdt_response('waiting_metadata', ['ListShares']) |
1715 | 833 | yield self.dbus.get_meta_queue() | 933 | yield self.dbus.get_meta_queue() |
1717 | 834 | self.assertTrue(self.handler.check_inf( | 934 | self.assertTrue(self.handler.check_info( |
1718 | 835 | "Processing Meta Queue items (1)")) | 935 | "Processing Meta Queue items (1)")) |
1720 | 836 | self.assertTrue(self.handler.check_dbg( | 936 | self.assertTrue(self.handler.check_debug( |
1721 | 837 | " Meta Queue data: u'ListShares'")) | 937 | " Meta Queue data: u'ListShares'")) |
1722 | 838 | 938 | ||
1723 | 839 | @defer.inlineCallbacks | 939 | @defer.inlineCallbacks |
1724 | @@ -843,8 +943,18 @@ | |||
1725 | 843 | suggested_path=u'sgp', type='UDF', volume_id='vid') | 943 | suggested_path=u'sgp', type='UDF', volume_id='vid') |
1726 | 844 | self.fake_sdt_response('get_folders', [d]) | 944 | self.fake_sdt_response('get_folders', [d]) |
1727 | 845 | yield self.dbus.get_folders() | 945 | yield self.dbus.get_folders() |
1730 | 846 | self.assertTrue(self.handler.check_inf("Processing Folders items (1)")) | 946 | msg = "Processing Folders items (1)" |
1731 | 847 | self.assertTrue(self.handler.check_dbg(" Folders data: %r" % d)) | 947 | self.assertTrue(self.handler.check_info(msg)) |
1732 | 948 | self.assertTrue(self.handler.check_debug(" Folders data: %r" % d)) | ||
1733 | 949 | |||
1734 | 950 | @defer.inlineCallbacks | ||
1735 | 951 | def test_metadata_processing(self): | ||
1736 | 952 | """Test get metadata.""" | ||
1737 | 953 | d = dict(lot_of_data="I don't care") | ||
1738 | 954 | self.fake_sdt_response('get_metadata', d) | ||
1739 | 955 | yield self.dbus.get_metadata('path') | ||
1740 | 956 | self.assertTrue(self.handler.check_debug( | ||
1741 | 957 | "Got metadata for path u'path': %r" % d)) | ||
1742 | 848 | 958 | ||
1743 | 849 | @defer.inlineCallbacks | 959 | @defer.inlineCallbacks |
1744 | 850 | def test_sharestome_processing(self): | 960 | def test_sharestome_processing(self): |
1745 | @@ -855,9 +965,9 @@ | |||
1746 | 855 | volume_id=u'vol', type=u'Share') | 965 | volume_id=u'vol', type=u'Share') |
1747 | 856 | self.fake_sdt_response('get_shares', [d]) | 966 | self.fake_sdt_response('get_shares', [d]) |
1748 | 857 | yield self.dbus.get_shares_to_me() | 967 | yield self.dbus.get_shares_to_me() |
1750 | 858 | self.assertTrue(self.handler.check_inf( | 968 | self.assertTrue(self.handler.check_info( |
1751 | 859 | "Processing Shares To Me items (1)")) | 969 | "Processing Shares To Me items (1)")) |
1753 | 860 | self.assertTrue(self.handler.check_dbg(" Share data: %r" % d)) | 970 | self.assertTrue(self.handler.check_debug(" Share data: %r" % d)) |
1754 | 861 | 971 | ||
1755 | 862 | @defer.inlineCallbacks | 972 | @defer.inlineCallbacks |
1756 | 863 | def test_sharestoothers_processing(self): | 973 | def test_sharestoothers_processing(self): |
1757 | @@ -868,16 +978,17 @@ | |||
1758 | 868 | volume_id=u'vol', type=u'Shared') | 978 | volume_id=u'vol', type=u'Shared') |
1759 | 869 | self.fake_sdt_response('list_shared', [d]) | 979 | self.fake_sdt_response('list_shared', [d]) |
1760 | 870 | yield self.dbus.get_shares_to_others() | 980 | yield self.dbus.get_shares_to_others() |
1762 | 871 | self.assertTrue(self.handler.check_inf( | 981 | self.assertTrue(self.handler.check_info( |
1763 | 872 | "Processing Shares To Others items (1)")) | 982 | "Processing Shares To Others items (1)")) |
1765 | 873 | self.assertTrue(self.handler.check_dbg(" Share data: %r" % d)) | 983 | self.assertTrue(self.handler.check_debug(" Share data: %r" % d)) |
1766 | 874 | 984 | ||
1767 | 875 | 985 | ||
1768 | 876 | class RetryDecoratorTests(TwistedTestCase): | 986 | class RetryDecoratorTests(TwistedTestCase): |
1769 | 877 | """Test the retry decorator.""" | 987 | """Test the retry decorator.""" |
1770 | 878 | 988 | ||
1771 | 879 | class Helper(object): | 989 | class Helper(object): |
1773 | 880 | """Fails some times, finally succeeds.""" | 990 | """Fail some times, finally succeed.""" |
1774 | 991 | |||
1775 | 881 | def __init__(self, limit, excep=None): | 992 | def __init__(self, limit, excep=None): |
1776 | 882 | self.cant = 0 | 993 | self.cant = 0 |
1777 | 883 | self.limit = limit | 994 | self.limit = limit |
1778 | @@ -915,7 +1026,7 @@ | |||
1779 | 915 | self.assertTrue(dbusiface._is_retry_exception(err)) | 1026 | self.assertTrue(dbusiface._is_retry_exception(err)) |
1780 | 916 | 1027 | ||
1781 | 917 | def get_decorated_func(self, func): | 1028 | def get_decorated_func(self, func): |
1783 | 918 | """Executes the test calling the received function.""" | 1029 | """Execute the test calling the received function.""" |
1784 | 919 | 1030 | ||
1785 | 920 | @dbusiface.retryable | 1031 | @dbusiface.retryable |
1786 | 921 | def f(): | 1032 | def f(): |
1787 | 922 | 1033 | ||
1788 | === modified file 'magicicada/tests/test_magicicada.py' | |||
1789 | --- magicicada/tests/test_magicicada.py 2010-06-08 10:53:02 +0000 | |||
1790 | +++ magicicada/tests/test_magicicada.py 2010-07-09 18:33:43 +0000 | |||
1791 | @@ -18,6 +18,9 @@ | |||
1792 | 18 | 18 | ||
1793 | 19 | """Tests for magicicada.""" | 19 | """Tests for magicicada.""" |
1794 | 20 | 20 | ||
1795 | 21 | import logging | ||
1796 | 22 | import sys | ||
1797 | 23 | |||
1798 | 21 | from functools import wraps | 24 | from functools import wraps |
1799 | 22 | 25 | ||
1800 | 23 | import gobject | 26 | import gobject |
1801 | @@ -26,33 +29,57 @@ | |||
1802 | 26 | 29 | ||
1803 | 27 | from twisted.trial.unittest import TestCase | 30 | from twisted.trial.unittest import TestCase |
1804 | 28 | 31 | ||
1806 | 29 | from magicicada import MagicicadaUI, CONTENT_QUEUE, META_QUEUE, syncdaemon | 32 | from magicicada import MagicicadaUI, CONTENT_QUEUE, META_QUEUE, \ |
1807 | 33 | UBUNTU_ONE_ROOT, syncdaemon | ||
1808 | 30 | from magicicada.dbusiface import QueueData, FolderData, ShareData | 34 | from magicicada.dbusiface import QueueData, FolderData, ShareData |
1810 | 31 | from magicicada.helpers import NO_OP, humanize_bytes | 35 | from magicicada.helpers import NO_OP, humanize_bytes, get_data_file |
1811 | 36 | from magicicada.tests.helpers import MementoHandler | ||
1812 | 37 | |||
1813 | 38 | |||
1814 | 39 | # It's ok to access private data in the test suite | ||
1815 | 40 | # pylint: disable-msg=W0212 | ||
1816 | 41 | # Arguments number differs from overridden method | ||
1817 | 42 | # pylint: disable-msg=W0221 | ||
1818 | 43 | |||
1819 | 32 | 44 | ||
1820 | 33 | def process_gtk_pendings(): | 45 | def process_gtk_pendings(): |
1822 | 34 | while gtk.events_pending(): gtk.main_iteration() | 46 | """Process all gtk pending events.""" |
1823 | 47 | while gtk.events_pending(): | ||
1824 | 48 | gtk.main_iteration() | ||
1825 | 49 | |||
1826 | 35 | 50 | ||
1827 | 36 | def close_dialog((dialog, test)): | 51 | def close_dialog((dialog, test)): |
1828 | 37 | """Call the 'test', close 'dialog'.""" | 52 | """Call the 'test', close 'dialog'.""" |
1837 | 38 | try: | 53 | response = gtk.RESPONSE_CLOSE |
1838 | 39 | process_gtk_pendings() | 54 | try: |
1839 | 40 | test() | 55 | process_gtk_pendings() |
1840 | 41 | process_gtk_pendings() | 56 | test() |
1841 | 42 | finally: | 57 | finally: |
1842 | 43 | dialog.response(gtk.RESPONSE_CLOSE) | 58 | dialog.response(response) |
1843 | 44 | process_gtk_pendings() | 59 | process_gtk_pendings() |
1844 | 45 | return False # do not be called again | 60 | return False # do not be called again |
1845 | 61 | |||
1846 | 62 | |||
1847 | 63 | def test_and_click((button, test)): | ||
1848 | 64 | """Call the 'test', and click 'button'.""" | ||
1849 | 65 | try: | ||
1850 | 66 | test() | ||
1851 | 67 | finally: | ||
1852 | 68 | button.clicked() | ||
1853 | 69 | return False # do not be called again | ||
1854 | 46 | 70 | ||
1855 | 47 | 71 | ||
1856 | 48 | class FakedSyncdaemon(object): | 72 | class FakedSyncdaemon(object): |
1857 | 49 | """A faked syncdaemon.""" | 73 | """A faked syncdaemon.""" |
1858 | 50 | 74 | ||
1859 | 51 | def __init__(self): | 75 | def __init__(self): |
1860 | 76 | self._meta_path = None | ||
1861 | 77 | |||
1862 | 52 | self.current_state = syncdaemon.State() | 78 | self.current_state = syncdaemon.State() |
1863 | 53 | self.meta_queue = [] | 79 | self.meta_queue = [] |
1864 | 54 | self.content_queue = [] | 80 | self.content_queue = [] |
1865 | 55 | self.folders = [] | 81 | self.folders = [] |
1866 | 82 | self.processing_meta = False | ||
1867 | 56 | 83 | ||
1868 | 57 | self.on_started_callback = NO_OP | 84 | self.on_started_callback = NO_OP |
1869 | 58 | self.on_stopped_callback = NO_OP | 85 | self.on_stopped_callback = NO_OP |
1870 | @@ -63,13 +90,16 @@ | |||
1871 | 63 | self.status_changed_callback = NO_OP | 90 | self.status_changed_callback = NO_OP |
1872 | 64 | self.content_queue_changed_callback = NO_OP | 91 | self.content_queue_changed_callback = NO_OP |
1873 | 65 | self.meta_queue_changed_callback = NO_OP | 92 | self.meta_queue_changed_callback = NO_OP |
1874 | 93 | self.on_metadata_ready_callback = None # mandatory | ||
1875 | 66 | self.shutdown = NO_OP | 94 | self.shutdown = NO_OP |
1876 | 67 | 95 | ||
1877 | 68 | self.start = lambda: setattr(self.current_state, 'is_started', True) | 96 | self.start = lambda: setattr(self.current_state, 'is_started', True) |
1878 | 69 | self.quit = lambda: setattr(self.current_state, 'is_started', False) | 97 | self.quit = lambda: setattr(self.current_state, 'is_started', False) |
1882 | 70 | self.connect = lambda: setattr(self.current_state, 'is_connected', True) | 98 | self.connect = lambda: setattr(self.current_state, |
1883 | 71 | self.disconnect = \ | 99 | 'is_connected', True) |
1884 | 72 | lambda: setattr(self.current_state, 'is_connected', False) | 100 | self.disconnect = lambda: \ |
1885 | 101 | setattr(self.current_state, 'is_connected', False) | ||
1886 | 102 | self.get_metadata = lambda path: setattr(self, '_meta_path', path) | ||
1887 | 73 | 103 | ||
1888 | 74 | 104 | ||
1889 | 75 | class MagicicadaUITestCase(TestCase): | 105 | class MagicicadaUITestCase(TestCase): |
1890 | @@ -78,13 +108,14 @@ | |||
1891 | 78 | def setUp(self): | 108 | def setUp(self): |
1892 | 79 | """Init.""" | 109 | """Init.""" |
1893 | 80 | self.ui = MagicicadaUI(syncdaemon_class=FakedSyncdaemon) | 110 | self.ui = MagicicadaUI(syncdaemon_class=FakedSyncdaemon) |
1896 | 81 | self._called = False | 111 | self.called = False |
1897 | 82 | self.set_called = lambda *args, **kwargs: setattr(self, '_called', True) | 112 | self.response = None |
1898 | 113 | self.set_called = lambda *args, **kwargs: setattr(self, 'called', True) | ||
1899 | 83 | 114 | ||
1900 | 84 | def tearDown(self): | 115 | def tearDown(self): |
1901 | 85 | """Cleanup.""" | 116 | """Cleanup.""" |
1902 | 86 | self.ui.on_main_window_destroy(self.ui.main_window) | 117 | self.ui.on_main_window_destroy(self.ui.main_window) |
1904 | 87 | self._called = False | 118 | self.called = False |
1905 | 88 | 119 | ||
1906 | 89 | def do_start(self): | 120 | def do_start(self): |
1907 | 90 | """Simulate that start fully happened.""" | 121 | """Simulate that start fully happened.""" |
1908 | @@ -106,14 +137,16 @@ | |||
1909 | 106 | result.append(data_type(**kwargs)) | 137 | result.append(data_type(**kwargs)) |
1910 | 107 | return result | 138 | return result |
1911 | 108 | 139 | ||
1913 | 109 | def assert_store_correct(self, store, items): | 140 | def assert_store_correct(self, store, items, markup=None): |
1914 | 110 | """Test that 'store' has 'items' as content.""" | 141 | """Test that 'store' has 'items' as content.""" |
1915 | 111 | msg = 'amount of rows for %s must be %s (got %s).' | 142 | msg = 'amount of rows for %s must be %s (got %s).' |
1916 | 112 | self.assertEqual(len(store), len(items), | 143 | self.assertEqual(len(store), len(items), |
1917 | 113 | msg % (store, len(items), len(store))) | 144 | msg % (store, len(items), len(store))) |
1918 | 145 | |||
1919 | 114 | # assert rows content equal to items content | 146 | # assert rows content equal to items content |
1920 | 115 | tree_iter = store.get_iter_root() | 147 | tree_iter = store.get_iter_root() |
1921 | 116 | tmp = list(reversed(items)) | 148 | tmp = list(reversed(items)) |
1922 | 149 | do_markup = markup is not None | ||
1923 | 117 | msg = "column %i ('%s') must be '%s' (got '%s' instead)" | 150 | msg = "column %i ('%s') must be '%s' (got '%s' instead)" |
1924 | 118 | while tree_iter is not None: | 151 | while tree_iter is not None: |
1925 | 119 | head = tmp.pop() | 152 | head = tmp.pop() |
1926 | @@ -122,27 +155,68 @@ | |||
1927 | 122 | expected = getattr(head, field) | 155 | expected = getattr(head, field) |
1928 | 123 | if store.get_column_type(i).name == 'gboolean': | 156 | if store.get_column_type(i).name == 'gboolean': |
1929 | 124 | expected = bool(expected) | 157 | expected = bool(expected) |
1931 | 125 | self.assertEqual(expected, actual, msg % (i, field, expected, actual)) | 158 | elif do_markup: |
1932 | 159 | expected = markup(expected) | ||
1933 | 160 | self.assertEqual(expected, actual, | ||
1934 | 161 | msg % (i, field, expected, actual)) | ||
1935 | 126 | 162 | ||
1936 | 127 | tree_iter = store.iter_next(tree_iter) | 163 | tree_iter = store.iter_next(tree_iter) |
1937 | 164 | do_markup = False # only for first row | ||
1938 | 128 | 165 | ||
1939 | 129 | def assert_indicator_disabled(self, indicator): | 166 | def assert_indicator_disabled(self, indicator): |
1940 | 130 | """Test that 'indicator' is not sensitive.""" | 167 | """Test that 'indicator' is not sensitive.""" |
1942 | 131 | self.assertFalse(indicator.is_sensitive(), 'indicator is not sensitive') | 168 | self.assertFalse(indicator.is_sensitive(), |
1943 | 169 | 'indicator must not be sensitive.') | ||
1944 | 132 | 170 | ||
1945 | 133 | def assert_indicator_ready(self, indicator): | 171 | def assert_indicator_ready(self, indicator): |
1946 | 134 | """Test that 'indicator' is sensitive and green.""" | 172 | """Test that 'indicator' is sensitive and green.""" |
1949 | 135 | self.assertTrue(indicator.is_sensitive(), 'indicator is sensitive') | 173 | self.assertTrue(indicator.is_sensitive(), |
1950 | 136 | expected = indicator.get_pixbuf() # a test on its own | 174 | 'indicator must be sensitive.') |
1951 | 175 | expected = indicator.get_pixbuf() # a test on its own | ||
1952 | 137 | self.assertEqual(self.ui.active_indicator, expected, | 176 | self.assertEqual(self.ui.active_indicator, expected, |
1954 | 138 | 'indicator is the correct pixbuf') | 177 | 'indicator must have the correct pixbuf.') |
1955 | 139 | 178 | ||
1956 | 140 | def assert_indicator_loading(self, indicator): | 179 | def assert_indicator_loading(self, indicator): |
1957 | 141 | """Test that 'indicator' is sensitive and loading.""" | 180 | """Test that 'indicator' is sensitive and loading.""" |
1960 | 142 | self.assertTrue(indicator.is_sensitive(), 'indicator is sensitive') | 181 | self.assertTrue(indicator.is_sensitive(), |
1961 | 143 | expected = indicator.get_animation() # a test on its own | 182 | 'indicator must be sensitive.') |
1962 | 183 | expected = indicator.get_animation() # a test on its own | ||
1963 | 144 | self.assertEqual(self.ui.loading_animation, expected, | 184 | self.assertEqual(self.ui.loading_animation, expected, |
1965 | 145 | 'indicator is the correct animation') | 185 | 'indicator must have the correct animation.') |
1966 | 186 | |||
1967 | 187 | def assert_widget_availability(self, widget_name, enabled=True): | ||
1968 | 188 | """Check button availability according to 'enabled'.""" | ||
1969 | 189 | widget = getattr(self.ui, widget_name) | ||
1970 | 190 | self.assertTrue(self.ui.widget_is_visible(widget), | ||
1971 | 191 | '%s should be visible' % widget_name) | ||
1972 | 192 | sensitive = widget.is_sensitive() | ||
1973 | 193 | msg = '%s should %sbe sensitive' | ||
1974 | 194 | self.assertTrue(sensitive if enabled else not sensitive, | ||
1975 | 195 | msg % (widget_name, '' if enabled else 'not ')) | ||
1976 | 196 | |||
1977 | 197 | def assert_dialog_properties(self, dialog_name, title, size=(600, 300), | ||
1978 | 198 | modal=True): | ||
1979 | 199 | """The dialog 'dialog_name' has correct properties.""" | ||
1980 | 200 | dialog = getattr(self.ui, dialog_name) | ||
1981 | 201 | actual = dialog.size_request() | ||
1982 | 202 | msg = 'size must be %s (got %s instead).' | ||
1983 | 203 | self.assertEquals(size, actual, msg % (size, actual)) | ||
1984 | 204 | |||
1985 | 205 | msg = '%s must %sbe modal.' | ||
1986 | 206 | self.assertEqual(modal, dialog.get_modal(), | ||
1987 | 207 | msg % (dialog_name, '' if modal else 'not ')) | ||
1988 | 208 | |||
1989 | 209 | position = dialog.get_property('window-position') | ||
1990 | 210 | self.assertEqual(gtk.WIN_POS_CENTER, position, | ||
1991 | 211 | '%s must be centered.' % dialog_name) | ||
1992 | 212 | |||
1993 | 213 | actual = dialog.get_title() | ||
1994 | 214 | msg = '%s title must be %s (got %s instead)' | ||
1995 | 215 | self.assertEqual(title, actual, msg % (dialog_name, title, actual)) | ||
1996 | 216 | |||
1997 | 217 | msg = '%s must have main_window as parent.' | ||
1998 | 218 | #self.assertTrue(dialog.parent is self.ui.main_window, | ||
1999 | 219 | # msg % dialog_name) | ||
2000 | 146 | 220 | ||
2001 | 147 | 221 | ||
2002 | 148 | class MagicicadaUIBasicTestCase(MagicicadaUITestCase): | 222 | class MagicicadaUIBasicTestCase(MagicicadaUITestCase): |
2003 | @@ -157,7 +231,7 @@ | |||
2004 | 157 | """SyncDaemon instance is shutdown at destroy time.""" | 231 | """SyncDaemon instance is shutdown at destroy time.""" |
2005 | 158 | self.patch(self.ui.sd, 'shutdown', self.set_called) | 232 | self.patch(self.ui.sd, 'shutdown', self.set_called) |
2006 | 159 | self.ui.on_main_window_destroy(self.ui.main_window) | 233 | self.ui.on_main_window_destroy(self.ui.main_window) |
2008 | 160 | self.assertTrue(self._called, | 234 | self.assertTrue(self.called, |
2009 | 161 | 'syncdaemon.shutdown must be called at destroy time.') | 235 | 'syncdaemon.shutdown must be called at destroy time.') |
2010 | 162 | 236 | ||
2011 | 163 | def test_main_window_is_visible(self): | 237 | def test_main_window_is_visible(self): |
2012 | @@ -192,7 +266,7 @@ | |||
2013 | 192 | """Update is called at startup.""" | 266 | """Update is called at startup.""" |
2014 | 193 | self.patch(MagicicadaUI, 'update', self.set_called) | 267 | self.patch(MagicicadaUI, 'update', self.set_called) |
2015 | 194 | self.ui = MagicicadaUI(syncdaemon_class=FakedSyncdaemon) | 268 | self.ui = MagicicadaUI(syncdaemon_class=FakedSyncdaemon) |
2017 | 195 | self.assertTrue(self._called, | 269 | self.assertTrue(self.called, |
2018 | 196 | 'update was called at startup.') | 270 | 'update was called at startup.') |
2019 | 197 | 271 | ||
2020 | 198 | 272 | ||
2021 | @@ -215,11 +289,11 @@ | |||
2022 | 215 | """Test on_start_clicked.""" | 289 | """Test on_start_clicked.""" |
2023 | 216 | self.patch(self.ui.sd, 'start', self.set_called) | 290 | self.patch(self.ui.sd, 'start', self.set_called) |
2024 | 217 | self.ui.on_start_clicked(self.ui.start) | 291 | self.ui.on_start_clicked(self.ui.start) |
2026 | 218 | self.assertTrue(self._called, 'syncdaemon.start was called.') | 292 | self.assertTrue(self.called, 'syncdaemon.start was called.') |
2027 | 219 | 293 | ||
2028 | 220 | def test_on_connect_clicked(self): | 294 | def test_on_connect_clicked(self): |
2029 | 221 | """Test on_connect_clicked.""" | 295 | """Test on_connect_clicked.""" |
2031 | 222 | self.do_start() # need to be started | 296 | self.do_start() # need to be started |
2032 | 223 | self.ui.on_connect_clicked(self.ui.connect) | 297 | self.ui.on_connect_clicked(self.ui.connect) |
2033 | 224 | 298 | ||
2034 | 225 | self.assertTrue(self.ui.widget_is_visible(self.ui.connect)) | 299 | self.assertTrue(self.ui.widget_is_visible(self.ui.connect)) |
2035 | @@ -234,7 +308,7 @@ | |||
2036 | 234 | """Test on_connect_clicked.""" | 308 | """Test on_connect_clicked.""" |
2037 | 235 | self.patch(self.ui.sd, 'connect', self.set_called) | 309 | self.patch(self.ui.sd, 'connect', self.set_called) |
2038 | 236 | self.ui.on_connect_clicked(self.ui.connect) | 310 | self.ui.on_connect_clicked(self.ui.connect) |
2040 | 237 | self.assertTrue(self._called, 'syncdaemon.connect was called.') | 311 | self.assertTrue(self.called, 'syncdaemon.connect was called.') |
2041 | 238 | 312 | ||
2042 | 239 | def test_on_stop_clicked(self): | 313 | def test_on_stop_clicked(self): |
2043 | 240 | """Test on_stop_clicked.""" | 314 | """Test on_stop_clicked.""" |
2044 | @@ -243,7 +317,7 @@ | |||
2045 | 243 | self.patch(self.ui, 'on_disconnect_clicked', self.set_called) | 317 | self.patch(self.ui, 'on_disconnect_clicked', self.set_called) |
2046 | 244 | self.ui.on_stop_clicked(self.ui.stop) | 318 | self.ui.on_stop_clicked(self.ui.stop) |
2047 | 245 | 319 | ||
2049 | 246 | self.assertFalse(self._called, 'on_disconnect_clicked was not called.') | 320 | self.assertFalse(self.called, 'on_disconnect_clicked was not called.') |
2050 | 247 | 321 | ||
2051 | 248 | self.assertFalse(self.ui.widget_is_visible(self.ui.start)) | 322 | self.assertFalse(self.ui.widget_is_visible(self.ui.start)) |
2052 | 249 | self.assertTrue(self.ui.widget_is_visible(self.ui.stop)) | 323 | self.assertTrue(self.ui.widget_is_visible(self.ui.stop)) |
2053 | @@ -259,13 +333,13 @@ | |||
2054 | 259 | self.patch(self.ui, 'on_disconnect_clicked', self.set_called) | 333 | self.patch(self.ui, 'on_disconnect_clicked', self.set_called) |
2055 | 260 | self.ui.on_stop_clicked(self.ui.stop) | 334 | self.ui.on_stop_clicked(self.ui.stop) |
2056 | 261 | 335 | ||
2058 | 262 | self.assertTrue(self._called, 'on_disconnect_clicked was called.') | 336 | self.assertTrue(self.called, 'on_disconnect_clicked was called.') |
2059 | 263 | 337 | ||
2060 | 264 | def test_on_stop_clicked_stops_syncdaemon(self): | 338 | def test_on_stop_clicked_stops_syncdaemon(self): |
2061 | 265 | """Test on_stop_clicked.""" | 339 | """Test on_stop_clicked.""" |
2062 | 266 | self.patch(self.ui.sd, 'quit', self.set_called) | 340 | self.patch(self.ui.sd, 'quit', self.set_called) |
2063 | 267 | self.ui.on_stop_clicked(self.ui.stop) | 341 | self.ui.on_stop_clicked(self.ui.stop) |
2065 | 268 | self.assertTrue(self._called, 'syncdaemon.quit was called.') | 342 | self.assertTrue(self.called, 'syncdaemon.quit was called.') |
2066 | 269 | 343 | ||
2067 | 270 | def test_on_disconnect_clicked(self): | 344 | def test_on_disconnect_clicked(self): |
2068 | 271 | """Test on_disconnect_clicked.""" | 345 | """Test on_disconnect_clicked.""" |
2069 | @@ -280,7 +354,7 @@ | |||
2070 | 280 | """Test on_disconnect_clicked.""" | 354 | """Test on_disconnect_clicked.""" |
2071 | 281 | self.patch(self.ui.sd, 'disconnect', self.set_called) | 355 | self.patch(self.ui.sd, 'disconnect', self.set_called) |
2072 | 282 | self.ui.on_disconnect_clicked(self.ui.disconnect) | 356 | self.ui.on_disconnect_clicked(self.ui.disconnect) |
2074 | 283 | self.assertTrue(self._called, 'syncdaemon.disconnect was called.') | 357 | self.assertTrue(self.called, 'syncdaemon.disconnect was called.') |
2075 | 284 | 358 | ||
2076 | 285 | 359 | ||
2077 | 286 | class MagicicadaUISystrayIconTestCase(MagicicadaUITestCase): | 360 | class MagicicadaUISystrayIconTestCase(MagicicadaUITestCase): |
2078 | @@ -294,14 +368,15 @@ | |||
2079 | 294 | 368 | ||
2080 | 295 | def test_main_window_is_shown_when_clicked_after_hidden(self): | 369 | def test_main_window_is_shown_when_clicked_after_hidden(self): |
2081 | 296 | """Main window is shown when the icon is clicked after hidden.""" | 370 | """Main window is shown when the icon is clicked after hidden.""" |
2084 | 297 | self.ui.on_status_icon_activate(self.ui.status_icon) # hide | 371 | self.ui.on_status_icon_activate(self.ui.status_icon) # hide |
2085 | 298 | self.ui.on_status_icon_activate(self.ui.status_icon) # show | 372 | self.ui.on_status_icon_activate(self.ui.status_icon) # show |
2086 | 299 | msg = 'main_window should be visible when icon clicked after hidden.' | 373 | msg = 'main_window should be visible when icon clicked after hidden.' |
2087 | 300 | self.assertTrue(self.ui.widget_is_visible(self.ui.main_window), msg) | 374 | self.assertTrue(self.ui.widget_is_visible(self.ui.main_window), msg) |
2088 | 301 | 375 | ||
2089 | 302 | 376 | ||
2090 | 303 | def skip_abstract_class(test): | 377 | def skip_abstract_class(test): |
2091 | 304 | """If 'test' belongs to an abstract class, don't run it.""" | 378 | """If 'test' belongs to an abstract class, don't run it.""" |
2092 | 379 | |||
2093 | 305 | @wraps(test) | 380 | @wraps(test) |
2094 | 306 | def inner(klass): | 381 | def inner(klass): |
2095 | 307 | """Execute 'test' only if not in an abstract class.""" | 382 | """Execute 'test' only if not in an abstract class.""" |
2096 | @@ -336,6 +411,24 @@ | |||
2097 | 336 | # operation path share node | 411 | # operation path share node |
2098 | 337 | return res | 412 | return res |
2099 | 338 | 413 | ||
2100 | 414 | def expected_markup(self, value): | ||
2101 | 415 | """Return the markup for row at index 'i'.""" | ||
2102 | 416 | processing_meta = self.name == META_QUEUE and \ | ||
2103 | 417 | self.ui.sd.current_state.processing_meta | ||
2104 | 418 | processing_content = self.name == CONTENT_QUEUE and \ | ||
2105 | 419 | self.ui.sd.current_state.processing_content | ||
2106 | 420 | assert not (processing_meta and processing_content) | ||
2107 | 421 | must_highlight = self.ui.sd.current_state.is_online and \ | ||
2108 | 422 | (processing_meta or processing_content) | ||
2109 | 423 | result = self.ui.CURRENT_ROW % value \ | ||
2110 | 424 | if must_highlight and value is not None else value | ||
2111 | 425 | return result | ||
2112 | 426 | |||
2113 | 427 | def assert_store_correct(self, store, items): | ||
2114 | 428 | """Test that 'store' has 'items' as content.""" | ||
2115 | 429 | args = (store, items, self.expected_markup) | ||
2116 | 430 | super(_MagicicadaUIQueueTestCase, self).assert_store_correct(*args) | ||
2117 | 431 | |||
2118 | 339 | @skip_abstract_class | 432 | @skip_abstract_class |
2119 | 340 | def test_callback_is_connected(self): | 433 | def test_callback_is_connected(self): |
2120 | 341 | """Queue changed callback is connected.""" | 434 | """Queue changed callback is connected.""" |
2121 | @@ -364,6 +457,13 @@ | |||
2122 | 364 | self.assert_store_correct(self.queue_store, []) | 457 | self.assert_store_correct(self.queue_store, []) |
2123 | 365 | 458 | ||
2124 | 366 | @skip_abstract_class | 459 | @skip_abstract_class |
2125 | 460 | def test_on_queue_changed_handles_an_item_none(self): | ||
2126 | 461 | """On queue changed handles None as items.""" | ||
2127 | 462 | items = [QueueData(operation='Test', path='', share=None, node=None)] | ||
2128 | 463 | self.sd_changed(items) | ||
2129 | 464 | self.assert_store_correct(self.queue_store, items) | ||
2130 | 465 | |||
2131 | 466 | @skip_abstract_class | ||
2132 | 367 | def test_model_is_cleared_before_updating(self): | 467 | def test_model_is_cleared_before_updating(self): |
2133 | 368 | """The model is cleared before upadting with a new set of data.""" | 468 | """The model is cleared before upadting with a new set of data.""" |
2134 | 369 | items = self.build_some_data() | 469 | items = self.build_some_data() |
2135 | @@ -400,7 +500,7 @@ | |||
2136 | 400 | cb = 'on_%s_queue_changed' % self.name | 500 | cb = 'on_%s_queue_changed' % self.name |
2137 | 401 | self.patch(self.ui, cb, self.set_called) | 501 | self.patch(self.ui, cb, self.set_called) |
2138 | 402 | self.ui.on_stopped() | 502 | self.ui.on_stopped() |
2140 | 403 | self.assertTrue(self._called, | 503 | self.assertTrue(self.called, |
2141 | 404 | '%s was called on_stopped.' % cb) | 504 | '%s was called on_stopped.' % cb) |
2142 | 405 | 505 | ||
2143 | 406 | @skip_abstract_class | 506 | @skip_abstract_class |
2144 | @@ -425,12 +525,64 @@ | |||
2145 | 425 | self.do_start() | 525 | self.do_start() |
2146 | 426 | self.assert_store_correct(self.queue_store, items) | 526 | self.assert_store_correct(self.queue_store, items) |
2147 | 427 | 527 | ||
2149 | 428 | items = items[:len(items)/2] | 528 | items = items[:len(items) / 2] |
2150 | 429 | self.set_sd_queue(items) | 529 | self.set_sd_queue(items) |
2151 | 430 | self.ui.on_stop_clicked(self.ui.stop) | 530 | self.ui.on_stop_clicked(self.ui.stop) |
2152 | 431 | self.ui.on_stopped() | 531 | self.ui.on_stopped() |
2153 | 432 | self.assert_store_correct(self.queue_store, items) | 532 | self.assert_store_correct(self.queue_store, items) |
2154 | 433 | 533 | ||
2155 | 534 | def assert_current_processing_row_is_different(self): | ||
2156 | 535 | """Row being processed is highlighted.""" | ||
2157 | 536 | items = self.build_some_data() | ||
2158 | 537 | self.sd_changed(items) | ||
2159 | 538 | |||
2160 | 539 | item = items[0] | ||
2161 | 540 | attrs = type(item)._fields | ||
2162 | 541 | |||
2163 | 542 | markup = self.expected_markup | ||
2164 | 543 | expected = tuple(markup(getattr(item, attr)) for attr in attrs) | ||
2165 | 544 | |||
2166 | 545 | iter_root = self.queue_store.get_iter_root() | ||
2167 | 546 | actual = self.queue_store.get(iter_root, *xrange(len(attrs))) | ||
2168 | 547 | |||
2169 | 548 | msg = 'first row for %s queue must be %s (got %s instead)' % \ | ||
2170 | 549 | (self.name, expected, actual) | ||
2171 | 550 | self.assertEqual(expected, actual, msg) | ||
2172 | 551 | |||
2173 | 552 | @skip_abstract_class | ||
2174 | 553 | def test_current_processing_row_is_different_if_online(self): | ||
2175 | 554 | """Row being processed is highlighted.""" | ||
2176 | 555 | self.ui.sd.current_state.set(is_online=True) | ||
2177 | 556 | |||
2178 | 557 | self.ui.sd.current_state.set(queues='') | ||
2179 | 558 | self.assert_current_processing_row_is_different() | ||
2180 | 559 | |||
2181 | 560 | self.ui.sd.current_state.set(queues='WORKING_ON_METADATA') | ||
2182 | 561 | self.assert_current_processing_row_is_different() | ||
2183 | 562 | |||
2184 | 563 | self.ui.sd.current_state.set(queues='WORKING_ON_CONTENT') | ||
2185 | 564 | self.assert_current_processing_row_is_different() | ||
2186 | 565 | |||
2187 | 566 | self.ui.sd.current_state.set(queues='WORKING_ON_BOTH') | ||
2188 | 567 | self.assert_current_processing_row_is_different() | ||
2189 | 568 | |||
2190 | 569 | @skip_abstract_class | ||
2191 | 570 | def test_current_processing_row_is_not_different_if_offline(self): | ||
2192 | 571 | """Row being processed is highlighted.""" | ||
2193 | 572 | self.ui.sd.current_state.set(is_online=False) | ||
2194 | 573 | |||
2195 | 574 | self.ui.sd.current_state.set(queues='') | ||
2196 | 575 | self.assert_current_processing_row_is_different() | ||
2197 | 576 | |||
2198 | 577 | self.ui.sd.current_state.set(queues='WORKING_ON_METADATA') | ||
2199 | 578 | self.assert_current_processing_row_is_different() | ||
2200 | 579 | |||
2201 | 580 | self.ui.sd.current_state.set(queues='WORKING_ON_CONTENT') | ||
2202 | 581 | self.assert_current_processing_row_is_different() | ||
2203 | 582 | |||
2204 | 583 | self.ui.sd.current_state.set(queues='WORKING_ON_BOTH') | ||
2205 | 584 | self.assert_current_processing_row_is_different() | ||
2206 | 585 | |||
2207 | 434 | 586 | ||
2208 | 435 | class MagicicadaUIContentQueueTestCase(_MagicicadaUIQueueTestCase): | 587 | class MagicicadaUIContentQueueTestCase(_MagicicadaUIQueueTestCase): |
2209 | 436 | """UI test cases for content queue view.""" | 588 | """UI test cases for content queue view.""" |
2210 | @@ -477,13 +629,14 @@ | |||
2211 | 477 | """Status callback is connected.""" | 629 | """Status callback is connected.""" |
2212 | 478 | self.assertEqual(self.ui.sd.status_changed_callback, | 630 | self.assertEqual(self.ui.sd.status_changed_callback, |
2213 | 479 | self.ui.on_status_changed, | 631 | self.ui.on_status_changed, |
2215 | 480 | 'status_changed callback must be set') | 632 | 'status_changed callback must be set.') |
2216 | 481 | 633 | ||
2217 | 482 | def test_status_label_ellipsizes(self): | 634 | def test_status_label_ellipsizes(self): |
2218 | 483 | """The status label ellipsizes.""" | 635 | """The status label ellipsizes.""" |
2219 | 484 | expected = pango.ELLIPSIZE_END | 636 | expected = pango.ELLIPSIZE_END |
2220 | 485 | actual = self.ui.status_label.get_ellipsize() | 637 | actual = self.ui.status_label.get_ellipsize() |
2222 | 486 | self.assertEqual(expected, actual, 'label ellipsizes is ELLIPSIZE_END.') | 638 | self.assertEqual(expected, actual, |
2223 | 639 | 'label ellipsizes is ELLIPSIZE_END.') | ||
2224 | 487 | 640 | ||
2225 | 488 | def test_on_status_changed_updates_status_label(self): | 641 | def test_on_status_changed_updates_status_label(self): |
2226 | 489 | """On status changed, the status label is updated.""" | 642 | """On status changed, the status label is updated.""" |
2227 | @@ -493,7 +646,7 @@ | |||
2228 | 493 | 646 | ||
2229 | 494 | def test_on_status_changed_updates_status_label_even_on_weird_cases(self): | 647 | def test_on_status_changed_updates_status_label_even_on_weird_cases(self): |
2230 | 495 | """On status changed, the status label is updated.""" | 648 | """On status changed, the status label is updated.""" |
2232 | 496 | keywords = ('name', 'description', 'queues', 'connection') # need order | 649 | keywords = ('name', 'description', 'queues', 'connection') # order |
2233 | 497 | for attr in keywords: | 650 | for attr in keywords: |
2234 | 498 | old_value = self.kwargs[attr] | 651 | old_value = self.kwargs[attr] |
2235 | 499 | 652 | ||
2236 | @@ -509,7 +662,7 @@ | |||
2237 | 509 | 662 | ||
2238 | 510 | def test_update_is_correct_for_status_label(self): | 663 | def test_update_is_correct_for_status_label(self): |
2239 | 511 | """Correctly updates the status label.""" | 664 | """Correctly updates the status label.""" |
2241 | 512 | self.ui.sd.current_state._set(**self.kwargs) | 665 | self.ui.sd.current_state.set(**self.kwargs) |
2242 | 513 | self.ui.update() | 666 | self.ui.update() |
2243 | 514 | self.assert_status_label_correct(**self.kwargs) | 667 | self.assert_status_label_correct(**self.kwargs) |
2244 | 515 | 668 | ||
2245 | @@ -517,7 +670,7 @@ | |||
2246 | 517 | """On SD stoppped, the UI updates the status label.""" | 670 | """On SD stoppped, the UI updates the status label.""" |
2247 | 518 | self.patch(self.ui, 'on_status_changed', self.set_called) | 671 | self.patch(self.ui, 'on_status_changed', self.set_called) |
2248 | 519 | self.ui.on_stopped() | 672 | self.ui.on_stopped() |
2250 | 520 | self.assertTrue(self._called, | 673 | self.assertTrue(self.called, |
2251 | 521 | 'on_status_changed was called on_stopped.') | 674 | 'on_status_changed was called on_stopped.') |
2252 | 522 | 675 | ||
2253 | 523 | def test_status_label_default_if_not_started(self): | 676 | def test_status_label_default_if_not_started(self): |
2254 | @@ -532,12 +685,12 @@ | |||
2255 | 532 | 685 | ||
2256 | 533 | def test_status_label_is_updated_on_started_and_on_stopped(self): | 686 | def test_status_label_is_updated_on_started_and_on_stopped(self): |
2257 | 534 | """Status label is updated on_started.""" | 687 | """Status label is updated on_started.""" |
2259 | 535 | self.ui.sd.current_state._set(**self.kwargs) | 688 | self.ui.sd.current_state.set(**self.kwargs) |
2260 | 536 | self.do_start() | 689 | self.do_start() |
2261 | 537 | self.assert_status_label_correct(**self.kwargs) | 690 | self.assert_status_label_correct(**self.kwargs) |
2262 | 538 | 691 | ||
2263 | 539 | self.kwargs['name'] = 'CHANGED' | 692 | self.kwargs['name'] = 'CHANGED' |
2265 | 540 | self.ui.sd.current_state._set(**self.kwargs) | 693 | self.ui.sd.current_state.set(**self.kwargs) |
2266 | 541 | 694 | ||
2267 | 542 | self.ui.on_stop_clicked(self.ui.stop) | 695 | self.ui.on_stop_clicked(self.ui.stop) |
2268 | 543 | self.ui.on_stopped() | 696 | self.ui.on_stopped() |
2269 | @@ -551,7 +704,7 @@ | |||
2270 | 551 | """Test that correctly updates the 'indicator'.""" | 704 | """Test that correctly updates the 'indicator'.""" |
2271 | 552 | cs = self.ui.sd.current_state | 705 | cs = self.ui.sd.current_state |
2272 | 553 | for expected in (True, False): | 706 | for expected in (True, False): |
2274 | 554 | cs._set(**{indicator: expected}) | 707 | cs.set(**{indicator: expected}) |
2275 | 555 | 708 | ||
2276 | 556 | self.ui.update() | 709 | self.ui.update() |
2277 | 557 | 710 | ||
2278 | @@ -684,67 +837,64 @@ | |||
2279 | 684 | self.volume_dialog_name = '%s_dialog' % self.name | 837 | self.volume_dialog_name = '%s_dialog' % self.name |
2280 | 685 | self.volume_dialog = getattr(self.ui, self.volume_dialog_name) | 838 | self.volume_dialog = getattr(self.ui, self.volume_dialog_name) |
2281 | 686 | self.on_volume_clicked = getattr(self.ui, 'on_%s_clicked' % self.name) | 839 | self.on_volume_clicked = getattr(self.ui, 'on_%s_clicked' % self.name) |
2282 | 840 | self.volume_close = getattr(self.ui, '%s_close' % self.name) | ||
2283 | 687 | 841 | ||
2284 | 688 | def build_some_data(self, limit=5): | 842 | def build_some_data(self, limit=5): |
2285 | 689 | """Build some data to act as volume.""" | 843 | """Build some data to act as volume.""" |
2286 | 690 | kwargs = dict(data_type=self.data_type, limit=limit) | 844 | kwargs = dict(data_type=self.data_type, limit=limit) |
2289 | 691 | res = super(_MagicicadaUIVolumeTestCase, self).build_some_data(**kwargs) | 845 | r = super(_MagicicadaUIVolumeTestCase, self).build_some_data(**kwargs) |
2290 | 692 | return res | 846 | return r |
2291 | 693 | 847 | ||
2293 | 694 | def assert_volume_availability(self, enabled): | 848 | def assert_widget_availability(self, enabled=True): |
2294 | 695 | """Check volume availability according to 'enabled'.""" | 849 | """Check volume availability according to 'enabled'.""" |
2301 | 696 | self.assertTrue(self.ui.widget_is_visible(self.volume), | 850 | s = super(_MagicicadaUIVolumeTestCase, self) |
2302 | 697 | '%s should be visible' % self.name) | 851 | s.assert_widget_availability(self.name, enabled) |
2297 | 698 | sensitive = self.volume.is_sensitive() | ||
2298 | 699 | msg = '%s should %sbe sensitive' | ||
2299 | 700 | self.assertTrue(sensitive if enabled else not sensitive, | ||
2300 | 701 | msg % (self.name, '' if enabled else 'not ')) | ||
2303 | 702 | 852 | ||
2304 | 703 | @skip_abstract_class | 853 | @skip_abstract_class |
2305 | 704 | def test_volume_are_disabled_until_started(self): | 854 | def test_volume_are_disabled_until_started(self): |
2306 | 705 | """Folders and shares are disabled until online.""" | 855 | """Folders and shares are disabled until online.""" |
2307 | 706 | # disabled at startup | 856 | # disabled at startup |
2309 | 707 | self.assert_volume_availability(enabled=False) | 857 | self.assert_widget_availability(enabled=False) |
2310 | 708 | 858 | ||
2311 | 709 | # enabled when started | 859 | # enabled when started |
2312 | 710 | self.do_start() | 860 | self.do_start() |
2314 | 711 | self.assert_volume_availability(enabled=True) | 861 | self.assert_widget_availability(enabled=True) |
2315 | 712 | 862 | ||
2316 | 713 | @skip_abstract_class | 863 | @skip_abstract_class |
2317 | 714 | def test_volume_are_enabled_until_stopped(self): | 864 | def test_volume_are_enabled_until_stopped(self): |
2318 | 715 | """Folders and shares are enabled until offline.""" | 865 | """Folders and shares are enabled until offline.""" |
2319 | 716 | self.do_connect() | 866 | self.do_connect() |
2321 | 717 | self.assert_volume_availability(enabled=True) | 867 | self.assert_widget_availability(enabled=True) |
2322 | 718 | 868 | ||
2323 | 719 | self.ui.on_online() | 869 | self.ui.on_online() |
2325 | 720 | self.assert_volume_availability(enabled=True) | 870 | self.assert_widget_availability(enabled=True) |
2326 | 721 | 871 | ||
2327 | 722 | self.ui.on_offline() | 872 | self.ui.on_offline() |
2329 | 723 | self.assert_volume_availability(enabled=True) | 873 | self.assert_widget_availability(enabled=True) |
2330 | 724 | 874 | ||
2331 | 725 | self.ui.on_disconnect_clicked(self.ui.disconnect) | 875 | self.ui.on_disconnect_clicked(self.ui.disconnect) |
2332 | 726 | self.ui.on_disconnected() | 876 | self.ui.on_disconnected() |
2334 | 727 | self.assert_volume_availability(enabled=True) | 877 | self.assert_widget_availability(enabled=True) |
2335 | 728 | 878 | ||
2336 | 729 | # disabled when stopped | 879 | # disabled when stopped |
2337 | 730 | self.ui.on_stop_clicked(self.ui.stop) | 880 | self.ui.on_stop_clicked(self.ui.stop) |
2339 | 731 | self.assert_volume_availability(enabled=False) | 881 | self.assert_widget_availability(enabled=False) |
2340 | 732 | self.ui.on_stopped() | 882 | self.ui.on_stopped() |
2342 | 733 | self.assert_volume_availability(enabled=False) | 883 | self.assert_widget_availability(enabled=False) |
2343 | 734 | 884 | ||
2344 | 735 | @skip_abstract_class | 885 | @skip_abstract_class |
2345 | 736 | def test_volume_close_emits_response_close(self): | 886 | def test_volume_close_emits_response_close(self): |
2346 | 737 | """Test volume close button emits RESPONSE_CLOSE when clicked.""" | 887 | """Test volume close button emits RESPONSE_CLOSE when clicked.""" |
2348 | 738 | self.response = None | 888 | |
2349 | 739 | def record_response(value): | 889 | def record_response(value): |
2350 | 740 | """Record the response received.""" | 890 | """Record the response received.""" |
2351 | 741 | self.response = value | 891 | self.response = value |
2352 | 892 | |||
2353 | 742 | self.patch(self.volume_dialog, 'response', record_response) | 893 | self.patch(self.volume_dialog, 'response', record_response) |
2354 | 743 | 894 | ||
2357 | 744 | volume_close = '%s_close' % self.name | 895 | self.volume_close.clicked() |
2356 | 745 | getattr(self.ui, volume_close).clicked() | ||
2358 | 746 | self.assertEqual(gtk.RESPONSE_CLOSE, self.response, | 896 | self.assertEqual(gtk.RESPONSE_CLOSE, self.response, |
2360 | 747 | '%s should emit RESPONSE_CLOSE.' % volume_close) | 897 | 'volume close button should emit RESPONSE_CLOSE.') |
2361 | 748 | 898 | ||
2362 | 749 | @skip_abstract_class | 899 | @skip_abstract_class |
2363 | 750 | def test_on_volume_clicked(self): | 900 | def test_on_volume_clicked(self): |
2364 | @@ -799,36 +949,25 @@ | |||
2365 | 799 | self.on_volume_clicked(self.volume) | 949 | self.on_volume_clicked(self.volume) |
2366 | 800 | 950 | ||
2367 | 801 | @skip_abstract_class | 951 | @skip_abstract_class |
2369 | 802 | def test_volume_dialog_props(self): | 952 | def test_volume_dialog_properties(self): |
2370 | 803 | """The volume dialog has correct properties.""" | 953 | """The volume dialog has correct properties.""" |
2386 | 804 | size = self.volume_dialog.size_request() | 954 | title = self.name.replace('_', ' ').capitalize() |
2387 | 805 | self.assertEquals((600, 300), size) | 955 | self.assert_dialog_properties(dialog_name=self.volume_dialog_name, |
2388 | 806 | 956 | title=title) | |
2389 | 807 | self.assertTrue(self.volume_dialog.get_modal(), | 957 | |
2375 | 808 | '%s must be modal.' % self.volume_dialog_name) | ||
2376 | 809 | |||
2377 | 810 | position = self.volume_dialog.get_property('window-position') | ||
2378 | 811 | self.assertEqual(gtk.WIN_POS_CENTER, position, | ||
2379 | 812 | '%s must be centered.' % self.volume_dialog_name) | ||
2380 | 813 | |||
2381 | 814 | actual = self.volume_dialog.get_title() | ||
2382 | 815 | expected = self.name.replace('_', ' ').capitalize() | ||
2383 | 816 | msg = '%s title must be %s (got %s instead)' | ||
2384 | 817 | self.assertEqual(expected, actual, | ||
2385 | 818 | msg % (self.volume_dialog_name, expected, actual)) | ||
2390 | 819 | 958 | ||
2391 | 820 | class MagicicadaUIFoldersTestCase(_MagicicadaUIVolumeTestCase): | 959 | class MagicicadaUIFoldersTestCase(_MagicicadaUIVolumeTestCase): |
2392 | 821 | """UI test cases for folders.""" | 960 | """UI test cases for folders.""" |
2393 | 822 | 961 | ||
2394 | 823 | name = 'folders' | 962 | name = 'folders' |
2396 | 824 | data_type = FolderData # node path suggested_path subscribed volume | 963 | data_type = FolderData # node path suggested_path subscribed volume |
2397 | 825 | 964 | ||
2398 | 826 | 965 | ||
2399 | 827 | class _MagicicadaUISharesTestCase(_MagicicadaUIVolumeTestCase): | 966 | class _MagicicadaUISharesTestCase(_MagicicadaUIVolumeTestCase): |
2400 | 828 | """UI test cases for shares_to_me.""" | 967 | """UI test cases for shares_to_me.""" |
2401 | 829 | 968 | ||
2404 | 830 | data_type = ShareData # accepted access_level free_bytes name node_id | 969 | data_type = ShareData # accepted access_level free_bytes name node_id |
2405 | 831 | # other_username other_visible_name path volume_id | 970 | # other_username other_visible_name path volume_id |
2406 | 832 | 971 | ||
2407 | 833 | @skip_abstract_class | 972 | @skip_abstract_class |
2408 | 834 | def test_bytes_are_humanized(self): | 973 | def test_bytes_are_humanized(self): |
2409 | @@ -862,3 +1001,279 @@ | |||
2410 | 862 | 1001 | ||
2411 | 863 | name = 'shares_to_others' | 1002 | name = 'shares_to_others' |
2412 | 864 | 1003 | ||
2413 | 1004 | |||
2414 | 1005 | class MagicicadaUIMetadataTestCase(MagicicadaUITestCase): | ||
2415 | 1006 | """UI test cases for metadata display.""" | ||
2416 | 1007 | |||
2417 | 1008 | name = 'raw_metadata' | ||
2418 | 1009 | |||
2419 | 1010 | def setUp(self): | ||
2420 | 1011 | """Init.""" | ||
2421 | 1012 | super(MagicicadaUIMetadataTestCase, self).setUp() | ||
2422 | 1013 | self.path = get_data_file('tests', 'metadata-test.txt') | ||
2423 | 1014 | self.metadata = dict(bla='ble', foo='bar') | ||
2424 | 1015 | |||
2425 | 1016 | def assert_widget_availability(self, enabled=True): | ||
2426 | 1017 | """Check button availability according to 'enabled'.""" | ||
2427 | 1018 | s = super(MagicicadaUIMetadataTestCase, self) | ||
2428 | 1019 | s.assert_widget_availability(self.name, enabled) | ||
2429 | 1020 | |||
2430 | 1021 | def assert_dialog_visibility(self, dialog, text_view, image): | ||
2431 | 1022 | """Check the visibility for dialog, text_view and image.""" | ||
2432 | 1023 | msg = '%s visibility should be %s (got %s instead).' | ||
2433 | 1024 | visible = self.ui.widget_is_visible(self.ui.raw_metadata_dialog) | ||
2434 | 1025 | self.assertEqual(dialog, visible, | ||
2435 | 1026 | msg % ('raw_metadata_dialog', dialog, visible)) | ||
2436 | 1027 | |||
2437 | 1028 | visible = self.ui.widget_is_visible(self.ui.raw_metadata_view) | ||
2438 | 1029 | self.assertEqual(text_view, visible, | ||
2439 | 1030 | msg % ('raw_metadata_view', text_view, visible)) | ||
2440 | 1031 | |||
2441 | 1032 | visible = self.ui.widget_is_visible(self.ui.raw_metadata_image) | ||
2442 | 1033 | self.assertEqual(image, visible, | ||
2443 | 1034 | msg % ('raw_metadata_image', image, visible)) | ||
2444 | 1035 | |||
2445 | 1036 | def test_raw_metadata_are_disabled_until_started(self): | ||
2446 | 1037 | """Raw metadata button is disabled until online.""" | ||
2447 | 1038 | # disabled at startup | ||
2448 | 1039 | self.assert_widget_availability(enabled=False) | ||
2449 | 1040 | |||
2450 | 1041 | # enabled when started | ||
2451 | 1042 | self.do_start() | ||
2452 | 1043 | self.assert_widget_availability(enabled=True) | ||
2453 | 1044 | |||
2454 | 1045 | def test_raw_metadata_are_enabled_until_stopped(self): | ||
2455 | 1046 | """Raw metadata button is enabled until offline.""" | ||
2456 | 1047 | self.do_connect() | ||
2457 | 1048 | self.assert_widget_availability(enabled=True) | ||
2458 | 1049 | |||
2459 | 1050 | self.ui.on_online() | ||
2460 | 1051 | self.assert_widget_availability(enabled=True) | ||
2461 | 1052 | |||
2462 | 1053 | self.ui.on_offline() | ||
2463 | 1054 | self.assert_widget_availability(enabled=True) | ||
2464 | 1055 | |||
2465 | 1056 | self.ui.on_disconnect_clicked(self.ui.disconnect) | ||
2466 | 1057 | self.ui.on_disconnected() | ||
2467 | 1058 | self.assert_widget_availability(enabled=True) | ||
2468 | 1059 | |||
2469 | 1060 | # disabled when stopped | ||
2470 | 1061 | self.ui.on_stop_clicked(self.ui.stop) | ||
2471 | 1062 | self.assert_widget_availability(enabled=False) | ||
2472 | 1063 | self.ui.on_stopped() | ||
2473 | 1064 | self.assert_widget_availability(enabled=False) | ||
2474 | 1065 | |||
2475 | 1066 | def test_raw_metadata_close_hides_the_dialog(self): | ||
2476 | 1067 | """Test raw_metadata close button emits RESPONSE_CLOSE when clicked.""" | ||
2477 | 1068 | self.ui.raw_metadata_close.clicked() | ||
2478 | 1069 | self.assertFalse(self.ui.widget_is_visible( | ||
2479 | 1070 | self.ui.raw_metadata_dialog), | ||
2480 | 1071 | 'raw_metadata_dialog should not be visible.') | ||
2481 | 1072 | |||
2482 | 1073 | def test_file_chooser_open_emits_response_ok(self): | ||
2483 | 1074 | """Test volume close button emits RESPONSE_CLOSE when clicked.""" | ||
2484 | 1075 | |||
2485 | 1076 | def record_response(value): | ||
2486 | 1077 | """Record the response received.""" | ||
2487 | 1078 | self.response = value | ||
2488 | 1079 | |||
2489 | 1080 | self.patch(self.ui.file_chooser, 'response', record_response) | ||
2490 | 1081 | |||
2491 | 1082 | self.ui.file_chooser_open.clicked() | ||
2492 | 1083 | self.assertEqual(gtk.FILE_CHOOSER_ACTION_OPEN, self.response, | ||
2493 | 1084 | 'open button should emit FILE_CHOOSER_ACTION_OPEN.') | ||
2494 | 1085 | |||
2495 | 1086 | def test_on_raw_metadata_clicked(self): | ||
2496 | 1087 | """Test on_raw_metadata_clicked.""" | ||
2497 | 1088 | self.assertFalse(self.ui.widget_is_visible( | ||
2498 | 1089 | self.ui.raw_metadata_dialog), | ||
2499 | 1090 | 'raw_metadata_dialog should not be visible.') | ||
2500 | 1091 | |||
2501 | 1092 | self.ui.file_chooser.set_filename(self.path) | ||
2502 | 1093 | |||
2503 | 1094 | def test_file_chooser(): | ||
2504 | 1095 | """Auxiliar to assert over the file_chooser.""" | ||
2505 | 1096 | self.assertTrue(self.ui.widget_is_visible(self.ui.file_chooser), | ||
2506 | 1097 | 'file_chooser must be visible on metadata clicked.') | ||
2507 | 1098 | |||
2508 | 1099 | gobject.timeout_add(100, test_and_click, | ||
2509 | 1100 | (self.ui.file_chooser_open, test_file_chooser)) | ||
2510 | 1101 | self.ui.on_raw_metadata_clicked(self.ui.raw_metadata) | ||
2511 | 1102 | |||
2512 | 1103 | self.assertFalse(self.ui.widget_is_visible(self.ui.file_chooser), | ||
2513 | 1104 | 'file_chooser must be visible after metadata clicked.') | ||
2514 | 1105 | self.assertEqual(self.path, self.ui.file_chooser.get_filename(), | ||
2515 | 1106 | 'filename returned by file chooser must be correct.') | ||
2516 | 1107 | |||
2517 | 1108 | # raw_metadata_dialog is enabled and shows the loading animation | ||
2518 | 1109 | self.assert_dialog_visibility(dialog=True, text_view=False, image=True) | ||
2519 | 1110 | expected = self.ui.raw_metadata_image.get_animation() | ||
2520 | 1111 | self.assertEqual(self.ui.loading_animation, expected, | ||
2521 | 1112 | 'raw_metadata_image must have the correct animation.') | ||
2522 | 1113 | |||
2523 | 1114 | # Check that the metadata was asked to the SD | ||
2524 | 1115 | self.assertEqual(self.ui.sd._meta_path, self.path) | ||
2525 | 1116 | # SD will eventually callback us with the metadata | ||
2526 | 1117 | self.ui.on_metadata_ready(self.path, self.metadata) | ||
2527 | 1118 | |||
2528 | 1119 | # raw_metadata_dialog is enabled and shows the metadata | ||
2529 | 1120 | self.assert_dialog_visibility(dialog=True, text_view=True, image=False) | ||
2530 | 1121 | |||
2531 | 1122 | # user closes the dialog | ||
2532 | 1123 | self.ui.raw_metadata_close.clicked() | ||
2533 | 1124 | |||
2534 | 1125 | # dialog was closed already | ||
2535 | 1126 | self.assertFalse(self.ui.widget_is_visible( | ||
2536 | 1127 | self.ui.raw_metadata_dialog), | ||
2537 | 1128 | 'raw_metadata_dialog should not be visible.') | ||
2538 | 1129 | |||
2539 | 1130 | def test_raw_metadata_dialog_properties(self): | ||
2540 | 1131 | """The raw_metadata dialog has correct properties.""" | ||
2541 | 1132 | title = self.name.replace('_', ' ').capitalize() | ||
2542 | 1133 | self.assert_dialog_properties(dialog_name='raw_metadata_dialog', | ||
2543 | 1134 | title=title, modal=False) | ||
2544 | 1135 | |||
2545 | 1136 | actual = self.ui.raw_metadata_view.get_wrap_mode() | ||
2546 | 1137 | msg = 'wrap mode for view must be gtk.WRAP_WORD (got %s instead).' | ||
2547 | 1138 | self.assertEqual(gtk.WRAP_WORD, actual, msg % actual) | ||
2548 | 1139 | |||
2549 | 1140 | def test_callback_is_connected(self): | ||
2550 | 1141 | """Metadata ready callback is connected.""" | ||
2551 | 1142 | self.assertEqual(self.ui.sd.on_metadata_ready_callback, | ||
2552 | 1143 | self.ui.on_metadata_ready, | ||
2553 | 1144 | 'on_metadata_ready_callback callback must be set.') | ||
2554 | 1145 | |||
2555 | 1146 | def test_file_chooser_is_hidden_at_startup(self): | ||
2556 | 1147 | """File chooser exists but is not visible.""" | ||
2557 | 1148 | self.assertFalse(self.ui.widget_is_visible(self.ui.file_chooser), | ||
2558 | 1149 | 'file_chooser must be hidden by default.') | ||
2559 | 1150 | |||
2560 | 1151 | def test_file_chooser_current_folder_is_ubuntu_one_root(self): | ||
2561 | 1152 | """File chooser default folder is ~/Ubuntu One.""" | ||
2562 | 1153 | process_gtk_pendings() # WOW! Needed to get proper value below | ||
2563 | 1154 | actual = self.ui.file_chooser.get_current_folder() | ||
2564 | 1155 | msg = 'file_chooser default folder must be %s (got %s instead).' | ||
2565 | 1156 | self.assertEqual(actual, UBUNTU_ONE_ROOT, | ||
2566 | 1157 | msg % (UBUNTU_ONE_ROOT, actual)) | ||
2567 | 1158 | |||
2568 | 1159 | def test_filename_is_used_only_if_open_clicked(self): | ||
2569 | 1160 | """Filename is used only if user clicked open.""" | ||
2570 | 1161 | self.patch(self.ui.sd, 'get_metadata', self.set_called) | ||
2571 | 1162 | gobject.timeout_add(100, test_and_click, | ||
2572 | 1163 | (self.ui.file_chooser_cancel, NO_OP)) | ||
2573 | 1164 | self.ui.on_raw_metadata_clicked(self.ui.raw_metadata) | ||
2574 | 1165 | |||
2575 | 1166 | self.assertFalse(self.called, | ||
2576 | 1167 | 'get_metadata should not be called if no file chosen.') | ||
2577 | 1168 | |||
2578 | 1169 | def test_filename_is_stored_if_open_clicked(self): | ||
2579 | 1170 | """Filename is stored as 'last_metadata_path' if user clicked open.""" | ||
2580 | 1171 | self.assertTrue(self.ui.last_metadata_path is None, | ||
2581 | 1172 | 'last_metadata_path must be None.') | ||
2582 | 1173 | self.ui.file_chooser.set_filename(self.path) | ||
2583 | 1174 | gobject.timeout_add(100, test_and_click, | ||
2584 | 1175 | (self.ui.file_chooser_open, NO_OP)) | ||
2585 | 1176 | self.ui.on_raw_metadata_clicked(self.ui.raw_metadata) | ||
2586 | 1177 | |||
2587 | 1178 | self.assertEqual(self.path, self.ui.last_metadata_path, | ||
2588 | 1179 | 'last_metadata_path should be what the user choose.') | ||
2589 | 1180 | |||
2590 | 1181 | def test_on_metadata_ready(self): | ||
2591 | 1182 | """Callback on_metadata_ready updates the raw_metadata_view.""" | ||
2592 | 1183 | path = 'bla' | ||
2593 | 1184 | self.ui.last_metadata_path = path | ||
2594 | 1185 | self.ui.on_metadata_ready(path, self.metadata) | ||
2595 | 1186 | |||
2596 | 1187 | buff = self.ui.raw_metadata_view.get_buffer() | ||
2597 | 1188 | self.assertTrue(buff is not None, | ||
2598 | 1189 | 'buffer for raw_metadata_view must not be None.') | ||
2599 | 1190 | |||
2600 | 1191 | expected = '\n'.join('%s: %s' % i for i in self.metadata.iteritems()) | ||
2601 | 1192 | actual = buff.get_text(*buff.get_bounds()) | ||
2602 | 1193 | msg = 'buffer content must be %s (got %s instead).' | ||
2603 | 1194 | self.assertEqual(actual, expected, | ||
2604 | 1195 | msg % (expected, actual)) | ||
2605 | 1196 | |||
2606 | 1197 | def test_on_metadata_ready_doesnt_update_if_last_path_doesnt_match(self): | ||
2607 | 1198 | """Callback on_metadata_ready updates the raw_metadata_view.""" | ||
2608 | 1199 | self.patch(self.ui.raw_metadata_view.get_buffer(), | ||
2609 | 1200 | 'set_text', self.set_called) | ||
2610 | 1201 | path = 'bla' | ||
2611 | 1202 | self.ui.last_metadata_path = path + path | ||
2612 | 1203 | self.ui.on_metadata_ready(path, self.metadata) | ||
2613 | 1204 | |||
2614 | 1205 | self.assertFalse(self.called, | ||
2615 | 1206 | 'view should not be updated if key is not last one.') | ||
2616 | 1207 | |||
2617 | 1208 | |||
2618 | 1209 | def override_input_output(input_args, output_args): | ||
2619 | 1210 | """Call 'f' but receive fixed input and return fixed output.""" | ||
2620 | 1211 | |||
2621 | 1212 | def decorator(f): | ||
2622 | 1213 | """The decorator per se.""" | ||
2623 | 1214 | |||
2624 | 1215 | @wraps(f) | ||
2625 | 1216 | def inner(*args, **kwargs): | ||
2626 | 1217 | """Feed 'f' with 'input_args' and return 'output_args'.""" | ||
2627 | 1218 | f(input_args) | ||
2628 | 1219 | return output_args | ||
2629 | 1220 | |||
2630 | 1221 | return inner | ||
2631 | 1222 | |||
2632 | 1223 | return decorator | ||
2633 | 1224 | |||
2634 | 1225 | |||
2635 | 1226 | class MagicicadaLoggingTestCase(MagicicadaUITestCase): | ||
2636 | 1227 | """UI test cases for logging.""" | ||
2637 | 1228 | |||
2638 | 1229 | def setUp(self): | ||
2639 | 1230 | """Init.""" | ||
2640 | 1231 | super(MagicicadaLoggingTestCase, self).setUp() | ||
2641 | 1232 | |||
2642 | 1233 | self.memento = MementoHandler() | ||
2643 | 1234 | self.memento.setLevel(logging.DEBUG) | ||
2644 | 1235 | logger = logging.getLogger('magicicada.ui') | ||
2645 | 1236 | logger.addHandler(self.memento) | ||
2646 | 1237 | |||
2647 | 1238 | def assert_function_logs(self, func, *args, **kwargs): | ||
2648 | 1239 | """Check 'funcion' logs its inputs as DEBUG.""" | ||
2649 | 1240 | name = func.__name__ | ||
2650 | 1241 | msg = '%s must be logged as DEBUG' | ||
2651 | 1242 | try: | ||
2652 | 1243 | func(*args, **kwargs) | ||
2653 | 1244 | except Exception: # pylint: disable-msg=E0501, W0703 | ||
2654 | 1245 | exc = sys.exc_info() | ||
2655 | 1246 | self.assertTrue(self.memento.check_error(name), | ||
2656 | 1247 | 'function (%s) must be logged as ERROR' % name) | ||
2657 | 1248 | self.assertTrue(self.memento.check_error(exc), | ||
2658 | 1249 | 'sys.exc_info (%s) must be logged as ERROR' % exc) | ||
2659 | 1250 | self.assertTrue(self.memento.check_debug(name), msg % name) | ||
2660 | 1251 | for arg in args: | ||
2661 | 1252 | self.assertTrue(self.memento.check_debug(str(arg)), msg % arg) | ||
2662 | 1253 | for key, val in kwargs.iteritems(): | ||
2663 | 1254 | arg = "'%s': %r" % (key, val) | ||
2664 | 1255 | self.assertTrue(self.memento.check_debug(arg), msg % arg) | ||
2665 | 1256 | |||
2666 | 1257 | def test_on_shares_clicked_logs(self): | ||
2667 | 1258 | """Check _on_shares_clicked logs properly.""" | ||
2668 | 1259 | args = ([0, object(), 'test', {}], object()) | ||
2669 | 1260 | kwargs = dict(dialog=object()) | ||
2670 | 1261 | self.assert_function_logs(self.ui._on_shares_clicked, *args, **kwargs) | ||
2671 | 1262 | |||
2672 | 1263 | def test_on_status_changed_logs(self): | ||
2673 | 1264 | """Check _on_status_changed logs properly.""" | ||
2674 | 1265 | args = ('test status', 'status description', True, False, True) | ||
2675 | 1266 | kwargs = dict(queues='bla', connection=None) | ||
2676 | 1267 | self.assert_function_logs(self.ui.on_status_changed, *args, **kwargs) | ||
2677 | 1268 | |||
2678 | 1269 | def test_on_queue_changed_logs(self): | ||
2679 | 1270 | """Check _on_queue_changed logs properly.""" | ||
2680 | 1271 | args = ('meta',) | ||
2681 | 1272 | kwargs = dict(items=[0, object(), 'test', {}], must_highlight=True) | ||
2682 | 1273 | self.assert_function_logs(self.ui._on_queue_changed, *args, **kwargs) | ||
2683 | 1274 | |||
2684 | 1275 | def test_on_metadata_ready_logs(self): | ||
2685 | 1276 | """Check on_metadata_ready logs properly.""" | ||
2686 | 1277 | args = () | ||
2687 | 1278 | kwargs = dict(path='test', metadata=True) | ||
2688 | 1279 | self.assert_function_logs(self.ui.on_metadata_ready, *args, **kwargs) | ||
2689 | 865 | 1280 | ||
2690 | === modified file 'magicicada/tests/test_syncdaemon.py' | |||
2691 | --- magicicada/tests/test_syncdaemon.py 2010-06-08 10:53:02 +0000 | |||
2692 | +++ magicicada/tests/test_syncdaemon.py 2010-07-09 18:33:43 +0000 | |||
2693 | @@ -28,6 +28,10 @@ | |||
2694 | 28 | from twisted.internet import defer, reactor | 28 | from twisted.internet import defer, reactor |
2695 | 29 | 29 | ||
2696 | 30 | 30 | ||
2697 | 31 | # It's ok to access private data in the test suite | ||
2698 | 32 | # pylint: disable-msg=W0212 | ||
2699 | 33 | |||
2700 | 34 | |||
2701 | 31 | class FakeDBusInterface(object): | 35 | class FakeDBusInterface(object): |
2702 | 32 | """Fake DBus Interface, for SD to not use dbus at all during tests.""" | 36 | """Fake DBus Interface, for SD to not use dbus at all during tests.""" |
2703 | 33 | 37 | ||
2704 | @@ -37,15 +41,18 @@ | |||
2705 | 37 | pass | 41 | pass |
2706 | 38 | 42 | ||
2707 | 39 | def shutdown(self): | 43 | def shutdown(self): |
2708 | 44 | """Fake shutdown.""" | ||
2709 | 40 | pass | 45 | pass |
2710 | 41 | 46 | ||
2711 | 42 | def get_status(self): | 47 | def get_status(self): |
2712 | 43 | """Fake status.""" | 48 | """Fake status.""" |
2713 | 44 | return defer.succeed(('fakename', 'fakedescrip', False, True, | 49 | return defer.succeed(('fakename', 'fakedescrip', False, True, |
2714 | 45 | False, 'fakequeues', 'fakeconnection')) | 50 | False, 'fakequeues', 'fakeconnection')) |
2715 | 51 | |||
2716 | 46 | def get_folders(self): | 52 | def get_folders(self): |
2717 | 47 | """Fake folders.""" | 53 | """Fake folders.""" |
2718 | 48 | return defer.succeed('fakedata') | 54 | return defer.succeed('fakedata') |
2719 | 55 | |||
2720 | 49 | get_content_queue = get_meta_queue = get_folders | 56 | get_content_queue = get_meta_queue = get_folders |
2721 | 50 | start = quit = connect = disconnect = get_folders | 57 | start = quit = connect = disconnect = get_folders |
2722 | 51 | get_shares_to_me = get_shares_to_others = get_folders | 58 | get_shares_to_me = get_shares_to_others = get_folders |
2723 | @@ -133,8 +140,9 @@ | |||
2724 | 133 | 140 | ||
2725 | 134 | @defer.inlineCallbacks | 141 | @defer.inlineCallbacks |
2726 | 135 | def test_initial_value(self): | 142 | def test_initial_value(self): |
2728 | 136 | """Fills the status info initially.""" | 143 | """Fill the status info initially.""" |
2729 | 137 | called = [] | 144 | called = [] |
2730 | 145 | |||
2731 | 138 | def fake(): | 146 | def fake(): |
2732 | 139 | """Fake method.""" | 147 | """Fake method.""" |
2733 | 140 | called.append(True) | 148 | called.append(True) |
2734 | @@ -167,7 +175,7 @@ | |||
2735 | 167 | return deferred | 175 | return deferred |
2736 | 168 | 176 | ||
2737 | 169 | def test_status_changed_affects_cuurent_status(self): | 177 | def test_status_changed_affects_cuurent_status(self): |
2739 | 170 | """Makes changes to see how status are reflected.""" | 178 | """Make changes to see how status are reflected.""" |
2740 | 171 | # one set of values | 179 | # one set of values |
2741 | 172 | self.sd.on_sd_status_changed('name1', 'description1', False, True, | 180 | self.sd.on_sd_status_changed('name1', 'description1', False, True, |
2742 | 173 | False, 'queues1', 'connection1') | 181 | False, 'queues1', 'connection1') |
2743 | @@ -229,13 +237,42 @@ | |||
2744 | 229 | self.assertEqual(self.sd.current_state.queues, '') | 237 | self.assertEqual(self.sd.current_state.queues, '') |
2745 | 230 | self.assertEqual(self.sd.current_state.connection, '') | 238 | self.assertEqual(self.sd.current_state.connection, '') |
2746 | 231 | 239 | ||
2747 | 240 | def test_processing_meta_if_working_on_meta_or_both(self): | ||
2748 | 241 | """Status.processing_meta is True when WORKING_ON_{METADATA,BOTH}.""" | ||
2749 | 242 | |||
2750 | 243 | msg = 'processing_meta must be False when %s.' | ||
2751 | 244 | for state in ('WORKING_ON_CONTENT', ''): | ||
2752 | 245 | self.sd.current_state.set(queues=state) | ||
2753 | 246 | self.assertFalse(self.sd.current_state.processing_meta, | ||
2754 | 247 | msg % state) | ||
2755 | 248 | |||
2756 | 249 | msg = 'processing_meta must be True when %s.' | ||
2757 | 250 | for state in ('WORKING_ON_METADATA', 'WORKING_ON_BOTH'): | ||
2758 | 251 | self.sd.current_state.set(queues=state) | ||
2759 | 252 | self.assertTrue(self.sd.current_state.processing_meta, msg % state) | ||
2760 | 253 | |||
2761 | 254 | def test_processing_content_if_working_on_content_or_both(self): | ||
2762 | 255 | """Status.processing_content is True when WORKING_ON_{CONTENT,BOTH}.""" | ||
2763 | 256 | |||
2764 | 257 | msg = 'processing_content must be False when %s.' | ||
2765 | 258 | for state in ('WORKING_ON_METADATA', ''): | ||
2766 | 259 | self.sd.current_state.set(queues=state) | ||
2767 | 260 | self.assertFalse(self.sd.current_state.processing_content, | ||
2768 | 261 | msg % state) | ||
2769 | 262 | |||
2770 | 263 | msg = 'processing_content must be True when %s.' | ||
2771 | 264 | for state in ('WORKING_ON_CONTENT', 'WORKING_ON_BOTH'): | ||
2772 | 265 | self.sd.current_state.set(queues=state) | ||
2773 | 266 | self.assertTrue(self.sd.current_state.processing_content, | ||
2774 | 267 | msg % state) | ||
2775 | 268 | |||
2776 | 232 | 269 | ||
2777 | 233 | class ContentQueueChangedTests(BaseTest): | 270 | class ContentQueueChangedTests(BaseTest): |
2778 | 234 | """Check the ContenQueueChanged handling.""" | 271 | """Check the ContenQueueChanged handling.""" |
2779 | 235 | 272 | ||
2780 | 236 | @defer.inlineCallbacks | 273 | @defer.inlineCallbacks |
2781 | 237 | def test_initial_value(self): | 274 | def test_initial_value(self): |
2783 | 238 | """Fills the content queue info initially.""" | 275 | """Fill the content queue info initially.""" |
2784 | 239 | called = [] | 276 | called = [] |
2785 | 240 | self.sd.dbus.get_content_queue = lambda: called.append(True) | 277 | self.sd.dbus.get_content_queue = lambda: called.append(True) |
2786 | 241 | yield self.sd._get_initial_data() | 278 | yield self.sd._get_initial_data() |
2787 | @@ -311,13 +348,19 @@ | |||
2788 | 311 | def setUp(self): | 348 | def setUp(self): |
2789 | 312 | """Set up.""" | 349 | """Set up.""" |
2790 | 313 | BaseTest.setUp(self) | 350 | BaseTest.setUp(self) |
2792 | 314 | self.sd.current_state._set(queues='WORKING_ON_METADATA') | 351 | self.sd.current_state.set(queues='WORKING_ON_METADATA') |
2793 | 315 | 352 | ||
2794 | 316 | @defer.inlineCallbacks | 353 | @defer.inlineCallbacks |
2795 | 317 | def test_initial_value(self): | 354 | def test_initial_value(self): |
2797 | 318 | """Fills the meta queue info initially.""" | 355 | """Fill the meta queue info initially.""" |
2798 | 319 | called = [] | 356 | called = [] |
2800 | 320 | self.sd.dbus.get_meta_queue = lambda: called.append(True) | 357 | |
2801 | 358 | def f(): | ||
2802 | 359 | """Helper function.""" | ||
2803 | 360 | called.append(True) | ||
2804 | 361 | return [] | ||
2805 | 362 | |||
2806 | 363 | self.sd.dbus.get_meta_queue = f | ||
2807 | 321 | yield self.sd._get_initial_data() | 364 | yield self.sd._get_initial_data() |
2808 | 322 | self.assertTrue(called) | 365 | self.assertTrue(called) |
2809 | 323 | 366 | ||
2810 | @@ -373,10 +416,12 @@ | |||
2811 | 373 | """Check that it polls mq while working in metadata not being in QM.""" | 416 | """Check that it polls mq while working in metadata not being in QM.""" |
2812 | 374 | # set the callback | 417 | # set the callback |
2813 | 375 | deferred = defer.Deferred() | 418 | deferred = defer.Deferred() |
2814 | 419 | |||
2815 | 376 | def fake(): | 420 | def fake(): |
2816 | 377 | """Fake.""" | 421 | """Fake.""" |
2817 | 378 | deferred.callback(True) | 422 | deferred.callback(True) |
2818 | 379 | return defer.succeed("foo") | 423 | return defer.succeed("foo") |
2819 | 424 | |||
2820 | 380 | self.sd.dbus.get_meta_queue = fake | 425 | self.sd.dbus.get_meta_queue = fake |
2821 | 381 | 426 | ||
2822 | 382 | # send status changed to working in metadata | 427 | # send status changed to working in metadata |
2823 | @@ -389,10 +434,12 @@ | |||
2824 | 389 | """Check that it polls mq while working in metadata being in QM.""" | 434 | """Check that it polls mq while working in metadata being in QM.""" |
2825 | 390 | # set the callback | 435 | # set the callback |
2826 | 391 | deferred = defer.Deferred() | 436 | deferred = defer.Deferred() |
2827 | 437 | |||
2828 | 392 | def fake(): | 438 | def fake(): |
2829 | 393 | """Fake.""" | 439 | """Fake.""" |
2830 | 394 | deferred.callback(True) | 440 | deferred.callback(True) |
2831 | 395 | return defer.succeed("foo") | 441 | return defer.succeed("foo") |
2832 | 442 | |||
2833 | 396 | self.sd.dbus.get_meta_queue = fake | 443 | self.sd.dbus.get_meta_queue = fake |
2834 | 397 | 444 | ||
2835 | 398 | # send status changed to working in metadata | 445 | # send status changed to working in metadata |
2836 | @@ -405,10 +452,12 @@ | |||
2837 | 405 | """Check that it polls mq while working in both.""" | 452 | """Check that it polls mq while working in both.""" |
2838 | 406 | # set the callback | 453 | # set the callback |
2839 | 407 | deferred = defer.Deferred() | 454 | deferred = defer.Deferred() |
2840 | 455 | |||
2841 | 408 | def fake(): | 456 | def fake(): |
2842 | 409 | """Fake.""" | 457 | """Fake.""" |
2843 | 410 | deferred.callback(True) | 458 | deferred.callback(True) |
2844 | 411 | return defer.succeed("foo") | 459 | return defer.succeed("foo") |
2845 | 460 | |||
2846 | 412 | self.sd.dbus.get_meta_queue = fake | 461 | self.sd.dbus.get_meta_queue = fake |
2847 | 413 | 462 | ||
2848 | 414 | # send status changed to working in metadata | 463 | # send status changed to working in metadata |
2849 | @@ -417,14 +466,47 @@ | |||
2850 | 417 | 'connection') | 466 | 'connection') |
2851 | 418 | return deferred | 467 | return deferred |
2852 | 419 | 468 | ||
2853 | 469 | def test_mq_polls_last_time(self): | ||
2854 | 470 | """Was polling, state changed, it needs to poll a last time.""" | ||
2855 | 471 | # set the callback | ||
2856 | 472 | deferred = defer.Deferred() | ||
2857 | 473 | changed = self.sd.on_sd_status_changed | ||
2858 | 474 | called = [] | ||
2859 | 475 | |||
2860 | 476 | def fake(): | ||
2861 | 477 | """Fake.""" | ||
2862 | 478 | called.append(None) | ||
2863 | 479 | if len(called) == 1: | ||
2864 | 480 | changed('QUEUE_MANAGER', 'description', False, True, False, | ||
2865 | 481 | 'WORKING_ON_CONTENT', 'connection') | ||
2866 | 482 | elif len(called) == 2: | ||
2867 | 483 | # check that the caller is set back to None | ||
2868 | 484 | self.assertTrue(self.sd._mqcaller is None) | ||
2869 | 485 | deferred.callback(True) | ||
2870 | 486 | return defer.succeed("foo") | ||
2871 | 487 | |||
2872 | 488 | self.sd.dbus.get_meta_queue = fake | ||
2873 | 489 | |||
2874 | 490 | # send status changed to working in metadata | ||
2875 | 491 | changed('QUEUE_MANAGER', 'description', False, True, False, | ||
2876 | 492 | 'WORKING_ON_BOTH', 'connection') | ||
2877 | 493 | return deferred | ||
2878 | 494 | |||
2879 | 495 | def test_mq_caller_is_reset_last_time(self): | ||
2880 | 496 | """When MQ is polled last time, the caller should be back to None.""" | ||
2881 | 497 | self.sd._mqcaller = reactor.callLater(100, lambda: None) | ||
2882 | 498 | self.sd.current_state.set(name='QUEUE_MANAGER', | ||
2883 | 499 | queues='WORKING_ON_CONTENT') | ||
2884 | 500 | |||
2885 | 501 | # call the method and check | ||
2886 | 502 | self.sd._check_mq() | ||
2887 | 503 | self.assertTrue(self.sd._mqcaller is None) | ||
2888 | 504 | |||
2889 | 420 | def test_mq_polling_untilfinish(self): | 505 | def test_mq_polling_untilfinish(self): |
2890 | 421 | """Check that it polls mq until no more is needed.""" | 506 | """Check that it polls mq until no more is needed.""" |
2891 | 422 | d2 = dict(name='QUEUE_MANAGER', queues='WORKING_ON_CONTENT', | ||
2892 | 423 | description='description', is_error='', is_connected='True', | ||
2893 | 424 | is_online='', connection='conn') | ||
2894 | 425 | |||
2895 | 426 | # set the callback, and adjust the polling time to faster | 507 | # set the callback, and adjust the polling time to faster |
2896 | 427 | calls = [] | 508 | calls = [] |
2897 | 509 | |||
2898 | 428 | def fake_get(*a): | 510 | def fake_get(*a): |
2899 | 429 | """Fake get.""" | 511 | """Fake get.""" |
2900 | 430 | calls.append(None) | 512 | calls.append(None) |
2901 | @@ -437,6 +519,8 @@ | |||
2902 | 437 | 519 | ||
2903 | 438 | # allow time to see if a mistaken call happens | 520 | # allow time to see if a mistaken call happens |
2904 | 439 | reactor.callLater(.5, deferred.callback, True) | 521 | reactor.callLater(.5, deferred.callback, True) |
2905 | 522 | elif len(calls) == 4: | ||
2906 | 523 | pass # last call after state changed | ||
2907 | 440 | else: | 524 | else: |
2908 | 441 | deferred.errback(ValueError("Too many calls")) | 525 | deferred.errback(ValueError("Too many calls")) |
2909 | 442 | return defer.succeed("foo") | 526 | return defer.succeed("foo") |
2910 | @@ -480,7 +564,7 @@ | |||
2911 | 480 | def test_set_one_value(self): | 564 | def test_set_one_value(self): |
2912 | 481 | """Set one value.""" | 565 | """Set one value.""" |
2913 | 482 | st = State() | 566 | st = State() |
2915 | 483 | st._set(name=55) | 567 | st.set(name=55) |
2916 | 484 | 568 | ||
2917 | 485 | # check the one is set, the rest not | 569 | # check the one is set, the rest not |
2918 | 486 | self.assertEqual(st.name, 55) | 570 | self.assertEqual(st.name, 55) |
2919 | @@ -489,7 +573,7 @@ | |||
2920 | 489 | def test_set_two_values(self): | 573 | def test_set_two_values(self): |
2921 | 490 | """Set two values.""" | 574 | """Set two values.""" |
2922 | 491 | st = State() | 575 | st = State() |
2924 | 492 | st._set(name=55, description=77) | 576 | st.set(name=55, description=77) |
2925 | 493 | 577 | ||
2926 | 494 | # check those two are set, the rest not | 578 | # check those two are set, the rest not |
2927 | 495 | self.assertEqual(st.name, 55) | 579 | self.assertEqual(st.name, 55) |
2928 | @@ -499,7 +583,7 @@ | |||
2929 | 499 | def test_bad_value(self): | 583 | def test_bad_value(self): |
2930 | 500 | """Set a value that should not.""" | 584 | """Set a value that should not.""" |
2931 | 501 | st = State() | 585 | st = State() |
2933 | 502 | self.assertRaises(AttributeError, st._set, not_really_allowed=44) | 586 | self.assertRaises(AttributeError, st.set, not_really_allowed=44) |
2934 | 503 | 587 | ||
2935 | 504 | 588 | ||
2936 | 505 | class APITests(unittest.TestCase): | 589 | class APITests(unittest.TestCase): |
2937 | @@ -617,7 +701,6 @@ | |||
2938 | 617 | self.assertTrue(self.called) | 701 | self.assertTrue(self.called) |
2939 | 618 | 702 | ||
2940 | 619 | 703 | ||
2941 | 620 | |||
2942 | 621 | class TestLogs(unittest.TestCase): | 704 | class TestLogs(unittest.TestCase): |
2943 | 622 | """Test logging.""" | 705 | """Test logging.""" |
2944 | 623 | 706 | ||
2945 | @@ -634,100 +717,128 @@ | |||
2946 | 634 | 717 | ||
2947 | 635 | def test_instancing(self): | 718 | def test_instancing(self): |
2948 | 636 | """Just logged SD instancing.""" | 719 | """Just logged SD instancing.""" |
2950 | 637 | self.assertTrue(self.hdlr.check_inf("SyncDaemon interface started!")) | 720 | self.assertTrue(self.hdlr.check_info("SyncDaemon interface started!")) |
2951 | 638 | 721 | ||
2952 | 639 | def test_shutdown(self): | 722 | def test_shutdown(self): |
2953 | 640 | """Log when SD shutdowns.""" | 723 | """Log when SD shutdowns.""" |
2954 | 641 | self.sd.shutdown() | 724 | self.sd.shutdown() |
2956 | 642 | self.assertTrue(self.hdlr.check_inf("SyncDaemon interface going down")) | 725 | msg = "SyncDaemon interface going down" |
2957 | 726 | self.assertTrue(self.hdlr.check_info(msg)) | ||
2958 | 643 | 727 | ||
2959 | 644 | @defer.inlineCallbacks | 728 | @defer.inlineCallbacks |
2960 | 645 | def test_initial_value(self): | 729 | def test_initial_value(self): |
2961 | 646 | """Log the initial filling.""" | 730 | """Log the initial filling.""" |
2962 | 647 | yield self.sd._get_initial_data() | 731 | yield self.sd._get_initial_data() |
2964 | 648 | self.assertTrue(self.hdlr.check_inf("Getting initial data")) | 732 | self.assertTrue(self.hdlr.check_info("Getting initial data")) |
2965 | 649 | 733 | ||
2966 | 650 | def test_start(self): | 734 | def test_start(self): |
2967 | 651 | """Log the call to start.""" | 735 | """Log the call to start.""" |
2968 | 652 | self.sd.start() | 736 | self.sd.start() |
2970 | 653 | self.assertTrue(self.hdlr.check_inf("Starting u1.SD")) | 737 | self.assertTrue(self.hdlr.check_info("Starting u1.SD")) |
2971 | 654 | 738 | ||
2972 | 655 | def test_quit(self): | 739 | def test_quit(self): |
2973 | 656 | """Log the call to quit.""" | 740 | """Log the call to quit.""" |
2974 | 657 | self.sd.quit() | 741 | self.sd.quit() |
2976 | 658 | self.assertTrue(self.hdlr.check_inf("Stopping u1.SD")) | 742 | self.assertTrue(self.hdlr.check_info("Stopping u1.SD")) |
2977 | 659 | 743 | ||
2978 | 660 | def test_connect(self): | 744 | def test_connect(self): |
2979 | 661 | """Log the call to connect.""" | 745 | """Log the call to connect.""" |
2980 | 662 | self.sd.connect() | 746 | self.sd.connect() |
2982 | 663 | self.assertTrue(self.hdlr.check_inf("Telling u1.SD to connect")) | 747 | self.assertTrue(self.hdlr.check_info("Telling u1.SD to connect")) |
2983 | 664 | 748 | ||
2984 | 665 | def test_disconnect(self): | 749 | def test_disconnect(self): |
2985 | 666 | """Log the call to disconnect.""" | 750 | """Log the call to disconnect.""" |
2986 | 667 | self.sd.disconnect() | 751 | self.sd.disconnect() |
2988 | 668 | self.assertTrue(self.hdlr.check_inf("Telling u1.SD to disconnect")) | 752 | self.assertTrue(self.hdlr.check_info("Telling u1.SD to disconnect")) |
2989 | 669 | 753 | ||
2990 | 670 | def test_check_mq_true(self): | 754 | def test_check_mq_true(self): |
2991 | 671 | """Log the MQ check when it asks for info.""" | 755 | """Log the MQ check when it asks for info.""" |
2993 | 672 | self.sd.current_state._set(name='QUEUE_MANAGER', | 756 | self.sd.current_state.set(name='QUEUE_MANAGER', |
2994 | 673 | queues='WORKING_ON_METADATA') | 757 | queues='WORKING_ON_METADATA') |
2995 | 674 | self.sd._check_mq() | 758 | self.sd._check_mq() |
2997 | 675 | self.assertTrue(self.hdlr.check_inf("Asking for MQ information")) | 759 | self.assertTrue(self.hdlr.check_info("Asking for MQ information")) |
2998 | 676 | 760 | ||
2999 | 677 | def test_check_mq_noreally(self): | 761 | def test_check_mq_noreally(self): |
3000 | 678 | """Log the MQ check when it should not work.""" | 762 | """Log the MQ check when it should not work.""" |
3002 | 679 | self.sd.current_state._set(name='QUEUE_MANAGER', | 763 | self.sd.current_state.set(name='QUEUE_MANAGER', |
3003 | 680 | queues='WORKING_ON_CONTENT') | 764 | queues='WORKING_ON_CONTENT') |
3004 | 681 | self.sd._check_mq() | 765 | self.sd._check_mq() |
3007 | 682 | self.assertTrue(self.hdlr.check_inf( | 766 | self.assertTrue(self.hdlr.check_info( |
3008 | 683 | "Check MQ called but States not in MQ")) | 767 | "Check MQ called, States not in MQ, call a last time")) |
3009 | 684 | 768 | ||
3010 | 685 | def test_meta_queue_changed(self): | 769 | def test_meta_queue_changed(self): |
3011 | 686 | """Log that MQ has new data.""" | 770 | """Log that MQ has new data.""" |
3012 | 687 | self.sd.dbus.get_meta_queue = lambda: defer.succeed(['foo']) | 771 | self.sd.dbus.get_meta_queue = lambda: defer.succeed(['foo']) |
3014 | 688 | self.sd.current_state._set(name='QUEUE_MANAGER', | 772 | self.sd.current_state.set(name='QUEUE_MANAGER', |
3015 | 689 | queues='WORKING_ON_METADATA') | 773 | queues='WORKING_ON_METADATA') |
3016 | 690 | self.sd._check_mq() | 774 | self.sd._check_mq() |
3018 | 691 | self.assertTrue(self.hdlr.check_inf("SD Meta Queue changed: 1 items")) | 775 | self.assertTrue(self.hdlr.check_info("SD Meta Queue changed: 1 items")) |
3019 | 692 | 776 | ||
3020 | 693 | def test_content_queue_changed(self): | 777 | def test_content_queue_changed(self): |
3021 | 694 | """Log that process_cq has new data.""" | 778 | """Log that process_cq has new data.""" |
3022 | 695 | self.sd.dbus.get_content_queue = lambda: defer.succeed(['foo']) | 779 | self.sd.dbus.get_content_queue = lambda: defer.succeed(['foo']) |
3023 | 696 | self.sd.on_sd_content_queue_changed() | 780 | self.sd.on_sd_content_queue_changed() |
3026 | 697 | self.assertTrue(self.hdlr.check_inf("SD Content Queue changed")) | 781 | self.assertTrue(self.hdlr.check_info("SD Content Queue changed")) |
3027 | 698 | self.assertTrue(self.hdlr.check_inf( | 782 | self.assertTrue(self.hdlr.check_info( |
3028 | 699 | "Content Queue info is new! 1 items")) | 783 | "Content Queue info is new! 1 items")) |
3029 | 700 | 784 | ||
3030 | 701 | def test_on_status_changed(self): | 785 | def test_on_status_changed(self): |
3031 | 702 | """Log status changed.""" | 786 | """Log status changed.""" |
3032 | 703 | self.sd.on_sd_status_changed('name', 'description', False, True, | 787 | self.sd.on_sd_status_changed('name', 'description', False, True, |
3033 | 704 | False, 'queues', 'connection') | 788 | False, 'queues', 'connection') |
3036 | 705 | self.assertTrue(self.hdlr.check_inf("SD Status changed")) | 789 | self.assertTrue(self.hdlr.check_info("SD Status changed")) |
3037 | 706 | self.assertTrue(self.hdlr.check_dbg(" new status: name=u'name', " | 790 | self.assertTrue(self.hdlr.check_debug(" new status: name=u'name', " |
3038 | 707 | "description=u'description', is_error=False, is_connected=True, " | 791 | "description=u'description', is_error=False, is_connected=True, " |
3039 | 708 | "is_online=False, queues=u'queues', connection=u'connection'")) | 792 | "is_online=False, queues=u'queues', connection=u'connection'")) |
3040 | 709 | 793 | ||
3041 | 710 | def test_folders_changed(self): | 794 | def test_folders_changed(self): |
3042 | 711 | """Log when folders changed.""" | 795 | """Log when folders changed.""" |
3043 | 712 | self.sd.on_sd_folders_changed() | 796 | self.sd.on_sd_folders_changed() |
3045 | 713 | self.assertTrue(self.hdlr.check_inf("SD Folders changed")) | 797 | self.assertTrue(self.hdlr.check_info("SD Folders changed")) |
3046 | 714 | 798 | ||
3047 | 715 | def test_shares_changed(self): | 799 | def test_shares_changed(self): |
3048 | 716 | """Log when shares changed.""" | 800 | """Log when shares changed.""" |
3049 | 717 | self.sd.on_sd_shares_changed() | 801 | self.sd.on_sd_shares_changed() |
3051 | 718 | self.assertTrue(self.hdlr.check_inf("SD Shares changed")) | 802 | self.assertTrue(self.hdlr.check_info("SD Shares changed")) |
3052 | 719 | 803 | ||
3053 | 720 | def test_on_name_owner_changed(self): | 804 | def test_on_name_owner_changed(self): |
3054 | 721 | """Log name owner changed.""" | 805 | """Log name owner changed.""" |
3055 | 722 | self.sd.on_sd_name_owner_changed(True) | 806 | self.sd.on_sd_name_owner_changed(True) |
3057 | 723 | self.assertTrue(self.hdlr.check_inf("SD Name Owner changed: True")) | 807 | self.assertTrue(self.hdlr.check_info("SD Name Owner changed: True")) |
3058 | 808 | |||
3059 | 809 | |||
3060 | 810 | class MetadataTests(BaseTest): | ||
3061 | 811 | """Get Metadata info.""" | ||
3062 | 812 | |||
3063 | 813 | def test_get_metadata_no_callback_set(self): | ||
3064 | 814 | """It's mandatory to set the callback for this response.""" | ||
3065 | 815 | self.assertRaises(ValueError, self.sd.get_metadata, 'path') | ||
3066 | 816 | |||
3067 | 817 | def test_get_metadata_ok(self): | ||
3068 | 818 | """Get the metadata for given path.""" | ||
3069 | 819 | called = [] | ||
3070 | 820 | self.sd.dbus.get_metadata = lambda p: defer.succeed('foo') | ||
3071 | 821 | self.sd.on_metadata_ready_callback = lambda *a: called.extend(a) | ||
3072 | 822 | self.sd.get_metadata('path') | ||
3073 | 823 | self.assertEqual(called, ['path', 'foo']) | ||
3074 | 824 | |||
3075 | 825 | def test_get_metadata_double(self): | ||
3076 | 826 | """Get the metadata twice.""" | ||
3077 | 827 | called = [] | ||
3078 | 828 | fake_md = {'path1': 'foo', 'path2': 'bar'} | ||
3079 | 829 | self.sd.dbus.get_metadata = lambda p: defer.succeed(fake_md[p]) | ||
3080 | 830 | self.sd.on_metadata_ready_callback = lambda *a: called.append(a) | ||
3081 | 831 | self.sd.get_metadata('path1') | ||
3082 | 832 | self.sd.get_metadata('path2') | ||
3083 | 833 | self.assertEqual(called[0], ('path1', 'foo')) | ||
3084 | 834 | self.assertEqual(called[1], ('path2', 'bar')) | ||
3085 | 724 | 835 | ||
3086 | 725 | 836 | ||
3087 | 726 | class FoldersTests(BaseTest): | 837 | class FoldersTests(BaseTest): |
3088 | 727 | """Folders checking.""" | 838 | """Folders checking.""" |
3089 | 728 | 839 | ||
3090 | 729 | def test_foldercreated_callback(self): | 840 | def test_foldercreated_callback(self): |
3092 | 730 | """Gets the new data after the folders changed.""" | 841 | """Get the new data after the folders changed.""" |
3093 | 731 | # set the callback | 842 | # set the callback |
3094 | 732 | called = [] | 843 | called = [] |
3095 | 733 | self.sd.dbus.get_folders = lambda: called.append(True) | 844 | self.sd.dbus.get_folders = lambda: called.append(True) |
3096 | @@ -740,7 +851,7 @@ | |||
3097 | 740 | 851 | ||
3098 | 741 | @defer.inlineCallbacks | 852 | @defer.inlineCallbacks |
3099 | 742 | def test_initial_value(self): | 853 | def test_initial_value(self): |
3101 | 743 | """Fills the folder info initially.""" | 854 | """Fill the folder info initially.""" |
3102 | 744 | called = [] | 855 | called = [] |
3103 | 745 | self.sd.dbus.get_folders = lambda: called.append(True) | 856 | self.sd.dbus.get_folders = lambda: called.append(True) |
3104 | 746 | yield self.sd._get_initial_data() | 857 | yield self.sd._get_initial_data() |
3105 | @@ -763,7 +874,7 @@ | |||
3106 | 763 | """Shares checking.""" | 874 | """Shares checking.""" |
3107 | 764 | 875 | ||
3108 | 765 | def test_shares_changed_callback(self): | 876 | def test_shares_changed_callback(self): |
3110 | 766 | """Gets the new data after the shares changed.""" | 877 | """Get the new data after the shares changed.""" |
3111 | 767 | # set the callback | 878 | # set the callback |
3112 | 768 | called = [] | 879 | called = [] |
3113 | 769 | self.sd.dbus.get_shares_to_me = lambda: called.append(True) | 880 | self.sd.dbus.get_shares_to_me = lambda: called.append(True) |
3114 | @@ -777,7 +888,7 @@ | |||
3115 | 777 | 888 | ||
3116 | 778 | @defer.inlineCallbacks | 889 | @defer.inlineCallbacks |
3117 | 779 | def test_initial_value(self): | 890 | def test_initial_value(self): |
3119 | 780 | """Fills the folder info initially.""" | 891 | """Fill the folder info initially.""" |
3120 | 781 | called = [] | 892 | called = [] |
3121 | 782 | self.sd.dbus.get_shares_to_me = lambda: called.append(True) | 893 | self.sd.dbus.get_shares_to_me = lambda: called.append(True) |
3122 | 783 | self.sd.dbus.get_shares_to_others = lambda: called.append(True) | 894 | self.sd.dbus.get_shares_to_others = lambda: called.append(True) |
3123 | @@ -793,7 +904,7 @@ | |||
3124 | 793 | 904 | ||
3125 | 794 | # they changed! | 905 | # they changed! |
3126 | 795 | self.sd.shares_to_me = 'foo' | 906 | self.sd.shares_to_me = 'foo' |
3128 | 796 | self.sd.shares_to_others = 'fakedata' # what fake dbus will return | 907 | self.sd.shares_to_others = 'fakedata' # what fake dbus will return |
3129 | 797 | self.sd.on_sd_shares_changed() | 908 | self.sd.on_sd_shares_changed() |
3130 | 798 | 909 | ||
3131 | 799 | # test | 910 | # test |
3132 | @@ -808,7 +919,7 @@ | |||
3133 | 808 | 919 | ||
3134 | 809 | # they changed! | 920 | # they changed! |
3135 | 810 | self.sd.shares_to_others = 'foo' | 921 | self.sd.shares_to_others = 'foo' |
3137 | 811 | self.sd.shares_to_me = 'fakedata' # what fake dbus will return | 922 | self.sd.shares_to_me = 'fakedata' # what fake dbus will return |
3138 | 812 | self.sd.on_sd_shares_changed() | 923 | self.sd.on_sd_shares_changed() |
3139 | 813 | 924 | ||
3140 | 814 | # test | 925 | # test |
3141 | 815 | 926 | ||
3142 | === modified file 'setup.py' | |||
3143 | --- setup.py 2010-06-08 10:53:02 +0000 | |||
3144 | +++ setup.py 2010-07-09 18:33:43 +0000 | |||
3145 | @@ -4,7 +4,9 @@ | |||
3146 | 4 | # This file is in the public domain | 4 | # This file is in the public domain |
3147 | 5 | ### END LICENSE | 5 | ### END LICENSE |
3148 | 6 | 6 | ||
3150 | 7 | ###################### DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ###################### | 7 | """Build tar.gz and related for magicicada.""" |
3151 | 8 | |||
3152 | 9 | ################# DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ################# | ||
3153 | 8 | 10 | ||
3154 | 9 | import os | 11 | import os |
3155 | 10 | import sys | 12 | import sys |
3156 | @@ -12,24 +14,28 @@ | |||
3157 | 12 | try: | 14 | try: |
3158 | 13 | import DistUtilsExtra.auto | 15 | import DistUtilsExtra.auto |
3159 | 14 | except ImportError: | 16 | except ImportError: |
3161 | 15 | print >> sys.stderr, 'To build magicicada you need https://launchpad.net/python-distutils-extra' | 17 | url = 'https://launchpad.net/python-distutils-extra' |
3162 | 18 | print >> sys.stderr, 'To build magicicada you need', url | ||
3163 | 16 | sys.exit(1) | 19 | sys.exit(1) |
3165 | 17 | assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18' | 20 | assert DistUtilsExtra.auto.__version__ >= '2.18', \ |
3166 | 21 | 'needs DistUtilsExtra.auto >= 2.18' | ||
3167 | 22 | |||
3168 | 18 | 23 | ||
3169 | 19 | def update_data_path(prefix, oldvalue=None): | 24 | def update_data_path(prefix, oldvalue=None): |
3170 | 25 | """Update data path.""" | ||
3171 | 20 | 26 | ||
3172 | 21 | try: | 27 | try: |
3173 | 22 | fin = file('magicicada/magicicadaconfig.py', 'r') | 28 | fin = file('magicicada/magicicadaconfig.py', 'r') |
3174 | 23 | fout = file(fin.name + '.new', 'w') | 29 | fout = file(fin.name + '.new', 'w') |
3175 | 24 | 30 | ||
3178 | 25 | for line in fin: | 31 | for line in fin: |
3179 | 26 | fields = line.split(' = ') # Separate variable from value | 32 | fields = line.split(' = ') # Separate variable from value |
3180 | 27 | if fields[0] == '__magicicada_data_directory__': | 33 | if fields[0] == '__magicicada_data_directory__': |
3181 | 28 | # update to prefix, store oldvalue | 34 | # update to prefix, store oldvalue |
3182 | 29 | if not oldvalue: | 35 | if not oldvalue: |
3183 | 30 | oldvalue = fields[1] | 36 | oldvalue = fields[1] |
3184 | 31 | line = "%s = '%s'\n" % (fields[0], prefix) | 37 | line = "%s = '%s'\n" % (fields[0], prefix) |
3186 | 32 | else: # restore oldvalue | 38 | else: # restore oldvalue |
3187 | 33 | line = "%s = %s" % (fields[0], oldvalue) | 39 | line = "%s = %s" % (fields[0], oldvalue) |
3188 | 34 | fout.write(line) | 40 | fout.write(line) |
3189 | 35 | 41 | ||
3190 | @@ -37,19 +43,20 @@ | |||
3191 | 37 | fout.close() | 43 | fout.close() |
3192 | 38 | fin.close() | 44 | fin.close() |
3193 | 39 | os.rename(fout.name, fin.name) | 45 | os.rename(fout.name, fin.name) |
3195 | 40 | except (OSError, IOError), e: | 46 | except (OSError, IOError): |
3196 | 41 | print ("ERROR: Can't find magicicada/magicicadaconfig.py") | 47 | print ("ERROR: Can't find magicicada/magicicadaconfig.py") |
3197 | 42 | sys.exit(1) | 48 | sys.exit(1) |
3198 | 43 | return oldvalue | 49 | return oldvalue |
3199 | 44 | 50 | ||
3200 | 45 | 51 | ||
3201 | 46 | def update_desktop_file(datadir): | 52 | def update_desktop_file(datadir): |
3202 | 53 | """Update desktop file.""" | ||
3203 | 47 | 54 | ||
3204 | 48 | try: | 55 | try: |
3205 | 49 | fin = file('magicicada.desktop.in', 'r') | 56 | fin = file('magicicada.desktop.in', 'r') |
3206 | 50 | fout = file(fin.name + '.new', 'w') | 57 | fout = file(fin.name + '.new', 'w') |
3207 | 51 | 58 | ||
3209 | 52 | for line in fin: | 59 | for line in fin: |
3210 | 53 | if 'Icon=' in line: | 60 | if 'Icon=' in line: |
3211 | 54 | line = "Icon=%s\n" % (datadir + 'media/icon.png') | 61 | line = "Icon=%s\n" % (datadir + 'media/icon.png') |
3212 | 55 | fout.write(line) | 62 | fout.write(line) |
3213 | @@ -57,33 +64,33 @@ | |||
3214 | 57 | fout.close() | 64 | fout.close() |
3215 | 58 | fin.close() | 65 | fin.close() |
3216 | 59 | os.rename(fout.name, fin.name) | 66 | os.rename(fout.name, fin.name) |
3218 | 60 | except (OSError, IOError), e: | 67 | except (OSError, IOError): |
3219 | 61 | print ("ERROR: Can't find magicicada.desktop.in") | 68 | print ("ERROR: Can't find magicicada.desktop.in") |
3220 | 62 | sys.exit(1) | 69 | sys.exit(1) |
3221 | 63 | 70 | ||
3222 | 64 | 71 | ||
3223 | 65 | class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto): | 72 | class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto): |
3224 | 73 | """Install and update data dir.""" | ||
3225 | 74 | |||
3226 | 66 | def run(self): | 75 | def run(self): |
3227 | 76 | """Run.""" | ||
3228 | 67 | previous_value = update_data_path(self.prefix + '/share/magicicada/') | 77 | previous_value = update_data_path(self.prefix + '/share/magicicada/') |
3229 | 68 | update_desktop_file(self.prefix + '/share/magicicada/') | 78 | update_desktop_file(self.prefix + '/share/magicicada/') |
3230 | 69 | DistUtilsExtra.auto.install_auto.run(self) | 79 | DistUtilsExtra.auto.install_auto.run(self) |
3231 | 70 | update_data_path(self.prefix, previous_value) | 80 | update_data_path(self.prefix, previous_value) |
3232 | 71 | 81 | ||
3233 | 72 | 82 | ||
3238 | 73 | 83 | ############################################################################## | |
3239 | 74 | ################################################################################## | 84 | #################### YOU SHOULD MODIFY ONLY WHAT IS BELOW #################### |
3240 | 75 | ###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ###################### | 85 | ############################################################################## |
3237 | 76 | ################################################################################## | ||
3241 | 77 | 86 | ||
3242 | 78 | DistUtilsExtra.auto.setup( | 87 | DistUtilsExtra.auto.setup( |
3243 | 79 | name='magicicada', | 88 | name='magicicada', |
3245 | 80 | version='0.1.1', | 89 | version='0.1.2', |
3246 | 81 | license='GPL-3', | 90 | license='GPL-3', |
3247 | 82 | author='Natalia Bidart', | 91 | author='Natalia Bidart', |
3248 | 83 | author_email='natalia.bidart@ubuntu.com', | 92 | author_email='natalia.bidart@ubuntu.com', |
3250 | 84 | description='A GTK+ frontend for the "Chicharra" part of Ubuntu One client.', | 93 | description='A GTK+ frontend for the "Chicharra" part of Ubuntu One.', |
3251 | 85 | #long_description='Here a longer description', | 94 | #long_description='Here a longer description', |
3252 | 86 | url='https://launchpad.net/magicicada', | 95 | url='https://launchpad.net/magicicada', |
3256 | 87 | cmdclass={'install': InstallAndUpdateDataDirectory} | 96 | cmdclass={'install': InstallAndUpdateDataDirectory}) |
3254 | 88 | ) | ||
3255 | 89 |