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

View File

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