forked from github/pelican
Merge pull request #2422 from justinmayer/print-settings
Add CLI argument to print current settings
This commit is contained in:
commit
f2b429b7b7
2 changed files with 43 additions and 4 deletions
|
|
@ -21,6 +21,12 @@ Settings are configured in the form of a Python module (a file). There is an
|
|||
<https://github.com/getpelican/pelican/raw/master/samples/pelican.conf.py>`_
|
||||
available for reference.
|
||||
|
||||
To see a list of current settings in your environment, including both default
|
||||
and any customized values, run the following command (append one or more
|
||||
specific setting names as arguments to see values for those settings only)::
|
||||
|
||||
pelican --print-settings
|
||||
|
||||
All the setting identifiers must be set in all-caps, otherwise they will not be
|
||||
processed. Setting values that are numbers (5, 20, etc.), booleans (True,
|
||||
False, None, etc.), dictionaries, or tuples should *not* be enclosed in
|
||||
|
|
@ -28,10 +34,9 @@ quotation marks. All other values (i.e., strings) *must* be enclosed in
|
|||
quotation marks.
|
||||
|
||||
Unless otherwise specified, settings that refer to paths can be either absolute
|
||||
or relative to the configuration file.
|
||||
|
||||
The settings you define in the configuration file will be passed to the
|
||||
templates, which allows you to use your settings to add site-wide content.
|
||||
or relative to the configuration file. The settings you define in the
|
||||
configuration file will be passed to the templates, which allows you to use your
|
||||
settings to add site-wide content.
|
||||
|
||||
Here is a list of settings for Pelican:
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import locale
|
|||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import pprint
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
|
|
@ -269,6 +270,32 @@ class Pelican(object):
|
|||
return writer(self.output_path, settings=self.settings)
|
||||
|
||||
|
||||
class PrintSettings(argparse.Action):
|
||||
def __call__(self, parser, namespace, values, option_string):
|
||||
instance, settings = get_instance(namespace)
|
||||
|
||||
if values:
|
||||
# One or more arguments provided, so only print those settings
|
||||
for setting in values:
|
||||
if setting in settings:
|
||||
# Only add newline between setting name and value if dict
|
||||
if isinstance(settings[setting], dict):
|
||||
setting_format = '\n{}:\n{}'
|
||||
else:
|
||||
setting_format = '\n{}: {}'
|
||||
print(setting_format.format(
|
||||
setting,
|
||||
pprint.pformat(settings[setting])))
|
||||
else:
|
||||
print('\n{} is not a recognized setting.'.format(setting))
|
||||
break
|
||||
else:
|
||||
# No argument was given to --print-settings, so print all settings
|
||||
pprint.pprint(settings)
|
||||
|
||||
parser.exit()
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='A tool to generate a static blog, '
|
||||
|
|
@ -319,6 +346,12 @@ def parse_arguments():
|
|||
help='Relaunch pelican each time a modification occurs'
|
||||
' on the content files.')
|
||||
|
||||
parser.add_argument('--print-settings', dest='print_settings', nargs='*',
|
||||
action=PrintSettings, metavar='SETTING_NAME',
|
||||
help='Print current configuration settings and exit. '
|
||||
'Append one or more setting name arguments to see the '
|
||||
'values for specific settings only.')
|
||||
|
||||
parser.add_argument('--relative-urls', dest='relative_paths',
|
||||
action='store_true',
|
||||
help='Use relative urls in output, '
|
||||
|
|
@ -527,6 +560,7 @@ def main():
|
|||
|
||||
try:
|
||||
pelican, settings = get_instance(args)
|
||||
|
||||
readers = Readers(settings)
|
||||
reader_descs = sorted(set(['%s (%s)' %
|
||||
(type(r).__name__,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue