Skip to content
Permalink
Browse files

Add a quiet flag (ref #376)

  • Loading branch information
saimn committed Oct 4, 2019
1 parent 1b75bd8 commit 745761ff9ad4fbef5810a49866a2796a8215a008
Showing with 23 additions and 10 deletions.
  1. +18 −7 sigal/__init__.py
  2. +5 −3 sigal/gallery.py
@@ -87,23 +87,34 @@ def init(path):
help="Force the reprocessing of existing images")
@option('-v', '--verbose', is_flag=True, help="Show all messages")
@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,
help="Configuration file")
@option('-t', '--theme', help="Specify a theme directory, or a theme name for "
"the themes included with Sigal")
@option('--title', help="Title of the gallery (overrides the title setting.")
@option('-n', '--ncpu', help="Number of cpu to use (default: all)")
def build(source, destination, debug, verbose, force, config, theme, title,
ncpu):
def build(source, destination, debug, verbose, quiet, force, config, theme,
title, ncpu):
"""Run sigal to process a directory.
If provided, 'source', 'destination' and 'theme' will override the
corresponding values from the settings file.
"""
level = ((debug and logging.DEBUG) or (verbose and logging.INFO) or
logging.WARNING)
if sum([debug, verbose, quiet]) > 1:
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)
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'])
init_plugins(settings)

gal = Gallery(settings, ncpu=ncpu)
gal = Gallery(settings, ncpu=ncpu, quiet=quiet)
gal.build(force=force)

# copy extra files
@@ -164,7 +175,7 @@ def format_stats(_type):
opt = ' ({})'.format(', '.join(opt)) if opt else ''
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'),
time.time() - start_time))

@@ -528,7 +528,7 @@ def zip(self):

class Gallery(object):

def __init__(self, settings, ncpu=None):
def __init__(self, settings, ncpu=None, quiet=False):
self.settings = settings
self.logger = logging.getLogger(__name__)
self.stats = defaultdict(int)
@@ -543,7 +543,8 @@ def __init__(self, settings, ncpu=None):
ignore_files = settings['ignore_files']

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()))
self.progressbar_target = None if show_progress else Devnull()

@@ -585,7 +586,8 @@ def __init__(self, settings, ncpu=None):
album.create_output_directories()
albums[relpath] = album

print("\rCollecting albums, done.")
if show_progress:
print("\rCollecting albums, done.")

with progressbar(albums.values(), label="%16s" % "Sorting albums",
file=self.progressbar_target) as progress_albums:

0 comments on commit 745761f

Please sign in to comment.
You can’t perform that action at this time.