Browse Source

Add a quiet flag (ref #376)

pull/377/head
Simon Conseil 7 years ago
parent
commit
745761ff9a
  1. 25
      sigal/__init__.py
  2. 8
      sigal/gallery.py

25
sigal/__init__.py

@ -87,23 +87,34 @@ def init(path):
help="Force the reprocessing of existing images") help="Force the reprocessing of existing images")
@option('-v', '--verbose', is_flag=True, help="Show all messages") @option('-v', '--verbose', is_flag=True, help="Show all messages")
@option('-d', '--debug', is_flag=True, @option('-d', '--debug', is_flag=True,
help="Show all message, including debug messages") help="Show all messages, including debug messages")
@option('-q', '--quiet', is_flag=True, help="Show only error messages")
@option('-c', '--config', default=_DEFAULT_CONFIG_FILE, show_default=True, @option('-c', '--config', default=_DEFAULT_CONFIG_FILE, show_default=True,
help="Configuration file") help="Configuration file")
@option('-t', '--theme', help="Specify a theme directory, or a theme name for " @option('-t', '--theme', help="Specify a theme directory, or a theme name for "
"the themes included with Sigal") "the themes included with Sigal")
@option('--title', help="Title of the gallery (overrides the title setting.") @option('--title', help="Title of the gallery (overrides the title setting.")
@option('-n', '--ncpu', help="Number of cpu to use (default: all)") @option('-n', '--ncpu', help="Number of cpu to use (default: all)")
def build(source, destination, debug, verbose, force, config, theme, title, def build(source, destination, debug, verbose, quiet, force, config, theme,
ncpu): title, ncpu):
"""Run sigal to process a directory. """Run sigal to process a directory.
If provided, 'source', 'destination' and 'theme' will override the If provided, 'source', 'destination' and 'theme' will override the
corresponding values from the settings file. corresponding values from the settings file.
""" """
level = ((debug and logging.DEBUG) or (verbose and logging.INFO) or if sum([debug, verbose, quiet]) > 1:
logging.WARNING) sys.exit('Only one option of debug, verbose and quiet should be used')
if debug:
level = logging.DEBUG
elif verbose:
level = logging.INFO
elif quiet:
level = logging.ERROR
else:
level = logging.WARNING
init_logging(__name__, level=level) init_logging(__name__, level=level)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -145,7 +156,7 @@ def build(source, destination, debug, verbose, force, config, theme, title,
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) gal = Gallery(settings, ncpu=ncpu, quiet=quiet)
gal.build(force=force) gal.build(force=force)
# copy extra files # copy extra files
@ -164,7 +175,7 @@ def build(source, destination, debug, verbose, force, config, theme, title,
opt = ' ({})'.format(', '.join(opt)) if opt else '' opt = ' ({})'.format(', '.join(opt)) if opt else ''
return '{} {}s{}'.format(stats[_type], _type, opt) return '{} {}s{}'.format(stats[_type], _type, opt)
print('Done.\nProcessed {} and {} in {:.2f} seconds.' print('Done, processed {} and {} in {:.2f} seconds.'
.format(format_stats('image'), format_stats('video'), .format(format_stats('image'), format_stats('video'),
time.time() - start_time)) time.time() - start_time))

8
sigal/gallery.py

@ -528,7 +528,7 @@ class Album:
class Gallery(object): class Gallery(object):
def __init__(self, settings, ncpu=None): def __init__(self, settings, ncpu=None, quiet=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)
@ -543,7 +543,8 @@ class Gallery(object):
ignore_files = settings['ignore_files'] ignore_files = settings['ignore_files']
progressChars = cycle(["/", "-", "\\", "|"]) progressChars = cycle(["/", "-", "\\", "|"])
show_progress = (self.logger.getEffectiveLevel() >= logging.WARNING and show_progress = (not quiet and
self.logger.getEffectiveLevel() >= logging.WARNING and
os.isatty(sys.stdout.fileno())) os.isatty(sys.stdout.fileno()))
self.progressbar_target = None if show_progress else Devnull() self.progressbar_target = None if show_progress else Devnull()
@ -585,7 +586,8 @@ class Gallery(object):
album.create_output_directories() album.create_output_directories()
albums[relpath] = album albums[relpath] = album
print("\rCollecting albums, done.") if show_progress:
print("\rCollecting albums, done.")
with progressbar(albums.values(), label="%16s" % "Sorting albums", with progressbar(albums.values(), label="%16s" % "Sorting albums",
file=self.progressbar_target) as progress_albums: file=self.progressbar_target) as progress_albums:

Loading…
Cancel
Save