Browse Source

py3 compat: print, iteritems, imports

pull/40/head
Simon Conseil 13 years ago
parent
commit
21c4041f3b
  1. 10
      setup.py
  2. 17
      sigal/__init__.py
  3. 14
      sigal/compat.py
  4. 7
      sigal/gallery.py
  5. 6
      sigal/pkgmeta.py
  6. 9
      sigal/settings.py

10
setup.py

@ -22,8 +22,10 @@ with open('docs/changelog.rst') as f:
# Load package meta from the pkgmeta module without loading the package.
pkgmeta = {}
execfile(os.path.join(os.path.dirname(__file__), 'sigal', 'pkgmeta.py'),
pkgmeta)
pkgmeta_file = os.path.join(os.path.dirname(__file__), 'sigal', 'pkgmeta.py')
with open(pkgmeta_file) as f:
code = compile(f.read(), 'pkgmeta.py', 'exec')
exec(code, pkgmeta)
setup(
name='sigal',
@ -46,8 +48,10 @@ setup(
'Environment :: Console',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Multimedia :: Graphics :: Viewers',
'Topic :: Software Development :: Libraries :: Python Modules',

17
sigal/__init__.py

@ -30,9 +30,9 @@ sigal is yet another python script to prepare a static gallery of images:
* generate html pages.
"""
from __future__ import absolute_import
from __future__ import absolute_import, print_function
import codecs
import io
import logging
import os
import sys
@ -72,9 +72,9 @@ def init():
from pkg_resources import resource_string
conf = resource_string(__name__, 'templates/sigal.conf.py')
with codecs.open('sigal.conf.py', 'w', 'utf-8') as f:
with io.open('sigal.conf.py', 'w', 'utf-8') as f:
f.write(conf)
print "Sample config file created: sigal.conf.py"
print("Sample config file created: sigal.conf.py")
@arg('source', nargs='?', help='Input directory')
@ -97,7 +97,7 @@ def build(source, destination, debug=False, verbose=False, force=False,
settings_file = config or _DEFAULT_CONFIG_FILE
if not os.path.isfile(settings_file):
logger.error("Settings file not found (%s)", settings_file)
logger.error("Settings file not found: %s", settings_file)
sys.exit(1)
settings = read_settings(settings_file)
@ -108,8 +108,7 @@ def build(source, destination, debug=False, verbose=False, force=False,
logger.info("Input : %s", settings['source'])
if not settings['source'] or not os.path.isdir(settings['source']):
logger.error("Input directory '%s' does not exist.",
settings['source'])
logger.error("Input directory not found: %s", settings['source'])
sys.exit(1)
logger.info("Output : %s", settings['destination'])
@ -138,7 +137,7 @@ def serve(path):
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler, False)
print " * Running on http://127.0.0.1:%i/" % PORT
print(" * Running on http://127.0.0.1:{}/".format(PORT))
try:
httpd.allow_reuse_address = True
@ -146,7 +145,7 @@ def serve(path):
httpd.server_activate()
httpd.serve_forever()
except KeyboardInterrupt:
print '\nAll done!'
print('\nAll done!')
else:
sys.stderr.write("The '%s' directory doesn't exist.\n" % path)

14
sigal/compat.py

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
import sys
PY2 = sys.version_info[0] == 2
if not PY2:
text_type = str
string_types = (str,)
unichr = chr
else:
text_type = unicode # NOQA
string_types = (str, unicode) # NOQA
unichr = unichr

7
sigal/gallery.py

@ -38,9 +38,13 @@ from PIL import Image as PILImage
import sigal.image
import sigal.video
from . import compat
from .settings import get_thumb
from .writer import Writer
if not compat.PY2:
from functools import reduce
DESCRIPTION_FILE = "index.md"
# Label with for the progress bar. The max value is 48 character = 80 - 32 for
@ -96,7 +100,8 @@ class PathsDb(object):
}
# get information for each directory
for path, dirnames, filenames in os.walk(self.basepath, followlinks=True):
for path, dirnames, filenames in os.walk(self.basepath,
followlinks=True):
relpath = os.path.relpath(path, self.basepath)
# sort images and sub-albums by name

6
sigal/pkgmeta.py

@ -1,8 +1,8 @@
# -*- coding:utf-8 -*-
__title__ = 'sigal'
__author__ = u"Simon Conseil"
__version__ = "0.5.1"
__license__ = "MIT"
__author__ = 'Simon Conseil'
__version__ = '0.5.1'
__license__ = 'MIT'
__url__ = 'https://github.com/saimn/sigal'
__all__ = ['__title__', '__author__', '__version__', '__license__', '__url__']

9
sigal/settings.py

@ -60,6 +60,7 @@ def get_thumb(settings, filename):
"""Return the path to the thumb.
examples:
>>> default_settings = create_settings()
>>> get_thumb(default_settings, "bar/foo.jpg")
"bar/thumbnails/foo.jpg"
>>> get_thumb(default_settings, "bar/foo.png")
@ -96,8 +97,12 @@ def read_settings(filename=None):
if filename:
logger.debug("Settings file: %s", filename)
tempdict = {}
execfile(filename, tempdict)
settings.update((k, v) for k, v in tempdict.iteritems()
with open(filename) as f:
code = compile(f.read(), filename, 'exec')
exec(code, tempdict)
settings.update((k, v) for k, v in tempdict.items()
if k not in ['__builtins__'])
# Make the paths relative to the settings file

Loading…
Cancel
Save