From: Daira Hopwood Date: Tue, 15 Sep 2015 15:43:41 +0000 (+0100) Subject: Remove or comment out print statements and improve logging. X-Git-Url: https://git.rkrishnan.org/listings/module-simplejson.scanner.html?a=commitdiff_plain;h=f47a5cc4aefee1fb02add62209cbbb8280c43aff;p=tahoe-lafs%2Ftahoe-lafs.git Remove or comment out print statements and improve logging. Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/backupdb.py b/src/allmydata/backupdb.py index e6f723ae..a51356ca 100644 --- a/src/allmydata/backupdb.py +++ b/src/allmydata/backupdb.py @@ -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] diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index 20bcf50a..da64d97d 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -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) diff --git a/src/allmydata/test/test_cli_magic_folder.py b/src/allmydata/test/test_cli_magic_folder.py index 1a098d03..bdb23160 100644 --- a/src/allmydata/test/test_cli_magic_folder.py +++ b/src/allmydata/test/test_cli_magic_folder.py @@ -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()) diff --git a/src/allmydata/test/test_magic_folder.py b/src/allmydata/test/test_magic_folder.py index debc94ce..afb76d25 100644 --- a/src/allmydata/test/test_magic_folder.py +++ b/src/allmydata/test/test_magic_folder.py @@ -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 diff --git a/src/allmydata/util/deferredutil.py b/src/allmydata/util/deferredutil.py index 08b7d679..ac6fa8a0 100644 --- a/src/allmydata/util/deferredutil.py +++ b/src/allmydata/util/deferredutil.py @@ -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: