Remove or comment out print statements and improve logging.
authorDaira Hopwood <daira@jacaranda.org>
Tue, 15 Sep 2015 15:43:41 +0000 (16:43 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Wed, 30 Sep 2015 15:45:27 +0000 (16:45 +0100)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/backupdb.py
src/allmydata/frontends/magic_folder.py
src/allmydata/test/test_cli_magic_folder.py
src/allmydata/test/test_magic_folder.py
src/allmydata/util/deferredutil.py

index e6f723ae3b992c5946c930e81f46630569abbf9e..a51356cae31803b57ae0322dcd50d0f95ced61ca 100644 (file)
@@ -421,7 +421,7 @@ class MagicFolderDB(BackupDB):
         meaning its current statinfo (i.e. size, ctime, and mtime) matched the statinfo
         that was previously stored in the db.
         """
-        print "check_file_time %s %s" % (path, relpath_u)
+        #print "check_file_time %s %s" % (path, relpath_u)
         path = abspath_expanduser_unicode(path)
         s = os.stat(path)
         size = s[stat.ST_SIZE]
index 20bcf50ae5fd52f0821c37d8b4cf5755107d7024..da64d97d7c9ee6a75c3a09644c018bd50a09b534 100644 (file)
@@ -50,7 +50,6 @@ class MagicFolder(service.MultiService):
 
         service.MultiService.__init__(self)
 
-        print "MagicFolder __init__"
         db = backupdb.get_backupdb(dbfile, create_version=(backupdb.SCHEMA_v3, 3))
         if db is None:
             return Failure(Exception('ERROR: Unable to load magic folder db.'))
@@ -68,7 +67,7 @@ class MagicFolder(service.MultiService):
         # TODO: why is this being called more than once?
         if self.running:
             return defer.succeed(None)
-        print "%r.startService" % (self,)
+        #print "%r.startService" % (self,)
         service.MultiService.startService(self)
         return self.uploader.start_monitoring()
 
@@ -83,7 +82,7 @@ class MagicFolder(service.MultiService):
         return d
 
     def finish(self):
-        print "finish"
+        #print "finish"
         d = self.uploader.stop()
         d2 = self.downloader.stop()
         d.addCallback(lambda ign: d2)
@@ -124,7 +123,7 @@ class QueueMixin(HookMixin):
     def _log(self, msg):
         s = "Magic Folder %s: %s" % (self._name, msg)
         self._client.log(s)
-        print s
+        #print s
         #open("events", "ab+").write(msg)
 
     def _append_to_deque(self, path):
@@ -155,7 +154,6 @@ class Uploader(QueueMixin):
     def __init__(self, client, local_path_u, db, upload_dircap, pending_delay):
         QueueMixin.__init__(self, client, local_path_u, db, 'uploader')
 
-        print "Magic-Folder: Uploader: __init__"
         self.is_ready = False
 
         # TODO: allow a path rather than a cap URI.
@@ -187,7 +185,7 @@ class Uploader(QueueMixin):
                              recursive=True)
 
     def start_monitoring(self):
-        print "start_monitoring"
+        self._log("start_monitoring")
         d = defer.succeed(None)
         d.addCallback(lambda ign: self._notifier.startReading())
         d.addCallback(lambda ign: self._count('dirs_monitored'))
@@ -195,6 +193,7 @@ class Uploader(QueueMixin):
         return d
 
     def stop(self):
+        self._log("stop")
         self._notifier.stopReading()
         self._count('dirs_monitored', -1)
         if hasattr(self._notifier, 'wait_until_stopped'):
@@ -205,7 +204,7 @@ class Uploader(QueueMixin):
         return d
 
     def start_scanning(self):
-        print "start_scanning self._db = %r" % (self._db,)
+        self._log("start_scanning")
         self.is_ready = True
         all_files = self._db.get_all_files()
         d = self._scan(self._local_path_u)
@@ -213,6 +212,7 @@ class Uploader(QueueMixin):
         return d
 
     def _scan(self, local_path_u):  # XXX should this take a FilePath?
+        self._log("scan %r" % (local_path_u))
         if not os.path.isdir(local_path_u):
             raise AssertionError("Programmer error: _scan() must be passed a directory path.")
         quoted_path = quote_local_unicode_path(local_path_u)
@@ -394,7 +394,6 @@ class Downloader(QueueMixin):
     def __init__(self, client, local_path_u, db, collective_dircap):
         QueueMixin.__init__(self, client, local_path_u, db, 'downloader')
 
-        print "Magic-Folder: Downloader: __init__"
         # TODO: allow a path rather than a cap URI.
         self._collective_dirnode = self._client.create_node_from_uri(collective_dircap)
 
index 1a098d039e355aa9ad01c0489f324a26835082ce..bdb23160105a900f657d42bddb4a8991e1e75f93 100644 (file)
@@ -93,7 +93,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
         return d
 
     def cleanup(self, res):
-        print "cleanup", res
+        #print "cleanup", res
         d = defer.succeed(None)
         if self.magicfolder is not None:
             d.addCallback(lambda ign: self.magicfolder.finish())
index debc94ceb0f9b9964c3120a6a6ac7999096d1f76..afb76d2511cf74f807b9c27bd245b4c22b81cba6 100644 (file)
@@ -44,13 +44,13 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
         return bdb
 
     def _restart_client(self, ign):
-        print "_restart_client"
+        #print "_restart_client"
         d = self.restart_client()
         d.addCallback(self._wait_until_started)
         return d
 
     def _wait_until_started(self, ign):
-        print "_wait_until_started"
+        #print "_wait_until_started"
         self.magicfolder = self.get_client().getServiceNamed('magic-folder')
         return self.magicfolder.ready()
 
@@ -202,23 +202,14 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
             self.notify(to_filepath(test_file), self.inotify.IN_CLOSE_WRITE)
             return d2
         d.addCallback(lambda ign: create_test_file(u"what1"))
-        def fu(res):
-            print "upload complete"
-            return res
-        d.addBoth(fu)
         d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_succeeded'), 1))
         d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_queued'), 0))
         d.addCallback(self.cleanup)
+
         d.addCallback(self._restart_client)
         d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_succeeded'), 1))
         d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_queued'), 0))
         d.addCallback(lambda ign: create_test_file(u"what2"))
-
-        def fu2(res):
-            print "2nd upload complete"
-            return res
-        d.addBoth(fu2)
-
         d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_succeeded'), 2))
         d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_queued'), 0))
         d.addBoth(self.cleanup)
@@ -312,12 +303,12 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
             # XXX are these used?
             (self.alice_collective_dircap, self.alice_upload_dircap, self.alice_magicfolder,
              self.bob_collective_dircap,   self.bob_upload_dircap,   self.bob_magicfolder) = result
-            print "Alice magicfolderdb is at %r" % (self.alice_magicfolder._client.basedir)
-            print "Bob   magicfolderdb is at %r" % (self.bob_magicfolder._client.basedir)
+            #print "Alice magicfolderdb is at %r" % (self.alice_magicfolder._client.basedir)
+            #print "Bob   magicfolderdb is at %r" % (self.bob_magicfolder._client.basedir)
         d.addCallback(get_results)
 
         def Alice_write_a_file(result):
-            print "Alice writes a file\n"
+            #print "Alice writes a file\n"
             self.file_path = abspath_expanduser_unicode(u"file1", base=self.alice_magicfolder.uploader._local_path_u)
             fileutil.write(self.file_path, "meow, meow meow. meow? meow meow! meow.")
             self.magicfolder = self.alice_magicfolder
@@ -326,7 +317,7 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
         d.addCallback(Alice_write_a_file)
 
         def Alice_wait_for_upload(result):
-            print "Alice waits for an upload\n"
+            #print "Alice waits for an upload\n"
             d2 = self.alice_magicfolder.uploader.set_hook('processed')
             return d2
         d.addCallback(Alice_wait_for_upload)
@@ -339,7 +330,7 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
         d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.directories_created', client=self.alice_magicfolder._client), 0))
 
         def Bob_wait_for_download(result):
-            print "Bob waits for a download\n"
+            #print "Bob waits for a download\n"
             d2 = self.bob_magicfolder.downloader.set_hook('processed')
             return d2
         d.addCallback(Bob_wait_for_download)
@@ -350,7 +341,7 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
 
         # test deletion of file behavior
         def Alice_delete_file(result):
-            print "Alice deletes the file!\n"
+            #print "Alice deletes the file!\n"
             os.unlink(self.file_path)
             self.notify(to_filepath(self.file_path), self.inotify.IN_DELETE)
 
@@ -368,7 +359,7 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
 
 
         def Alice_rewrite_file(result):
-            print "Alice rewrites file\n"
+            #print "Alice rewrites file\n"
             self.file_path = abspath_expanduser_unicode(u"file1", base=self.alice_magicfolder.uploader._local_path_u)
             fileutil.write(self.file_path, "Alice suddenly sees the white rabbit running into the forest.")
             self.magicfolder = self.alice_magicfolder
index 08b7d6797be6bb9704764e9ef3d5e442437b0f3d..ac6fa8a0d06be8b6d31968c2a6da44ba3a073383 100644 (file)
@@ -113,11 +113,12 @@ class HookMixin:
         'res' is returned so that the current result or failure will be passed
         through.
         """
-        print "calling hook %r" % (name,)
         hook = self._hooks[name]
         if hook is None:
             return defer.succeed(None)
+
         (d, ignore_count) = hook
+        log.msg("call_hook", name=name, ignore_count=ignore_count, level=log.NOISY)
         if ignore_count > 0:
             self._hooks[name] = (d, ignore_count - 1)
         else: