mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
add stash
This commit is contained in:
parent
edb8fd5e71
commit
5016797a7b
3 changed files with 39 additions and 59 deletions
|
|
@ -47,7 +47,6 @@ class Pelican(object):
|
|||
|
||||
self.path = settings['PATH']
|
||||
self.theme = settings['THEME']
|
||||
self.base_theme = settings['BASE_THEME']
|
||||
self.output_path = settings['OUTPUT_PATH']
|
||||
self.ignore_files = settings['IGNORE_FILES']
|
||||
self.delete_outputdir = settings['DELETE_OUTPUT_DIRECTORY']
|
||||
|
|
@ -153,7 +152,6 @@ class Pelican(object):
|
|||
settings=self.settings,
|
||||
path=self.path,
|
||||
theme=self.theme,
|
||||
base_theme=self.base_theme,
|
||||
output_path=self.output_path,
|
||||
) for cls in self.get_generator_classes()
|
||||
]
|
||||
|
|
@ -230,11 +228,6 @@ def parse_arguments():
|
|||
'specified, it will use the default one included with '
|
||||
'pelican.')
|
||||
|
||||
parser.add_argument('-b', '--base-theme-path', dest='base_theme',
|
||||
help='Path where to find the base theme templates. If not '
|
||||
'specified, it will use the default one included with '
|
||||
'pelican.')
|
||||
|
||||
parser.add_argument('-o', '--output', dest='output',
|
||||
help='Where to output the generated files. If not '
|
||||
'specified, a directory will be created, named '
|
||||
|
|
@ -290,9 +283,6 @@ def get_config(args):
|
|||
if args.theme:
|
||||
abstheme = os.path.abspath(os.path.expanduser(args.theme))
|
||||
config['THEME'] = abstheme if os.path.exists(abstheme) else args.theme
|
||||
if args.base_theme:
|
||||
absbasetheme = os.path.abspath(os.path.expanduser(args.base_theme))
|
||||
config['BASE_THEME'] = absbasetheme if os.path.exists(absbasetheme) else args.base_theme
|
||||
if args.delete_outputdir is not None:
|
||||
config['DELETE_OUTPUT_DIRECTORY'] = args.delete_outputdir
|
||||
if args.ignore_cache:
|
||||
|
|
@ -307,7 +297,7 @@ def get_config(args):
|
|||
if not six.PY3:
|
||||
enc = locale.getpreferredencoding()
|
||||
for key in config:
|
||||
if key in ('PATH', 'OUTPUT_PATH', 'THEME', 'BASE_THEME'):
|
||||
if key in ('PATH', 'OUTPUT_PATH', 'THEME'):
|
||||
config[key] = config[key].decode(enc)
|
||||
return config
|
||||
|
||||
|
|
@ -341,9 +331,6 @@ def main():
|
|||
'theme': folder_watcher(pelican.theme,
|
||||
[''],
|
||||
pelican.ignore_files),
|
||||
'base_theme': folder_watcher(pelican.base_theme,
|
||||
[''],
|
||||
pelican.ignore_files),
|
||||
'settings': file_watcher(args.settings)}
|
||||
|
||||
for static_path in settings.get("STATIC_PATHS", []):
|
||||
|
|
@ -351,7 +338,7 @@ def main():
|
|||
|
||||
try:
|
||||
if args.autoreload:
|
||||
print(' --- AutoReload Mode: Monitoring `content`, `theme`, `base_theme` and'
|
||||
print(' --- AutoReload Mode: Monitoring `content`, `theme`, and'
|
||||
' `settings` for changes. ---')
|
||||
|
||||
def _ignore_cache(pelican_obj):
|
||||
|
|
@ -361,7 +348,7 @@ def main():
|
|||
while True:
|
||||
try:
|
||||
# Check source dir for changed files ending with the given
|
||||
# extension in the settings. In the theme and base_theme dir there is no such
|
||||
# extension in the settings. In the theme dir there is no such
|
||||
# restriction; all files are recursively checked if they
|
||||
# have changed, no matter what extension the filenames
|
||||
# have.
|
||||
|
|
@ -384,11 +371,6 @@ def main():
|
|||
if modified['theme'] is None:
|
||||
logger.warning('Empty theme folder. Using `basic` '
|
||||
'theme.')
|
||||
|
||||
if modified['base_theme'] is None:
|
||||
logger.warning('Empty base_theme folder. Using `simple` '
|
||||
'theme.')
|
||||
|
||||
pelican.run()
|
||||
# restore original caching policy
|
||||
pelican.settings['LOAD_CONTENT_CACHE'] = original_load_cache
|
||||
|
|
@ -414,10 +396,6 @@ def main():
|
|||
if next(watchers['theme']) is None:
|
||||
logger.warning('Empty theme folder. Using `basic` theme.')
|
||||
|
||||
if next(watchers['base_theme']) is None:
|
||||
logger.warning('Empty base_theme folder. Using `simple` '
|
||||
'theme.')
|
||||
|
||||
pelican.run()
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -30,14 +30,12 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
class Generator(object):
|
||||
"""Baseclass generator"""
|
||||
|
||||
def __init__(self, context, settings, path, theme, base_theme, output_path,
|
||||
def __init__(self, context, settings, path, theme, output_path,
|
||||
readers_cache_name='', **kwargs):
|
||||
self.context = context
|
||||
self.settings = settings
|
||||
self.path = path
|
||||
self.theme = theme
|
||||
self.base_theme = base_theme
|
||||
self.output_path = output_path
|
||||
|
||||
for arg, value in kwargs.items():
|
||||
|
|
@ -52,24 +50,26 @@ class Generator(object):
|
|||
os.path.join(self.theme, 'templates')))
|
||||
self._templates_path += self.settings['EXTRA_TEMPLATES_PATHS']
|
||||
|
||||
theme_path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
theme_path = os.path.dirname(os.path.abspath(__file__))
|
||||
simple_loader = FileSystemLoader(os.path.join(theme_path,
|
||||
"themes", "simple", "templates"))
|
||||
|
||||
base_theme = self.settings['BASE_THEME']
|
||||
themes = {}
|
||||
for theme in settings['THEMES']:
|
||||
themes['!' + os.path.basename(theme)] = FileSystemLoader(os.path.join(theme, "templates"))
|
||||
|
||||
loader=ChoiceLoader([
|
||||
FileSystemLoader(self._templates_path),
|
||||
simple_loader, #implicit inheritance
|
||||
PrefixLoader(themes), # explicit one
|
||||
])
|
||||
|
||||
base_loader = FileSystemLoader(os.path.join(theme_path,
|
||||
"themes", base_theme, "templates"))
|
||||
self.env = Environment(
|
||||
trim_blocks=True,
|
||||
lstrip_blocks=True,
|
||||
loader=ChoiceLoader([
|
||||
FileSystemLoader(self._templates_path),
|
||||
base_loader, # implicit inheritance
|
||||
PrefixLoader({'!simple': simple_loader}), # explicit one
|
||||
PrefixLoader({'!base': base_loader}) # explicit one
|
||||
]),
|
||||
loader=loader,
|
||||
extensions=self.settings['JINJA_EXTENSIONS'],
|
||||
)
|
||||
|
||||
|
|
@ -681,9 +681,6 @@ class StaticGenerator(Generator):
|
|||
|
||||
def generate_output(self, writer):
|
||||
|
||||
self._copy_paths(self.settings['BASE_THEME_STATIC_PATHS'], self.base_theme,
|
||||
self.settings['THEME_STATIC_DIR'], self.output_path,
|
||||
os.curdir)
|
||||
self._copy_paths(self.settings['THEME_STATIC_PATHS'], self.theme,
|
||||
self.settings['THEME_STATIC_DIR'], self.output_path,
|
||||
os.curdir)
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
DEFAULT_THEME = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
||||
'themes', 'notmyidea')
|
||||
DEFAULT_BASE_THEME = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
||||
'themes', 'simple')
|
||||
|
||||
DEFAULT_CONFIG = {
|
||||
'PATH': os.curdir,
|
||||
|
|
@ -36,14 +34,13 @@ DEFAULT_CONFIG = {
|
|||
'ARTICLE_EXCLUDES': ('pages',),
|
||||
'PAGE_DIR': 'pages',
|
||||
'PAGE_EXCLUDES': (),
|
||||
'BASE_THEME': DEFAULT_BASE_THEME,
|
||||
'THEME': DEFAULT_THEME,
|
||||
'THEMES':['simple',],
|
||||
'OUTPUT_PATH': 'output',
|
||||
'READERS': {},
|
||||
'STATIC_PATHS': ['images', ],
|
||||
'THEME_STATIC_DIR': 'theme',
|
||||
'THEME_STATIC_PATHS': ['static', ],
|
||||
'BASE_THEME_STATIC_PATHS': ['static', ],
|
||||
'FEED_ALL_ATOM': os.path.join('feeds', 'all.atom.xml'),
|
||||
'CATEGORY_FEED_ATOM': os.path.join('feeds', '%s.atom.xml'),
|
||||
'AUTHOR_FEED_ATOM': os.path.join('feeds', '%s.atom.xml'),
|
||||
|
|
@ -144,13 +141,12 @@ def read_settings(path=None, override=None):
|
|||
if path:
|
||||
local_settings = get_settings_from_file(path)
|
||||
# Make the paths relative to the settings file
|
||||
|
||||
for p in ['PATH', 'OUTPUT_PATH', 'THEME', 'BASE_THEME']:
|
||||
for p in ['PATH', 'OUTPUT_PATH', 'THEME']:
|
||||
if p in local_settings and local_settings[p] is not None \
|
||||
and not isabs(local_settings[p]):
|
||||
absp = os.path.abspath(os.path.normpath(os.path.join(
|
||||
os.path.dirname(path), local_settings[p])))
|
||||
if p not in ('THEME', 'BASE_THEME') or os.path.exists(absp):
|
||||
if p not in ('THEME') or os.path.exists(absp):
|
||||
local_settings[p] = absp
|
||||
|
||||
if isinstance(local_settings['PLUGIN_PATH'], six.string_types):
|
||||
|
|
@ -160,6 +156,14 @@ def read_settings(path=None, override=None):
|
|||
if 'PLUGIN_PATH' in local_settings and local_settings['PLUGIN_PATH'] is not None:
|
||||
local_settings['PLUGIN_PATH'] = [os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(path), pluginpath)))
|
||||
if not isabs(pluginpath) else pluginpath for pluginpath in local_settings['PLUGIN_PATH']]
|
||||
|
||||
if 'THEMES' in local_settings and local_settings[p] is not None:
|
||||
for p in local_settings['THEMES']:
|
||||
if p is not isabs(p):
|
||||
absp = os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(path), p)))
|
||||
if os.path.exists(absp):
|
||||
local_settings['THEMES'][p] = absp
|
||||
|
||||
else:
|
||||
local_settings = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
||||
|
|
@ -219,17 +223,18 @@ def configure_settings(settings):
|
|||
raise Exception("Could not find the theme %s"
|
||||
% settings['THEME'])
|
||||
|
||||
# lookup the base theme in "pelican/themes" if the given one doesn't exist
|
||||
if not os.path.isdir(settings['BASE_THEME']):
|
||||
theme_path = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
'themes',
|
||||
settings['BASE_THEME'])
|
||||
if os.path.exists(theme_path):
|
||||
settings['BASE_THEME'] = theme_path
|
||||
else:
|
||||
raise Exception("Could not find the base theme %s"
|
||||
% settings['BASE_THEME'])
|
||||
for theme in settings['THEMES']:
|
||||
if not os.path.isdir(theme):
|
||||
theme_path = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
'themes',
|
||||
theme)
|
||||
if os.path.exists(theme_path):
|
||||
index = settings['THEMES'].index(theme)
|
||||
settings['THEMES'][index] = theme_path
|
||||
else:
|
||||
raise Exception("Could not find the theme %s"
|
||||
% theme)
|
||||
|
||||
# make paths selected for writing absolute if necessary
|
||||
settings['WRITE_SELECTED'] = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue