diff --git a/src/mceditlib/revisionhistory.py b/src/mceditlib/revisionhistory.py index da2860a..3c1666b 100644 --- a/src/mceditlib/revisionhistory.py +++ b/src/mceditlib/revisionhistory.py @@ -10,6 +10,7 @@ import shutil from mceditlib.anvil.worldfolder import AnvilWorldFolder from mceditlib.exceptions import ChunkNotPresent +from mceditlib.util.progress import rescaleProgress, enumProgress log = logging.getLogger(__name__) # @@ -360,46 +361,11 @@ class RevisionHistory(object): currentNode.invalid = True shutil.rmtree(currentNode.worldFolder.filename, ignore_errors=True) + def copyToFolder(destFolder, sourceNode, presaveNode=None): for status in copyToFolderIter(destFolder, sourceNode, presaveNode): pass -def rescaleProgress(iterable, start, end): - """ - Given an iterable that yields (current, maximum, status) tuples, rescales current and maximum - to fit within the range [start, end]. `current` is assumed to start at zero. - - :param iterable: - :param start: - :param end: - :return: - """ - d = end - start - - for current, maximum, status in iterable: - yield start + current * d / maximum, end, status - - -def enumProgress(collection, start, end=None): - """ - Iterate through a collection, yielding (progress, value) tuples. `progress` is the value - between `start` and `end` proportional to the progress through the collection. - - :param collection: - :param progress: - :return: - """ - if end is None: - end = start - start = 0 - - if len(collection) == 0: - return - - progFraction = (end - start) / len(collection) - for i, value in enumerate(collection): - yield start + i * progFraction, value - def copyToFolderIter(destFolder, sourceNode, presaveNode=None): # Progress counts: diff --git a/src/mceditlib/util/progress.py b/src/mceditlib/util/progress.py new file mode 100644 index 0000000..23cb0b6 --- /dev/null +++ b/src/mceditlib/util/progress.py @@ -0,0 +1,44 @@ +""" + progress +""" +from __future__ import absolute_import, division, print_function, unicode_literals +import logging + +log = logging.getLogger(__name__) + + +def rescaleProgress(iterable, start, end): + """ + Given an iterable that yields (current, maximum, status) tuples, rescales current and maximum + to fit within the range [start, end]. `current` is assumed to start at zero. + + :param iterable: + :param start: + :param end: + :return: + """ + d = end - start + + for current, maximum, status in iterable: + yield start + current * d / maximum, end, status + + +def enumProgress(collection, start, end=None): + """ + Iterate through a collection, yielding (progress, value) tuples. `progress` is the value + between `start` and `end` proportional to the progress through the collection. + + :param collection: + :param progress: + :return: + """ + if end is None: + end = start + start = 0 + + if len(collection) == 0: + return + + progFraction = (end - start) / len(collection) + for i, value in enumerate(collection): + yield start + i * progFraction, value \ No newline at end of file