From f9437a7ec054b35bdd099b4ea11a9a3abd01b18c Mon Sep 17 00:00:00 2001 From: random-geek <35757396+random-geek@users.noreply.github.com> Date: Fri, 1 Feb 2019 21:33:21 -0800 Subject: [PATCH] Add destructor to Progress class --- lib/commands.py | 22 ---------------------- lib/helpers.py | 7 +++++++ 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/lib/commands.py b/lib/commands.py index 0eac345..cc69de1 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -46,8 +46,6 @@ def clone_blocks(cursor, args): "INSERT OR REPLACE INTO blocks (pos, data) VALUES (?, ?)", (newPos, data)) - progress.print_bar(len(list), len(list)) - # # deleteblocks command # @@ -62,8 +60,6 @@ def delete_blocks(cursor, args): progress.print_bar(i, len(list)) cursor.execute("DELETE FROM blocks WHERE pos = ?", (pos,)) - progress.print_bar(len(list), len(list)) - # # fillblocks command # @@ -90,8 +86,6 @@ def fill_blocks(cursor, args): data = parsedData.serialize() cursor.execute("UPDATE blocks SET data = ? WHERE pos = ?", (data, pos)) - progress.print_bar(len(list), len(list)) - # # overlayblocks command # @@ -111,8 +105,6 @@ def overlay_blocks(cursor, sCursor, args): "INSERT OR REPLACE INTO blocks (pos, data) VALUES (?, ?)", (pos, data)) - progress.print_bar(len(list), len(list)) - # # replacenodes command # @@ -181,8 +173,6 @@ def replace_nodes(cursor, args): cursor.execute("UPDATE blocks SET data = ? WHERE pos = ?", (data, pos)) - progress.print_bar(len(list), len(list)) - # # setparam2 command # @@ -219,8 +209,6 @@ def set_param2(cursor, args): data = parsedData.serialize() cursor.execute("UPDATE blocks SET data = ? WHERE pos = ?", (data, pos)) - progress.print_bar(len(list), len(list)) - # # deletemeta command # @@ -253,8 +241,6 @@ def delete_meta(cursor, args): data = parsedData.serialize() cursor.execute("UPDATE blocks SET data = ? WHERE pos = ?", (data, pos)) - progress.print_bar(len(list), len(list)) - # # setmetavar command # @@ -296,8 +282,6 @@ def set_meta_var(cursor, args): data = parsedData.serialize() cursor.execute("UPDATE blocks SET data = ? WHERE pos = ?", (data, pos)) - progress.print_bar(len(list), len(list)) - # # replaceininv command # @@ -350,8 +334,6 @@ def replace_in_inv(cursor, args): data = parsedData.serialize() cursor.execute("UPDATE blocks SET data = ? WHERE pos = ?", (data, pos)) - progress.print_bar(len(list), len(list)) - # # deletetimers # @@ -385,8 +367,6 @@ def delete_timers(cursor, args): data = parsedData.serialize() cursor.execute("UPDATE blocks SET data = ? WHERE pos = ?", (data, pos)) - progress.print_bar(len(list), len(list)) - # # deleteobjects # @@ -430,5 +410,3 @@ def delete_objects(cursor, args): parsedData.serialize_static_objects(objects) data = parsedData.serialize() cursor.execute("UPDATE blocks SET data = ? WHERE pos = ?", (data, pos)) - - progress.print_bar(len(list), len(list)) diff --git a/lib/helpers.py b/lib/helpers.py index d647c8e..cf00df6 100644 --- a/lib/helpers.py +++ b/lib/helpers.py @@ -6,10 +6,17 @@ class Progress: """Prints a progress bar with time elapsed.""" def __init__(self): + self.last_total = 0 self.start_time = time.time() + def __del__(self): + self.print_bar(self.last_total, self.last_total) + + def print_bar(self, completed, total): + self.last_total = total + if completed % 100 == 0 or completed == total: if total > 0: percent = round(completed / total * 100, 1)