Browse Source

* Bug Fix: `hyde create` only fails when `content`, `layout` or `site.yaml`

is present in the target directory. (Issue #21)
*   Bug Fix: Exceptions are now handled with `ArgumentParser.error`.
    (Issue #21)
main
Lakshmi Vyasarajan 13 years ago
parent
commit
c01da9d0a4
4 changed files with 76 additions and 15 deletions
  1. +8
    -0
      CHANGELOG.rst
  2. +29
    -4
      hyde/engine.py
  3. +0
    -3
      hyde/tests/ext/test_sorter.py
  4. +39
    -8
      hyde/tests/test_initialize.py

+ 8
- 0
CHANGELOG.rst View File

@@ -1,3 +1,11 @@
Version 0.8.3c10
===============

* Bug Fix: `hyde create` only fails when `content`, `layout` or `site.yaml`
is present in the target directory. (Issue #21)
* Bug Fix: Exceptions are now handled with `ArgumentParser.error`.
(Issue #21)

Version 0.8.3c9
===============



+ 29
- 4
hyde/engine.py View File

@@ -4,7 +4,7 @@ Implements the hyde entry point commands
"""
from commando import *
from hyde.exceptions import HydeException
from hyde.fs import File, Folder
from hyde.fs import FS, File, Folder
from hyde.layout import Layout, HYDE_DATA
from hyde.model import Config
from hyde.site import Site
@@ -23,6 +23,28 @@ class Engine(Application):
"""
The Hyde Application
"""
def __init__(self, raise_exceptions=False):
self.raise_exceptions = raise_exceptions
super(Engine, self).__init__()

def run(self, args=None):
"""
The engine entry point.
"""

# Catch any errors thrown and log the message.

try:
super(Engine, self).run(args)
except HydeException, he:
if self.raise_exceptions:
raise
elif self.__parser__:
self.__parser__.error(he.message)
else:
logger.error(he.message)
return -1


@command(description='hyde - a python static website generator',
epilog='Use %(prog)s {command} -h to get help on individual commands')
@@ -39,7 +61,7 @@ class Engine(Application):
import logging
logger.setLevel(logging.DEBUG)

@subcommand('create', help='Create a new hyde site')
@subcommand('create', help='Create a new hyde site.')
@store('-l', '--layout', default='basic', help='Layout for the new site')
@true('-f', '--force', default=False, dest='overwrite',
help='Overwrite the current site if it exists')
@@ -50,9 +72,12 @@ class Engine(Application):
"""
self.main(args)
sitepath = Folder(Folder(args.sitepath).fully_expanded_path)
if sitepath.exists and not args.overwrite:
markers = ['content', 'layout', 'site.yaml']
exists = any((FS(sitepath.child(item)).exists for item in markers))

if exists and not args.overwrite:
raise HydeException(
"The given site path [%s] already exists."
"The given site path [%s] already contains a hyde site."
" Use -f to overwrite." % sitepath)
layout = Layout.find_layout(args.layout)
logger.info(


+ 0
- 3
hyde/tests/ext/test_sorter.py View File

@@ -329,6 +329,3 @@ class TestSorterMeta(object):
s.content.walk_resources_sorted_by_index()]

assert pages == sorted(expected, key=lambda f: (File(f).kind, f))




+ 39
- 8
hyde/tests/test_initialize.py View File

@@ -33,26 +33,57 @@ def delete_test_site_at_user():

@raises(HydeException)
@with_setup(create_test_site, delete_test_site)
def test_ensure_exception_when_sitepath_exists():
e = Engine()
def test_ensure_exception_when_site_yaml_exists():
e = Engine(raise_exceptions=True)
File(TEST_SITE.child('site.yaml')).write("Hey")
e.run(e.parse(['-s', str(TEST_SITE), 'create']))

@raises(HydeException)
@with_setup(create_test_site, delete_test_site)
def test_ensure_exception_when_content_folder_exists():
e = Engine(raise_exceptions=True)
TEST_SITE.child_folder('content').make()
e.run(e.parse(['-s', str(TEST_SITE), 'create']))

@raises(HydeException)
@with_setup(create_test_site, delete_test_site)
def test_ensure_exception_when_layout_folder_exists():
e = Engine(raise_exceptions=True)
TEST_SITE.child_folder('layout').make()
e.run(e.parse(['-s', str(TEST_SITE), 'create']))

@with_setup(create_test_site, delete_test_site)
def test_ensure_no_exception_when_empty_site_exists():
e = Engine(raise_exceptions=True)
e.run(e.parse(['-s', str(TEST_SITE), 'create']))
verify_site_contents(TEST_SITE, Layout.find_layout())

@with_setup(create_test_site, delete_test_site)
def test_ensure_no_exception_when_sitepath_exists_when_forced():
e = Engine()
def test_ensure_no_exception_when_forced():
e = Engine(raise_exceptions=True)
TEST_SITE.child_folder('layout').make()
e.run(e.parse(['-s', str(TEST_SITE), 'create', '-f']))
verify_site_contents(TEST_SITE, Layout.find_layout())
TEST_SITE.delete()
TEST_SITE.child_folder('content').make()
e.run(e.parse(['-s', str(TEST_SITE), 'create', '-f']))
assert True #No Exception
verify_site_contents(TEST_SITE, Layout.find_layout())
TEST_SITE.delete()
TEST_SITE.make()
File(TEST_SITE.child('site.yaml')).write("Hey")
e.run(e.parse(['-s', str(TEST_SITE), 'create', '-f']))
verify_site_contents(TEST_SITE, Layout.find_layout())

@with_setup(create_test_site, delete_test_site)
def test_ensure_no_exception_when_sitepath_does_not_exist():
e = Engine()
e = Engine(raise_exceptions=True)
TEST_SITE.delete()
e.run(e.parse(['-s', str(TEST_SITE), 'create', '-f']))
verify_site_contents(TEST_SITE, Layout.find_layout())

@with_setup(create_test_site_at_user, delete_test_site_at_user)
def test_ensure_can_create_site_at_user():
e = Engine()
e = Engine(raise_exceptions=True)
TEST_SITE_AT_USER.delete()
e.run(e.parse(['-s', str(TEST_SITE_AT_USER), 'create', '-f']))
verify_site_contents(TEST_SITE_AT_USER, Layout.find_layout())
@@ -75,6 +106,6 @@ def verify_site_contents(site, layout):
@raises(HydeException)
@with_setup(create_test_site, delete_test_site)
def test_ensure_exception_when_layout_is_invalid():
e = Engine()
e = Engine(raise_exceptions=True)
e.run(e.parse(['-s', str(TEST_SITE), 'create', '-l', 'junk']))


Loading…
Cancel
Save