Merge branch 'Spindel-master'
update to make this Python3 friendly
This commit is contained in:
commit
6ebca5751c
2 changed files with 30 additions and 28 deletions
|
@ -4,7 +4,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>albums</h2>
|
<h2>albums</h2>
|
||||||
<ul>
|
<ul>
|
||||||
{% for aname,album in ALBUMS.iteritems() %}
|
{% for aname,album in ALBUMS.items() %}
|
||||||
<li>{{ aname }}<a href="{{ SITEURL }}/{{ SIGLICAN_DESTINATION }}/{{ album.url }}"><img src="{{ SITEURL }}/{{ SIGLICAN_DESTINATION }}/{{ album.thumbnail }}"></a>
|
<li>{{ aname }}<a href="{{ SITEURL }}/{{ SIGLICAN_DESTINATION }}/{{ album.url }}"><img src="{{ SITEURL }}/{{ SIGLICAN_DESTINATION }}/{{ album.thumbnail }}"></a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
56
siglican.py
56
siglican.py
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2014 - Scott Boone
|
# Copyright (c) 2014 - Scott Boone
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
# in the Software without restriction, including without limitation the rights
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# The above copyright notice and this permission notice shall be included in
|
# The above copyright notice and this permission notice shall be included in
|
||||||
# all copies or substantial portions of the Software.
|
# all copies or substantial portions of the Software.
|
||||||
#
|
#
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
@ -37,7 +37,7 @@ from .writer import Writer
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Default config from Sigal's settings module. These have been changed to
|
# Default config from Sigal's settings module. These have been changed to
|
||||||
# upper case because Pelican does not recognize lower case configuration names.
|
# upper case because Pelican does not recognize lower case configuration names.
|
||||||
# note: if a default is changed, please also update README.md
|
# note: if a default is changed, please also update README.md
|
||||||
_DEFAULT_SIGLICAN_SETTINGS = {
|
_DEFAULT_SIGLICAN_SETTINGS = {
|
||||||
|
@ -83,9 +83,9 @@ class SigalGalleryGenerator(Generator):
|
||||||
# reference: methods provided by Pelican Generator:
|
# reference: methods provided by Pelican Generator:
|
||||||
# def _update_context(self, items): adds more items to the context dict
|
# def _update_context(self, items): adds more items to the context dict
|
||||||
# def get_template(self, name): returns templates from theme based on theme
|
# def get_template(self, name): returns templates from theme based on theme
|
||||||
# def get_files(self, paths, exclude=[], extensions=None): paths to search,
|
# def get_files(self, paths, exclude=[], extensions=None): paths to search,
|
||||||
# exclude, allowed extensions
|
# exclude, allowed extensions
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize gallery dict and load in custom Sigal settings."""
|
"""Initialize gallery dict and load in custom Sigal settings."""
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class SigalGalleryGenerator(Generator):
|
||||||
# this needs to be first to establish pelican settings:
|
# this needs to be first to establish pelican settings:
|
||||||
super(SigalGalleryGenerator, self).__init__(*args, **kwargs)
|
super(SigalGalleryGenerator, self).__init__(*args, **kwargs)
|
||||||
# add default sigal settings to generator settings:
|
# add default sigal settings to generator settings:
|
||||||
for k in _DEFAULT_SIGLICAN_SETTINGS.keys()[:]:
|
for k in list(_DEFAULT_SIGLICAN_SETTINGS.keys()):
|
||||||
self.settings[k] = self.settings.get(k, _DEFAULT_SIGLICAN_SETTINGS[k])
|
self.settings[k] = self.settings.get(k, _DEFAULT_SIGLICAN_SETTINGS[k])
|
||||||
#logger.debug("sigal.pelican: setting %s: %s",k,self.settings[k])
|
#logger.debug("sigal.pelican: setting %s: %s",k,self.settings[k])
|
||||||
self._clean_settings()
|
self._clean_settings()
|
||||||
|
@ -103,18 +103,18 @@ class SigalGalleryGenerator(Generator):
|
||||||
|
|
||||||
def _clean_settings(self):
|
def _clean_settings(self):
|
||||||
"""Checks existence of directories and normalizes image size settings."""
|
"""Checks existence of directories and normalizes image size settings."""
|
||||||
|
|
||||||
# create absolute paths to source, theme and destination directories:
|
# create absolute paths to source, theme and destination directories:
|
||||||
init_source = self.settings['SIGLICAN_SOURCE']
|
init_source = self.settings['SIGLICAN_SOURCE']
|
||||||
self.settings['SIGLICAN_SOURCE'] = os.path.normpath(self.settings['PATH'] +
|
self.settings['SIGLICAN_SOURCE'] = os.path.normpath(self.settings['PATH'] +
|
||||||
"/../" + self.settings['SIGLICAN_SOURCE'] + '/images')
|
"/../" + self.settings['SIGLICAN_SOURCE'] + '/images')
|
||||||
self.settings['SIGLICAN_THEME'] = os.path.normpath(self.settings['PATH'] +
|
self.settings['SIGLICAN_THEME'] = os.path.normpath(self.settings['PATH'] +
|
||||||
"/../" + init_source + "/" + self.settings['SIGLICAN_THEME'])
|
"/../" + init_source + "/" + self.settings['SIGLICAN_THEME'])
|
||||||
self.settings['SIGLICAN_DESTINATION'] = os.path.normpath(
|
self.settings['SIGLICAN_DESTINATION'] = os.path.normpath(
|
||||||
self.settings['OUTPUT_PATH'] + "/" + self.settings['SIGLICAN_DESTINATION'])
|
self.settings['OUTPUT_PATH'] + "/" + self.settings['SIGLICAN_DESTINATION'])
|
||||||
|
|
||||||
enc = locale.getpreferredencoding() if PY2 else None
|
enc = locale.getpreferredencoding() if PY2 else None
|
||||||
|
|
||||||
# test for existence of source directories
|
# test for existence of source directories
|
||||||
pathkeys = ['SIGLICAN_SOURCE', 'SIGLICAN_THEME']
|
pathkeys = ['SIGLICAN_SOURCE', 'SIGLICAN_THEME']
|
||||||
for k in pathkeys:
|
for k in pathkeys:
|
||||||
|
@ -127,7 +127,7 @@ class SigalGalleryGenerator(Generator):
|
||||||
logger.error("siglican: missing source directory %s: %s",
|
logger.error("siglican: missing source directory %s: %s",
|
||||||
k,self.settings[k])
|
k,self.settings[k])
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# normalize sizes as e landscape
|
# normalize sizes as e landscape
|
||||||
for key in ('SIGLICAN_IMG_SIZE', 'SIGLICAN_THUMB_SIZE', 'SIGLICAN_VIDEO_SIZE'):
|
for key in ('SIGLICAN_IMG_SIZE', 'SIGLICAN_THUMB_SIZE', 'SIGLICAN_VIDEO_SIZE'):
|
||||||
w, h = self.settings[key]
|
w, h = self.settings[key]
|
||||||
|
@ -135,11 +135,11 @@ class SigalGalleryGenerator(Generator):
|
||||||
self.settings[key] = (h, w)
|
self.settings[key] = (h, w)
|
||||||
logger.warning("siglican: The %s setting should be specified "
|
logger.warning("siglican: The %s setting should be specified "
|
||||||
"with the largest value first.", key)
|
"with the largest value first.", key)
|
||||||
|
|
||||||
if not self.settings['SIGLICAN_IMG_PROCESSOR']:
|
if not self.settings['SIGLICAN_IMG_PROCESSOR']:
|
||||||
logger.info('No Processor, images will not be resized')
|
logger.info('No Processor, images will not be resized')
|
||||||
|
|
||||||
# based on Sigal's Gallery.__init__() method:
|
# based on Sigal's Gallery.__init__() method:
|
||||||
def generate_context(self):
|
def generate_context(self):
|
||||||
""""Update the global Pelican context that's shared between generators."""
|
""""Update the global Pelican context that's shared between generators."""
|
||||||
|
|
||||||
|
@ -167,14 +167,14 @@ class SigalGalleryGenerator(Generator):
|
||||||
logger.debug('siglican: Files before filtering: %r', files)
|
logger.debug('siglican: Files before filtering: %r', files)
|
||||||
files = [os.path.split(f)[1] for f in files_path]
|
files = [os.path.split(f)[1] for f in files_path]
|
||||||
logger.debug('siglican: Files after filtering: %r', files)
|
logger.debug('siglican: Files after filtering: %r', files)
|
||||||
|
|
||||||
# Remove sub-directories that have been ignored in a previous
|
# Remove sub-directories that have been ignored in a previous
|
||||||
# iteration (as topdown=False, sub-directories are processed before
|
# iteration (as topdown=False, sub-directories are processed before
|
||||||
# their parent
|
# their parent
|
||||||
for d in dirs[:]:
|
for d in dirs[:]:
|
||||||
path = os.path.join(relpath, d) if relpath != '.' else d
|
path = os.path.join(relpath, d) if relpath != '.' else d
|
||||||
if path not in self.albums.keys():
|
if path not in self.albums.keys():
|
||||||
dirs.remove(d)
|
dirs.remove(d)
|
||||||
album = Album(relpath, self.settings, dirs, files, self)
|
album = Album(relpath, self.settings, dirs, files, self)
|
||||||
|
|
||||||
if not album.medias and not album.albums:
|
if not album.medias and not album.albums:
|
||||||
|
@ -189,27 +189,27 @@ class SigalGalleryGenerator(Generator):
|
||||||
self.context['ALBUMS'] = self.albums # ** change to SIGLICAN_ALBUMS?
|
self.context['ALBUMS'] = self.albums # ** change to SIGLICAN_ALBUMS?
|
||||||
|
|
||||||
# update the jinja context with the default sigal settings:
|
# update the jinja context with the default sigal settings:
|
||||||
for k,v in _DEFAULT_SIGLICAN_SETTINGS.iteritems():
|
for k,v in _DEFAULT_SIGLICAN_SETTINGS.items():
|
||||||
if not k in self.context:
|
if not k in self.context:
|
||||||
self.context[k] = v
|
self.context[k] = v
|
||||||
|
|
||||||
def generate_output(self, writer):
|
def generate_output(self, writer):
|
||||||
""" Creates gallery destination directories, thumbnails, resized
|
""" Creates gallery destination directories, thumbnails, resized
|
||||||
images, and moves everything into the destination."""
|
images, and moves everything into the destination."""
|
||||||
|
|
||||||
# note: ignore the writer sent by Pelican because it's not certain
|
# note: ignore the writer sent by Pelican because it's not certain
|
||||||
# which Writer it will send. if another active plugin also implements
|
# which Writer it will send. if another active plugin also implements
|
||||||
# Writer, Pelican may send that instead of one of its core Writers.
|
# Writer, Pelican may send that instead of one of its core Writers.
|
||||||
# I logged a feature request here:
|
# I logged a feature request here:
|
||||||
# https://github.com/getpelican/pelican/issues/1459
|
# https://github.com/getpelican/pelican/issues/1459
|
||||||
|
|
||||||
# create destination directory
|
# create destination directory
|
||||||
if not os.path.isdir(self.settings['SIGLICAN_DESTINATION']):
|
if not os.path.isdir(self.settings['SIGLICAN_DESTINATION']):
|
||||||
os.makedirs(self.settings['SIGLICAN_DESTINATION'])
|
os.makedirs(self.settings['SIGLICAN_DESTINATION'])
|
||||||
|
|
||||||
# github7 ** improve exception catching
|
# github7 ** improve exception catching
|
||||||
# github8 ** re-integrate multiprocessing logic from Sigal
|
# github8 ** re-integrate multiprocessing logic from Sigal
|
||||||
|
|
||||||
# generate thumbnails, process images, and move them to the destination
|
# generate thumbnails, process images, and move them to the destination
|
||||||
if logger.getEffectiveLevel() > logging.INFO:
|
if logger.getEffectiveLevel() > logging.INFO:
|
||||||
print('siglican is processing media: ', end='')
|
print('siglican is processing media: ', end='')
|
||||||
|
@ -239,7 +239,7 @@ class SigalGalleryGenerator(Generator):
|
||||||
media.dst_path),self.settings)
|
media.dst_path),self.settings)
|
||||||
if logger.getEffectiveLevel() > logging.INFO:
|
if logger.getEffectiveLevel() > logging.INFO:
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
# generate the index.html files for the albums
|
# generate the index.html files for the albums
|
||||||
if self.settings['SIGLICAN_WRITE_HTML']: # defaults to True
|
if self.settings['SIGLICAN_WRITE_HTML']: # defaults to True
|
||||||
# locate the theme; check for a custom theme in ./sigal/themes, if not
|
# locate the theme; check for a custom theme in ./sigal/themes, if not
|
||||||
|
@ -254,19 +254,21 @@ class SigalGalleryGenerator(Generator):
|
||||||
if not os.path.exists(self.theme):
|
if not os.path.exists(self.theme):
|
||||||
raise Exception("siglican: unable to find theme: %s" %
|
raise Exception("siglican: unable to find theme: %s" %
|
||||||
os.path.basename(self.theme))
|
os.path.basename(self.theme))
|
||||||
|
|
||||||
logger.info("siglican theme: %s", self.theme)
|
logger.info("siglican theme: %s", self.theme)
|
||||||
|
|
||||||
self.writer = Writer(self.context, self.theme, 'album')
|
self.writer = Writer(self.context, self.theme, 'album')
|
||||||
for album in self.albums.values():
|
for album in self.albums.values():
|
||||||
self.writer.write(album)
|
self.writer.write(album)
|
||||||
|
|
||||||
## possible cleanup:
|
## possible cleanup:
|
||||||
## - bring back Writer options that Sigal had?
|
## - bring back Writer options that Sigal had?
|
||||||
## - make sure thumbnails don't break in some cases [fixed?]
|
## - make sure thumbnails don't break in some cases [fixed?]
|
||||||
|
|
||||||
|
|
||||||
def get_generators(generators):
|
def get_generators(generators):
|
||||||
return SigalGalleryGenerator
|
return SigalGalleryGenerator
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
signals.get_generators.connect(get_generators)
|
signals.get_generators.connect(get_generators)
|
||||||
|
|
Loading…
Reference in a new issue