From 39101c2ac7998f1f991ed865434e85a14579ca8f Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Fri, 2 May 2014 11:40:16 +0200 Subject: [PATCH] Disqus import uses Progressbar class as well --- isso/migrate.py | 15 ++++----------- isso/tests/test_migration.py | 2 ++ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/isso/migrate.py b/isso/migrate.py index b549238..2a985f1 100644 --- a/isso/migrate.py +++ b/isso/migrate.py @@ -93,7 +93,7 @@ class Disqus(object): tree = ElementTree.parse(self.xmlfile) res = defaultdict(list) - for post in tree.findall('%spost' % Disqus.ns): + for post in tree.findall(Disqus.ns + 'post'): item = { 'dsq:id': post.attrib.get(Disqus.internals + 'id'), @@ -111,15 +111,9 @@ class Disqus(object): res[post.find('%sthread' % Disqus.ns).attrib.get(Disqus.internals + 'id')].append(item) - num = len(tree.findall(Disqus.ns + 'thread')) - cols = int((os.popen('stty size', 'r').read() or "25 80").split()[1]) - + progress = Progress(len(tree.findall(Disqus.ns + 'thread'))) for i, thread in enumerate(tree.findall(Disqus.ns + 'thread')): - - if int(round((i+1)/num, 2) * 100) % 13 == 0: - sys.stdout.write("\r%s" % (" "*cols)) - sys.stdout.write("\r[%i%%] %s" % (((i+1)/num * 100), thread.find(Disqus.ns + 'id').text)) - sys.stdout.flush() + progress.update(i, thread.find(Disqus.ns + 'id').text) # skip (possibly?) duplicate, but empty thread elements if thread.find(Disqus.ns + 'id').text is None: @@ -133,8 +127,7 @@ class Disqus(object): # in case a comment has been deleted (and no further childs) self.db.comments._remove_stale() - sys.stdout.write("\r%s" % (" "*cols)) - sys.stdout.write("\r[100%] {0} threads, {1} comments\n".format( + progress.finish("{0} threads, {1} comments".format( len(self.threads), len(self.comments))) orphans = set(map(lambda e: e.attrib.get(Disqus.internals + "id"), tree.findall(Disqus.ns + "post"))) - self.comments diff --git a/isso/tests/test_migration.py b/isso/tests/test_migration.py index fd5a68c..29adbd5 100644 --- a/isso/tests/test_migration.py +++ b/isso/tests/test_migration.py @@ -24,6 +24,8 @@ class TestMigration(unittest.TestCase): db = SQLite3(xxx.name, Config.load(None)) Disqus(db, xml).migrate() + self.assertEqual(len(db.execute("SELECT id FROM comments").fetchall()), 2) + self.assertEqual(db.threads["/"]["title"], "Hello, World!") self.assertEqual(db.threads["/"]["id"], 1)