Better handling of verbosity/progress

This commit is contained in:
Simon Conseil
2023-07-30 22:54:23 +02:00
parent 6997fe3290
commit 33ab4f53ea
2 changed files with 6 additions and 7 deletions

View File

@@ -134,6 +134,7 @@ def build(
if sum([debug, verbose, quiet]) > 1:
sys.exit("Only one option of debug, verbose and quiet should be used")
show_progress = False
if debug:
level = logging.DEBUG
elif verbose:
@@ -142,6 +143,7 @@ def build(
level = logging.ERROR
else:
level = logging.WARNING
show_progress = True
init_logging(__name__, level=level)
logger = logging.getLogger(__name__)
@@ -184,7 +186,7 @@ def build(
locale.setlocale(locale.LC_ALL, settings["locale"])
init_plugins(settings)
gal = Gallery(settings, ncpu=ncpu, quiet=quiet)
gal = Gallery(settings, ncpu=ncpu, show_progress=show_progress)
gal.build(force=force_album if len(force_album) else force)
# copy extra files

View File

@@ -701,7 +701,7 @@ class Album:
class Gallery:
def __init__(self, settings, ncpu=None, quiet=False):
def __init__(self, settings, ncpu=None, show_progress=False):
self.settings = settings
self.logger = logging.getLogger(__name__)
self.stats = defaultdict(int)
@@ -724,10 +724,7 @@ class Gallery:
except io.UnsupportedOperation:
isatty = False
show_progress = (
not quiet and self.logger.getEffectiveLevel() >= logging.WARNING and isatty
)
self.progressbar_target = None if show_progress else Devnull()
self.progressbar_target = None if show_progress and isatty else Devnull()
for path, dirs, files in os.walk(src_path, followlinks=True, topdown=False):
if show_progress:
@@ -910,7 +907,7 @@ class Gallery:
if album.albums:
if album.medias:
self.logger.warning(
"Album %s contains sub-albums and images. "
"Album '%s' contains sub-albums and images. "
"Please move images to their own sub-album. "
"Images in album %s will not be visible.",
album.title,