Permalink
Browse files

Merge pull request #9 from ralsina/packaging

PackagingDoing it, and if it dies, it dies, like Ivan Drago would say.
  • Loading branch information...
2 parents dfeb02d + 410cf1b commit 72977bce5cfe5b8db911bc385fd8869af194cf3a @ralsina committed Apr 24, 2012
Showing with 217 additions and 16 deletions.
  1. +28 −0 README.md
  2. 0 {stories → docs}/manual.txt
  3. 0 {stories → docs}/theming.txt
  4. 0 README.rst → nikola/data/samplesite/README.txt
  5. +3 −1 dodo.py → nikola/data/samplesite/dodo_py
  6. BIN { → nikola/data/samplesite}/files/favicon.ico
  7. 0 { → nikola/data/samplesite}/galleries/demo/index.txt
  8. BIN { → nikola/data/samplesite}/galleries/demo/tesla2_lg.jpg
  9. BIN { → nikola/data/samplesite}/galleries/demo/tesla4_lg.jpg
  10. BIN { → nikola/data/samplesite}/galleries/demo/tesla_conducts_lg.jpg
  11. BIN { → nikola/data/samplesite}/galleries/demo/tesla_lightning1_lg.jpg
  12. BIN { → nikola/data/samplesite}/galleries/demo/tesla_lightning2_lg.jpg
  13. BIN { → nikola/data/samplesite}/galleries/demo/tesla_tower1_lg.jpg
  14. 0 { → nikola/data/samplesite}/posts/1.meta
  15. 0 { → nikola/data/samplesite}/posts/1.txt
  16. 0 { → nikola/data/samplesite}/stories/1.meta
  17. 0 { → nikola/data/samplesite}/stories/1.txt
  18. 0 { → nikola/data/samplesite}/stories/configsample.meta
  19. 0 { → nikola/data/samplesite}/stories/configsample.txt
  20. 0 { → nikola/data/samplesite}/stories/manual.meta
  21. +1 −0 nikola/data/samplesite/stories/manual.txt
  22. 0 { → nikola/data/samplesite}/stories/quickref.meta
  23. 0 { → nikola/data/samplesite}/stories/quickref.txt
  24. 0 { → nikola/data/samplesite}/stories/quickstart.meta
  25. 0 { → nikola/data/samplesite}/stories/quickstart.txt
  26. 0 { → nikola/data/samplesite}/stories/theming.meta
  27. +1 −0 nikola/data/samplesite/stories/theming.txt
  28. 0 { → nikola/data}/themes/default/assets/css/bootstrap-responsive.css
  29. 0 { → nikola/data}/themes/default/assets/css/bootstrap-responsive.min.css
  30. 0 { → nikola/data}/themes/default/assets/css/bootstrap.css
  31. 0 { → nikola/data}/themes/default/assets/css/bootstrap.min.css
  32. 0 { → nikola/data}/themes/default/assets/css/code.css
  33. 0 { → nikola/data}/themes/default/assets/css/colorbox.css
  34. 0 { → nikola/data}/themes/default/assets/css/custom.css
  35. BIN { → nikola/data}/themes/default/assets/css/images/border.png
  36. BIN { → nikola/data}/themes/default/assets/css/images/controls.png
  37. BIN { → nikola/data}/themes/default/assets/css/images/ie6/borderBottomCenter.png
  38. BIN { → nikola/data}/themes/default/assets/css/images/ie6/borderBottomLeft.png
  39. BIN { → nikola/data}/themes/default/assets/css/images/ie6/borderBottomRight.png
  40. BIN { → nikola/data}/themes/default/assets/css/images/ie6/borderMiddleLeft.png
  41. BIN { → nikola/data}/themes/default/assets/css/images/ie6/borderMiddleRight.png
  42. BIN { → nikola/data}/themes/default/assets/css/images/ie6/borderTopCenter.png
  43. BIN { → nikola/data}/themes/default/assets/css/images/ie6/borderTopLeft.png
  44. BIN { → nikola/data}/themes/default/assets/css/images/ie6/borderTopRight.png
  45. BIN { → nikola/data}/themes/default/assets/css/images/loading.gif
  46. BIN { → nikola/data}/themes/default/assets/css/images/loading_background.png
  47. BIN { → nikola/data}/themes/default/assets/css/images/overlay.png
  48. 0 { → nikola/data}/themes/default/assets/css/rst.css
  49. BIN { → nikola/data}/themes/default/assets/img/glyphicons-halflings-white.png
  50. BIN { → nikola/data}/themes/default/assets/img/glyphicons-halflings.png
  51. 0 { → nikola/data}/themes/default/assets/js/bootstrap.js
  52. 0 { → nikola/data}/themes/default/assets/js/bootstrap.min.js
  53. 0 { → nikola/data}/themes/default/assets/js/jquery-1.7.2.min.js
  54. 0 { → nikola/data}/themes/default/assets/js/jquery.colorbox-min.js
  55. 0 { → nikola/data}/themes/default/messages/en.py
  56. 0 { → nikola/data}/themes/default/messages/es.py
  57. 0 { → nikola/data}/themes/default/messages/fr.py
  58. 0 { → nikola/data}/themes/default/templates/base.tmpl
  59. 0 { → nikola/data}/themes/default/templates/gallery.tmpl
  60. 0 { → nikola/data}/themes/default/templates/index.tmpl
  61. 0 { → nikola/data}/themes/default/templates/list.tmpl
  62. 0 { → nikola/data}/themes/default/templates/post.tmpl
  63. 0 { → nikola/data}/themes/default/templates/story.tmpl
  64. 0 { → nikola/data}/themes/jinja-default/README
  65. 0 { → nikola/data}/themes/jinja-default/parent
  66. 0 { → nikola/data}/themes/jinja-default/templates/base.tmpl
  67. 0 { → nikola/data}/themes/jinja-default/templates/gallery.tmpl
  68. 0 { → nikola/data}/themes/jinja-default/templates/index.tmpl
  69. 0 { → nikola/data}/themes/jinja-default/templates/list.tmpl
  70. 0 { → nikola/data}/themes/jinja-default/templates/post.tmpl
  71. 0 { → nikola/data}/themes/jinja-default/templates/story.tmpl
  72. 0 { → nikola/data}/themes/site/README
  73. 0 { → nikola/data}/themes/site/parent
  74. 0 { → nikola/data}/themes/site/templates/base.tmpl
  75. 0 { → nikola/data}/themes/site/templates/post.tmpl
  76. +2 −2 nikola/jinja_templates.py
  77. +2 −2 nikola/mako_templates.py
  78. +32 −11 nikola/nikola.py
  79. +30 −0 scripts/nikola
  80. +118 −0 setup.py
View
@@ -0,0 +1,28 @@
+Nikola, a Static Site and Blog Generator
+========================================
+
+In goes content, out comes a website, ready to deploy.
+
+Why Static Websites?
+--------------------
+
+Static websites are safer, use fewer resources, and avoid vendor and platform lockin.
+You can read more about this in the [Nikola Handbook.](http://nikola.ralsina.com.ar/handbook.html#why-static)
+
+What Can Nikola Do?
+-------------------
+
+It has many features, but here are some of the nicer ones:
+
+* Blogs, with tags, feeds, archives, comments, etc.
+* [Theming](http://nikola.ralsina.com.ar/theming.html)
+* Fast builds, thanks to [doit](http://python-doit.sf.net)
+* Flexible
+* Small codebase (programmers can understand all of Nikola in a couple of hours)
+* [reStructuredText](http://nikola.ralsina.com.ar/quickstart.html) or [Markdown](http://daringfireball.net/projects/markdown) as input languages.
+* Easy [image galleries](http://nikola.ralsina.com.ar/galleries/demo/) (just drop files in a folder!)
+* Syntax highlighting for almost any programming language or markup
+* Multilingual sites
+* Doesn't reinvent wheels, leverages existing tools.
+
+For more information, see http://nikola.ralsina.com.ar
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -185,7 +185,9 @@
}
# Sorry, this is magic. It just is.
-execfile("nikola/nikola.py")
+import os
+import nikola
+execfile(os.path.join(os.path.dirname(nikola.__file__), "nikola.py"))
if __name__ == "__main__":
nikola_main()
# End of magic.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -8,9 +8,9 @@
lookup = None
-def get_template_lookup(themes):
+def get_template_lookup(directories):
return jinja2.Environment(loader=jinja2.FileSystemLoader(
- [os.path.join('themes', name, "templates") for name in themes],
+ directories,
encoding='utf-8',
))
View
@@ -9,9 +9,9 @@
lookup = None
-def get_template_lookup(themes):
+def get_template_lookup(directories):
return TemplateLookup(
- directories=[os.path.join('themes', name, "templates") for name in themes],
+ directories=directories,
module_directory='tmp',
output_encoding='utf-8',
)
View
@@ -55,11 +55,25 @@ def execute(self, out=None, err=None):
THEME = locals().get('THEME', 'default')
+def get_theme_path(theme):
+ """Given a theme name, returns the path where its files are located.
+
+ Looks in ./themes and in the place where themes go when installed.
+ """
+ dir_name = os.path.join('themes', theme)
+ if os.path.isdir(dir_name):
+ return dirname
+ dir_name = os.path.join(os.path.dirname(nikola.__file__), 'data', 'themes', theme)
+ if os.path.isdir(dir_name):
+ return dir_name
+ raise Exception(u"Can't find theme '%s'" % theme)
+
def get_theme_chain():
"""Create the full theme inheritance chain."""
THEMES = [THEME]
def get_parent(theme_name):
parent_path = os.path.join('themes', theme_name, 'parent')
+ parent_path = os.path.join(get_theme_path(theme_name), 'parent')
if os.path.isfile(parent_path):
with open(parent_path) as fd:
return fd.readlines()[0].strip()
@@ -92,8 +106,9 @@ def get_parent(theme_name):
except Exception, exc:
print "There was a problem loading Jinja2. Is it installed?", exc
sys.exit(1)
-
-templates_module.lookup = templates_module.get_template_lookup(THEMES)
+
+templates_module.lookup = templates_module.get_template_lookup(
+ [os.path.join(get_theme_path(name), "templates") for name in THEMES])
def render_template(template_name, output_name, context):
templates_module.render_template(template_name, output_name, context, GLOBAL_CONTEXT)
template_deps = templates_module.template_deps
@@ -110,7 +125,7 @@ def load_messages():
"""
MESSAGES = defaultdict(dict)
for theme_name in THEMES[::-1]:
- MSG_FOLDER = os.path.join('themes', theme_name, 'messages')
+ MSG_FOLDER = os.path.join(get_theme_path(theme_name), 'messages')
oldpath = sys.path
sys.path.insert(0, MSG_FOLDER)
for lang in TRANSLATIONS.keys():
@@ -197,7 +212,7 @@ def task_copy_assets():
"""
tasks = {}
for theme_name in THEMES:
- src = os.path.join('themes', theme_name, 'assets')
+ src = os.path.join(get_theme_path(theme_name), 'assets')
dst = os.path.join('output', 'assets')
for task in copy_tree(src, dst):
if task['name'] in tasks:
@@ -606,13 +621,18 @@ def task_render_galleries():
return
try:
import Image
- def create_thumb(src, dst):
- size = THUMBNAIL_SIZE, THUMBNAIL_SIZE
- im = Image.open(src)
- im.thumbnail(size, Image.ANTIALIAS)
- im.save(dst)
except ImportError:
- create_thumb = copy_file
+ try:
+ from PIL import Image
+ def create_thumb(src, dst):
+ size = THUMBNAIL_SIZE, THUMBNAIL_SIZE
+ im = Image.open(src)
+ im.thumbnail(size, Image.ANTIALIAS)
+ im.save(dst)
+ except ImportError:
+ create_thumb = copy_file
+
+
# gallery_path is "gallery/name"
for gallery_path in gallery_list:
@@ -900,7 +920,8 @@ def copy_file(source, dest):
def nikola_main():
print "Starting doit..."
os.system("doit -f %s" % __file__)
-
+
+
def path(kind, name=None, lang=DEFAULT_LANG, is_link=False):
"""Build the path to a certain kind of page.
View
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+"""Nikola main script."""
+
+import os
+import shutil
+import sys
+
+import nikola
+
+USAGE = """To create a new site in a folder, run "nikola init foldername".
+
+The destination folder must not exist.
+"""
+
+
+def init(dst):
+ """Create a copy of demosite in the current folder."""
+ src = os.path.join(os.path.dirname(nikola.__file__),'data','samplesite')
+ shutil.copytree(src, dst)
+ shutil.move(os.path.join(dst, 'dodo_py'), os.path.join(dst, 'dodo.py'))
+ print "A new site with some sample data has been created at %s." % dst
+ print "See README.txt in that folder for more information."
+
+if __name__ == "__main__":
+ if len(sys.argv)==3 and sys.argv[1] == "init":
+ print "Doing init"
+ init(sys.argv[2])
+ else:
+ print USAGE
View
118 setup.py
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+
+# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
+# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
+# Note: you may want to copy this into your setup.py file verbatim, as
+# you can't import this from another package, when you don't know if
+# that package is installed yet.
+
+import os
+import sys
+from fnmatch import fnmatchcase
+from distutils.util import convert_path
+
+# Provided as an attribute, so you can append to these instead
+# of replicating them:
+standard_exclude = ('*.pyc', '*$py.class', '*~', '.*', '*.bak')
+standard_exclude_directories = ('.*', 'CVS', '_darcs', './build',
+ './dist', 'EGG-INFO', '*.egg-info')
+
+def find_package_data(
+ where='.', package='',
+ exclude=standard_exclude,
+ exclude_directories=standard_exclude_directories,
+ only_in_packages=True,
+ show_ignored=False):
+ """
+ Return a dictionary suitable for use in ``package_data``
+ in a distutils ``setup.py`` file.
+
+ The dictionary looks like::
+
+ {'package': [files]}
+
+ Where ``files`` is a list of all the files in that package that
+ don't match anything in ``exclude``.
+
+ If ``only_in_packages`` is true, then top-level directories that
+ are not packages won't be included (but directories under packages
+ will).
+
+ Directories matching any pattern in ``exclude_directories`` will
+ be ignored; by default directories with leading ``.``, ``CVS``,
+ and ``_darcs`` will be ignored.
+
+ If ``show_ignored`` is true, then all the files that aren't
+ included in package data are shown on stderr (for debugging
+ purposes).
+
+ Note patterns use wildcards, or can be exact paths (including
+ leading ``./``), and all searching is case-insensitive.
+ """
+
+ out = {}
+ stack = [(convert_path(where), '', package, only_in_packages)]
+ while stack:
+ where, prefix, package, only_in_packages = stack.pop(0)
+ for name in os.listdir(where):
+ fn = os.path.join(where, name)
+ if os.path.isdir(fn):
+ bad_name = False
+ for pattern in exclude_directories:
+ if (fnmatchcase(name, pattern)
+ or fn.lower() == pattern.lower()):
+ bad_name = True
+ if show_ignored:
+ print >> sys.stderr, (
+ "Directory %s ignored by pattern %s"
+ % (fn, pattern))
+ break
+ if bad_name:
+ continue
+ if (os.path.isfile(os.path.join(fn, '__init__.py'))
+ and not prefix):
+ if not package:
+ new_package = name
+ else:
+ new_package = package + '.' + name
+ stack.append((fn, '', new_package, False))
+ else:
+ stack.append((fn, prefix + name + '/', package, only_in_packages))
+ elif package or not only_in_packages:
+ # is a file
+ bad_name = False
+ for pattern in exclude:
+ if (fnmatchcase(name, pattern)
+ or fn.lower() == pattern.lower()):
+ bad_name = True
+ if show_ignored:
+ print >> sys.stderr, (
+ "File %s ignored by pattern %s"
+ % (fn, pattern))
+ break
+ if bad_name:
+ continue
+ out.setdefault(package, []).append(prefix+name)
+ return out
+
+from distutils.core import setup
+
+setup(name='Nikola',
+ version='3.1',
+ description='Static blog/website generator',
+ author='Roberto Alsina and others',
+ author_email='ralsina@netmanagers.com.ar',
+ url='http://nikola.ralsina.com.ar/',
+ packages=['nikola'],
+ scripts=['scripts/nikola'],
+ package_data=find_package_data(),
+ data_files=['docs/manual.txt',
+ 'docs/theming.txt'],
+ install_requires = [
+ 'pygments',
+ 'doit',
+ 'mako>=0.6',
+ 'pillow',
+ 'docutils',
+ ],
+ )

0 comments on commit 72977bc

Please sign in to comment.