Merge lp:~alecu/ubuntuone-client/make-ziggy-optional into lp:ubuntuone-client

Proposed by Alejandro J. Cura on 2010-12-15
Status: Merged
Approved by: Alejandro J. Cura on 2010-12-17
Approved revision: 778
Merged at revision: 778
Proposed branch: lp:~alecu/ubuntuone-client/make-ziggy-optional
Merge into: lp:ubuntuone-client
Diff against target: 314 lines (+177/-10)
10 files modified
tests/eventlog/test_zg_listener.py (+14/-3)
tests/platform/linux/test_event_logging.py (+38/-0)
tests/platform/windows/test_event_logging.py (+36/-0)
tests/syncdaemon/test_main.py (+14/-0)
ubuntuone/eventlog/zg_listener.py (+1/-1)
ubuntuone/platform/linux/__init__.py (+1/-1)
ubuntuone/platform/linux/event_logging.py (+36/-0)
ubuntuone/platform/windows/__init__.py (+5/-2)
ubuntuone/platform/windows/event_logging.py (+22/-0)
ubuntuone/syncdaemon/main.py (+10/-3)
To merge this branch: bzr merge lp:~alecu/ubuntuone-client/make-ziggy-optional
Reviewer Review Type Date Requested Status
Natalia Bidart Approve on 2010-12-17
Facundo Batista 2010-12-15 Approve on 2010-12-15
Manuel de la Peña 2010-12-15 Pending
Review via email: mp+43812@code.launchpad.net

Commit Message

Zeitgeist is now not required to run syncdaemon.

Description of the Change

Move the zeitgeist logging code into the platform/linux module.
Zeitgeist is now not required to run syncdaemon.

To post a comment you must log in.
778. By Alejandro J. Cura on 2010-12-15

moved and fixed a testing module that was misplaced

Facundo Batista (facundo) wrote :

Great, thanks!

review: Approve
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed file 'tests/syncdaemon/test_event_logging.py' => 'tests/eventlog/test_zg_listener.py'
2--- tests/syncdaemon/test_event_logging.py 2010-12-13 23:40:14 +0000
3+++ tests/eventlog/test_zg_listener.py 2010-12-15 21:21:19 +0000
4@@ -1,6 +1,6 @@
5 # -*- coding: utf-8 -*-
6 #
7-# tests.syncdaemon.test_event_logging - test logging ZG events
8+# tests.eventlog.test_zg_listener - test logging ZG events
9 #
10 # Author: Alejandro J. Cura <alecu@canonical.com>
11 #
12@@ -22,6 +22,7 @@
13 import logging
14 import os
15 import shutil
16+import unittest
17 import uuid
18
19 from twisted.internet import defer
20@@ -35,7 +36,7 @@
21 from ubuntuone.storageprotocol.sharersp import NotifyShareHolder
22 from ubuntuone.syncdaemon.action_queue import (
23 RequestQueue, Upload, MakeFile, MakeDir)
24-from ubuntuone.syncdaemon.event_logging import (
25+from ubuntuone.eventlog.zg_listener import (
26 zglog, ZeitgeistListener, ACTOR_UBUNTUONE,
27 EVENT_INTERPRETATION_U1_FOLDER_SHARED,
28 EVENT_INTERPRETATION_U1_FOLDER_UNSHARED,
29@@ -51,7 +52,7 @@
30 STORAGE_DELETED, STORAGE_NETWORK, STORAGE_LOCAL)
31 from ubuntuone.syncdaemon.sync import Sync
32 from ubuntuone.syncdaemon.volume_manager import Share, Shared, UDF
33-from test_action_queue import ConnectedBaseTestCase
34+from tests.syncdaemon.test_action_queue import ConnectedBaseTestCase
35
36 VOLUME = uuid.UUID('12345678-1234-1234-1234-123456789abc')
37
38@@ -1136,3 +1137,13 @@
39 self.assertTrue(public_file.origin.endswith(node_id))
40 self.assertEqual(public_file.mimetype, "audio/mpeg")
41 self.assertEqual(public_file.storage, STORAGE_DELETED)
42+
43+
44+def test_suite():
45+ """Collect these tests only on linux."""
46+ import sys
47+ if sys.platform == 'linux2':
48+ tests = unittest.TestLoader().loadTestsFromName(__name__)
49+ else:
50+ tests = []
51+ return tests
52
53=== added file 'tests/platform/linux/test_event_logging.py'
54--- tests/platform/linux/test_event_logging.py 1970-01-01 00:00:00 +0000
55+++ tests/platform/linux/test_event_logging.py 2010-12-15 21:21:19 +0000
56@@ -0,0 +1,38 @@
57+# tests.platform.linux.test_event_logging
58+#
59+# Author: Alejandro J. Cura <alecu@canonical.com>
60+#
61+# Copyright 2010 Canonical Ltd.
62+#
63+# This program is free software: you can redistribute it and/or modify it
64+# under the terms of the GNU General Public License version 3, as published
65+# by the Free Software Foundation.
66+#
67+# This program is distributed in the hope that it will be useful, but
68+# WITHOUT ANY WARRANTY; without even the implied warranties of
69+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
70+# PURPOSE. See the GNU General Public License for more details.
71+#
72+# You should have received a copy of the GNU General Public License along
73+# with this program. If not, see <http://www.gnu.org/licenses/>.
74+"""Test the event logging on linux."""
75+
76+from twisted.trial.unittest import TestCase
77+
78+from ubuntuone.platform.linux import event_logging
79+
80+
81+class GetListenerTestCase(TestCase):
82+ """The zg listener is created."""
83+
84+ def test_zeitgeist_installed_returns_listener(self):
85+ """get_listener returns a listener if ZG installed."""
86+ self.patch(event_logging, "is_zeitgeist_installed", lambda: True)
87+ listener = event_logging.get_listener(None, None)
88+ self.assertNotEqual(listener, None)
89+
90+ def test_zeitgeist_not_installed_returns_none(self):
91+ """get_listener returns None if ZG not installed."""
92+ self.patch(event_logging, "is_zeitgeist_installed", lambda: False)
93+ listener = event_logging.get_listener(None, None)
94+ self.assertEqual(listener, None)
95
96=== added file 'tests/platform/windows/test_event_logging.py'
97--- tests/platform/windows/test_event_logging.py 1970-01-01 00:00:00 +0000
98+++ tests/platform/windows/test_event_logging.py 2010-12-15 21:21:19 +0000
99@@ -0,0 +1,36 @@
100+# tests.platform.windows.test_event_logging
101+#
102+# Author: Alejandro J. Cura <alecu@canonical.com>
103+#
104+# Copyright 2010 Canonical Ltd.
105+#
106+# This program is free software: you can redistribute it and/or modify it
107+# under the terms of the GNU General Public License version 3, as published
108+# by the Free Software Foundation.
109+#
110+# This program is distributed in the hope that it will be useful, but
111+# WITHOUT ANY WARRANTY; without even the implied warranties of
112+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
113+# PURPOSE. See the GNU General Public License for more details.
114+#
115+# You should have received a copy of the GNU General Public License along
116+# with this program. If not, see <http://www.gnu.org/licenses/>.
117+"""Test the event logging on windows."""
118+
119+import sys
120+
121+from twisted.trial import unittest
122+
123+class GetListenerTestCase(unittest.TestCase):
124+ """Listener creation tests."""
125+
126+ def test_never_creates_a_listener(self):
127+ """The listener is never created on windows."""
128+ from ubuntuone.platform.windows import event_logging
129+ listener = event_logging.get_listener(None, None)
130+ self.assertEqual(listener, None)
131+
132+def test_suite():
133+ if sys.platform == 'win32':
134+ return unittest.TestLoader().loadTestsFromName(__name__)
135+ return unittest.TestSuite()
136
137=== modified file 'tests/syncdaemon/test_main.py'
138--- tests/syncdaemon/test_main.py 2010-12-10 19:44:18 +0000
139+++ tests/syncdaemon/test_main.py 2010-12-15 21:21:19 +0000
140@@ -205,3 +205,17 @@
141 self.addCleanup(lambda: main.shutdown())
142
143 self.assertFalse(self.connect_called)
144+
145+ def test_event_logger_starts_if_available(self):
146+ """The event logger is started if available."""
147+ self.patch(main_mod.event_logging, "get_listener", lambda *a: object())
148+ main = self.build_main()
149+ self.addCleanup(lambda: main.shutdown())
150+ self.assertIn(main.eventlog_listener, main.event_q._listeners)
151+
152+ def test_event_logger_not_started_if_not_available(self):
153+ """The event logger is not started if it's not available."""
154+ self.patch(main_mod.event_logging, "get_listener", lambda *a: None)
155+ main = self.build_main()
156+ self.addCleanup(lambda: main.shutdown())
157+ self.assertNotIn(main.eventlog_listener, main.event_q._listeners)
158
159=== renamed file 'ubuntuone/syncdaemon/event_logging.py' => 'ubuntuone/eventlog/zg_listener.py'
160--- ubuntuone/syncdaemon/event_logging.py 2010-12-13 06:10:47 +0000
161+++ ubuntuone/eventlog/zg_listener.py 2010-12-15 21:21:19 +0000
162@@ -1,4 +1,4 @@
163-# ubuntuone.syncdaemon.event_logging - listen for SD events, log into ZG
164+# ubuntuone.eventlog.zg_listener - listen for SD events, log into ZG
165 #
166 # Author: Alejandro J. Cura <alecu@canonical.com>
167 #
168
169=== modified file 'ubuntuone/platform/linux/__init__.py'
170--- ubuntuone/platform/linux/__init__.py 2010-12-10 19:44:18 +0000
171+++ ubuntuone/platform/linux/__init__.py 2010-12-15 21:21:19 +0000
172@@ -40,7 +40,7 @@
173 )
174 from ubuntuone.platform.linux.vm_helper import (create_shares_link,
175 get_udf_path_name, get_udf_path, get_share_path, VMMetadataUpgraderMixIn)
176-from ubuntuone.platform.linux import tools
177+from ubuntuone.platform.linux import tools, event_logging
178 from filesystem_notifications import FilesystemMonitor
179
180
181
182=== added file 'ubuntuone/platform/linux/event_logging.py'
183--- ubuntuone/platform/linux/event_logging.py 1970-01-01 00:00:00 +0000
184+++ ubuntuone/platform/linux/event_logging.py 2010-12-15 21:21:19 +0000
185@@ -0,0 +1,36 @@
186+# ubuntuone.platform.linux.event_logging
187+#
188+# Author: Alejandro J. Cura <alecu@canonical.com>
189+#
190+# Copyright 2010 Canonical Ltd.
191+#
192+# This program is free software: you can redistribute it and/or modify it
193+# under the terms of the GNU General Public License version 3, as published
194+# by the Free Software Foundation.
195+#
196+# This program is distributed in the hope that it will be useful, but
197+# WITHOUT ANY WARRANTY; without even the implied warranties of
198+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
199+# PURPOSE. See the GNU General Public License for more details.
200+#
201+# You should have received a copy of the GNU General Public License along
202+# with this program. If not, see <http://www.gnu.org/licenses/>.
203+"""Builds a syncdaemon listener that logs events if ZG is installed."""
204+
205+def is_zeitgeist_installed():
206+ """Return true if zeitgeist is installed."""
207+ try:
208+ import zeitgeist
209+ # use the above module in some way so pylint does not complain
210+ assert(zeitgeist is not None)
211+ return True
212+ except ImportError:
213+ return False
214+
215+def get_listener(fsm, vm):
216+ """Build a listener if zg is installed."""
217+ if is_zeitgeist_installed():
218+ from ubuntuone.eventlog import zg_listener
219+ return zg_listener.ZeitgeistListener(fsm, vm)
220+ else:
221+ return None
222
223=== modified file 'ubuntuone/platform/windows/__init__.py'
224--- ubuntuone/platform/windows/__init__.py 2010-12-03 19:56:31 +0000
225+++ ubuntuone/platform/windows/__init__.py 2010-12-15 21:21:19 +0000
226@@ -17,8 +17,9 @@
227 # with this program. If not, see <http://www.gnu.org/licenses/>.
228 """Windows import for ubuntuone-client
229
230-This module has to have all windows specific modules and provide the api required
231-to support the windows platform."""
232+This module has to have all windows specific modules and provide the api
233+required to support the windows platform.
234+"""
235
236 platform = "win32"
237
238@@ -28,3 +29,5 @@
239 get_share_path,
240 VMMetadataUpgraderMixIn,
241 )
242+from ubuntuone.platform.windows import event_logging
243+
244
245=== added file 'ubuntuone/platform/windows/event_logging.py'
246--- ubuntuone/platform/windows/event_logging.py 1970-01-01 00:00:00 +0000
247+++ ubuntuone/platform/windows/event_logging.py 2010-12-15 21:21:19 +0000
248@@ -0,0 +1,22 @@
249+# ubuntuone.platform.windows.event_logging
250+#
251+# Author: Alejandro J. Cura <alecu@canonical.com>
252+#
253+# Copyright 2010 Canonical Ltd.
254+#
255+# This program is free software: you can redistribute it and/or modify it
256+# under the terms of the GNU General Public License version 3, as published
257+# by the Free Software Foundation.
258+#
259+# This program is distributed in the hope that it will be useful, but
260+# WITHOUT ANY WARRANTY; without even the implied warranties of
261+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
262+# PURPOSE. See the GNU General Public License for more details.
263+#
264+# You should have received a copy of the GNU General Public License along
265+# with this program. If not, see <http://www.gnu.org/licenses/>.
266+"""Event logging module for windows, that does nothing."""
267+
268+def get_listener(fsm, vm):
269+ """Zeitgeist is not available on windows yet."""
270+ return None
271
272=== modified file 'ubuntuone/syncdaemon/main.py'
273--- ubuntuone/syncdaemon/main.py 2010-12-10 19:44:18 +0000
274+++ ubuntuone/syncdaemon/main.py 2010-12-15 21:21:19 +0000
275@@ -30,7 +30,6 @@
276 event_queue,
277 filesystem_manager,
278 hash_queue,
279- event_logging,
280 events_nanny,
281 local_rescan,
282 sync,
283@@ -39,6 +38,7 @@
284 from ubuntuone import syncdaemon
285 import ubuntuone.platform
286
287+from ubuntuone.platform import event_logging
288 from ubuntuone.syncdaemon.states import StateManager, QueueManager
289
290
291@@ -128,14 +128,21 @@
292
293 self.action_q.content_queue.set_change_notification_cb(
294 self.external.change_notification)
295- self.zg_listener = event_logging.ZeitgeistListener(self.fs, self.vm)
296- self.event_q.subscribe(self.zg_listener)
297+
298+ self.eventlog_listener = None
299+ self.start_event_logger()
300 self.logger.info("Using %r as root dir", self.root_dir)
301 self.logger.info("Using %r as data dir", self.data_dir)
302 self.logger.info("Using %r as shares root dir", self.shares_dir)
303 self.mark = task.LoopingCall(self.log_mark)
304 self.mark.start(mark_interval)
305
306+ def start_event_logger(self):
307+ """Start the event logger if it's available for this platform."""
308+ self.eventlog_listener = event_logging.get_listener(self.fs, self.vm)
309+ if self.eventlog_listener:
310+ self.event_q.subscribe(self.eventlog_listener)
311+
312 def log_mark(self):
313 """Log a "mark" that includes the current AQ state and queue size."""
314 self.logger.note("---- MARK (state: %s; queues: metadata: %d; content:"

Subscribers

People subscribed via source and target branches