Ditch older 'progressbar' for newer 'progress' package
This commit is contained in:
parent
c10b5fb50f
commit
e633899998
|
@ -45,7 +45,7 @@ from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
||||||
from rattail import __version__
|
from rattail import __version__
|
||||||
from rattail.core import Object
|
from rattail.core import Object
|
||||||
from rattail.util import load_entry_points, load_object
|
from rattail.util import load_entry_points, load_object
|
||||||
from rattail.console import Progress
|
from rattail.progress import ConsoleProgress
|
||||||
from rattail.config import make_config, parse_list
|
from rattail.config import make_config, parse_list
|
||||||
from rattail.util import progress_loop
|
from rattail.util import progress_loop
|
||||||
from rattail.time import make_utc
|
from rattail.time import make_utc
|
||||||
|
@ -266,7 +266,7 @@ Commands:\n""".format(self))
|
||||||
# And finally, do something of real value...
|
# And finally, do something of real value...
|
||||||
cmd = self.subcommands[cmd](self, self.config)
|
cmd = self.subcommands[cmd](self, self.config)
|
||||||
cmd.show_progress = args.progress
|
cmd.show_progress = args.progress
|
||||||
cmd.progress = Progress if args.progress else None
|
cmd.progress = ConsoleProgress if args.progress else None
|
||||||
# TODO: make this default to something from config?
|
# TODO: make this default to something from config?
|
||||||
cmd.runas_username = args.runas or None
|
cmd.runas_username = args.runas or None
|
||||||
log.debug("running '%s %s' with args: %s", self.name, cmd.name, args.argv)
|
log.debug("running '%s %s' with args: %s", self.name, cmd.name, args.argv)
|
||||||
|
@ -286,7 +286,7 @@ class Subcommand(object):
|
||||||
self.stdout = getattr(parent, 'stdout', sys.stdout)
|
self.stdout = getattr(parent, 'stdout', sys.stdout)
|
||||||
self.stderr = getattr(parent, 'stderr', sys.stderr)
|
self.stderr = getattr(parent, 'stderr', sys.stderr)
|
||||||
self.show_progress = show_progress
|
self.show_progress = show_progress
|
||||||
self.progress = Progress if show_progress else None
|
self.progress = ConsoleProgress if show_progress else None
|
||||||
self.parser = argparse.ArgumentParser(
|
self.parser = argparse.ArgumentParser(
|
||||||
prog='{0} {1}'.format(getattr(self.parent, 'name', 'UNDEFINED'), self.name),
|
prog='{0} {1}'.format(getattr(self.parent, 'name', 'UNDEFINED'), self.name),
|
||||||
description=self.description)
|
description=self.description)
|
||||||
|
@ -636,7 +636,7 @@ class Dump(Subcommand):
|
||||||
|
|
||||||
progress = None
|
progress = None
|
||||||
if self.show_progress: # pragma no cover
|
if self.show_progress: # pragma no cover
|
||||||
progress = Progress
|
progress = ConsoleProgress
|
||||||
|
|
||||||
if args.output:
|
if args.output:
|
||||||
output = open(args.output, 'wb')
|
output = open(args.output, 'wb')
|
||||||
|
@ -791,7 +791,7 @@ class LoadHostDataCommand(Subcommand):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
proc = load.LoadProcessor(self.config)
|
proc = load.LoadProcessor(self.config)
|
||||||
proc.load_all_data(engines['host'], Progress)
|
proc.load_all_data(engines['host'], ConsoleProgress)
|
||||||
|
|
||||||
|
|
||||||
class MakeAppDir(Subcommand):
|
class MakeAppDir(Subcommand):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8; -*-
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2017 Lance Edgar
|
# Copyright © 2010-2018 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -28,23 +28,23 @@ from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import progressbar
|
from progress.bar import Bar
|
||||||
|
|
||||||
|
|
||||||
class Progress(object):
|
class ConsoleProgress(object):
|
||||||
"""
|
"""
|
||||||
Provides a console-based progress bar.
|
Provides a console-based progress bar.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, message, maximum, stdout=None):
|
def __init__(self, message, maximum, stdout=None):
|
||||||
self.stdout = stdout or sys.stderr
|
self.stdout = stdout or sys.stderr
|
||||||
self.stdout.write("\n{}...({:,d} total)\n".format(message, maximum))
|
self.stdout.write("\n{}...\n".format(message))
|
||||||
widgets = [progressbar.Percentage(), ' ', progressbar.Bar(), ' ', progressbar.ETA()]
|
self.bar = Bar(None, max=maximum, width=70,
|
||||||
self.progress = progressbar.ProgressBar(maxval=maximum, widgets=widgets).start()
|
suffix='%(index)d/%(max)d %(percent)d%% ETA %(eta)ds')
|
||||||
|
|
||||||
def update(self, value):
|
def update(self, value):
|
||||||
self.progress.update(value)
|
self.bar.next()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
self.stdout.write("\n")
|
self.bar.finish()
|
Loading…
Reference in a new issue