Browse Source

Added verbose parameter. Cleaned up log messages. handled keyboard interrupt exception

main
Lakshmi Vyasarajan 14 years ago
parent
commit
5944394cf6
5 changed files with 30 additions and 18 deletions
  1. +16
    -3
      hyde/engine.py
  2. +6
    -6
      hyde/generator.py
  3. +2
    -2
      hyde/loader.py
  4. +4
    -4
      hyde/site.py
  5. +2
    -3
      hyde/util.py

+ 16
- 3
hyde/engine.py View File

@@ -25,7 +25,8 @@ class Engine(Application):


@command(description='hyde - a python static website generator', @command(description='hyde - a python static website generator',
epilog='Use %(prog)s {command} -h to get help on individual commands') epilog='Use %(prog)s {command} -h to get help on individual commands')
@version('-v', '--version', version='%(prog)s ' + __version__)
@true('-v', '--verbose', help="Show detailed information in console")
@version('--version', version='%(prog)s ' + __version__)
@store('-s', '--sitepath', default='.', help="Location of the hyde site") @store('-s', '--sitepath', default='.', help="Location of the hyde site")
def main(self, args): def main(self, args):
""" """
@@ -33,7 +34,9 @@ class Engine(Application):
to provide common parameters for the subcommands and some generic stuff to provide common parameters for the subcommands and some generic stuff
like version and metadata like version and metadata
""" """
pass
if args.verbose:
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') @store('-l', '--layout', default='basic', help='Layout for the new site')
@@ -44,6 +47,7 @@ class Engine(Application):
The create command. Creates a new site from the template at the given The create command. Creates a new site from the template at the given
sitepath. sitepath.
""" """
self.main(args)
sitepath = Folder(Folder(args.sitepath).fully_expanded_path) sitepath = Folder(Folder(args.sitepath).fully_expanded_path)
if sitepath.exists and not args.overwrite: if sitepath.exists and not args.overwrite:
raise HydeException( raise HydeException(
@@ -70,6 +74,7 @@ class Engine(Application):
The generate command. Generates the site at the given The generate command. Generates the site at the given
deployment directory. deployment directory.
""" """
self.main(args)
site = self.make_site(args.sitepath, args.config) site = self.make_site(args.sitepath, args.config)
from hyde.generator import Generator from hyde.generator import Generator
gen = Generator(site) gen = Generator(site)
@@ -90,12 +95,20 @@ class Engine(Application):
deployment directory, address and port. Regenerates deployment directory, address and port. Regenerates
the entire site or specific files based on ths request. the entire site or specific files based on ths request.
""" """
self.main(args)
sitepath = Folder(Folder(args.sitepath).fully_expanded_path) sitepath = Folder(Folder(args.sitepath).fully_expanded_path)
config_file = sitepath.child(args.config) config_file = sitepath.child(args.config)
site = self.make_site(args.sitepath, args.config) site = self.make_site(args.sitepath, args.config)
from hyde.server import HydeWebServer from hyde.server import HydeWebServer
server = HydeWebServer(site, args.address, args.port) server = HydeWebServer(site, args.address, args.port)
server.serve_forever()
logger.info("Starting webserver at [%s]:[%d]", args.address, args.port)
try:
server.serve_forever()
except KeyboardInterrupt, SystemExit:
logger.info("Received shutdown request. Shutting down...")
server.shutdown()
logger.info("Server successfully stopped")
exit()


def make_site(self, sitepath, config): def make_site(self, sitepath, config):
""" """


+ 6
- 6
hyde/generator.py View File

@@ -78,7 +78,7 @@ class Generator(object):
if not self.template: if not self.template:
logger.info("Generating site at [%s]" % self.site.sitepath) logger.info("Generating site at [%s]" % self.site.sitepath)
self.template = Template.find_template(self.site) self.template = Template.find_template(self.site)
logger.info("Using [%s] as the template",
logger.debug("Using [%s] as the template",
self.template.__class__.__name__) self.template.__class__.__name__)


logger.info("Configuring the template environment") logger.info("Configuring the template environment")
@@ -224,7 +224,7 @@ class Generator(object):


def __generate_node__(self, node): def __generate_node__(self, node):
for node in node.walk(): for node in node.walk():
logger.info("Generating Node [%s]", node)
logger.debug("Generating Node [%s]", node)
self.events.begin_node(node) self.events.begin_node(node)
for resource in node.resources: for resource in node.resources:
self.__generate_resource__(resource) self.__generate_resource__(resource)
@@ -232,15 +232,15 @@ class Generator(object):


def __generate_resource__(self, resource): def __generate_resource__(self, resource):
if not resource.is_processable: if not resource.is_processable:
logger.info("Skipping [%s]", resource)
logger.debug("Skipping [%s]", resource)
return return
logger.info("Processing [%s]", resource)
logger.debug("Processing [%s]", resource)
with self.context_for_resource(resource) as context: with self.context_for_resource(resource) as context:
if resource.source_file.is_text: if resource.source_file.is_text:
text = resource.source_file.read_all() text = resource.source_file.read_all()
text = self.events.begin_text_resource(resource, text) or text text = self.events.begin_text_resource(resource, text) or text
if resource.uses_template: if resource.uses_template:
logger.info("Rendering [%s]", resource)
logger.debug("Rendering [%s]", resource)
text = self.template.render(text, context) text = self.template.render(text, context)
text = self.events.text_resource_complete( text = self.events.text_resource_complete(
resource, text) or text resource, text) or text
@@ -249,7 +249,7 @@ class Generator(object):
target.parent.make() target.parent.make()
target.write(text) target.write(text)
else: else:
logger.info("Copying binary file [%s]", resource)
logger.debug("Copying binary file [%s]", resource)
self.events.begin_binary_resource(resource) self.events.begin_binary_resource(resource)
target = File(self.site.config.deploy_root_path.child( target = File(self.site.config.deploy_root_path.child(
resource.relative_deploy_path)) resource.relative_deploy_path))


+ 2
- 2
hyde/loader.py View File

@@ -20,7 +20,7 @@ def load_python_object(name):
if module_name == '': if module_name == '':
(module_name, object_name) = (object_name, module_name) (module_name, object_name) = (object_name, module_name)
try: try:
logger.info('Loading module [%s]' % module_name)
logger.debug('Loading module [%s]' % module_name)
module = __import__(module_name) module = __import__(module_name)
except ImportError: except ImportError:
raise HydeException("The given module name [%s] is invalid." % raise HydeException("The given module name [%s] is invalid." %
@@ -36,7 +36,7 @@ def load_python_object(name):
module_name) module_name)


try: try:
logger.info('Getting object [%s] from module [%s]' %
logger.debug('Getting object [%s] from module [%s]' %
(object_name, module_name)) (object_name, module_name))
return getattr(module, object_name) return getattr(module, object_name)
except AttributeError: except AttributeError:


+ 4
- 4
hyde/site.py View File

@@ -254,7 +254,7 @@ class RootNode(Node):
folder = Folder(a_folder) folder = Folder(a_folder)
node = self.node_from_path(folder) node = self.node_from_path(folder)
if node: if node:
logger.info("Node exists at [%s]" % node.relative_path)
logger.debug("Node exists at [%s]" % node.relative_path)
return node return node


if not folder.is_descendant_of(self.source_folder): if not folder.is_descendant_of(self.source_folder):
@@ -275,7 +275,7 @@ class RootNode(Node):
for h_folder in hierarchy: for h_folder in hierarchy:
node = node.add_child_node(h_folder) node = node.add_child_node(h_folder)
self.node_map[str(h_folder)] = node self.node_map[str(h_folder)] = node
logger.info("Added node [%s] to [%s]" % (
logger.debug("Added node [%s] to [%s]" % (
node.relative_path, self.source_folder)) node.relative_path, self.source_folder))


return node return node
@@ -290,7 +290,7 @@ class RootNode(Node):


resource = self.resource_from_path(afile) resource = self.resource_from_path(afile)
if resource: if resource:
logger.info("Resource exists at [%s]" % resource.relative_path)
logger.debug("Resource exists at [%s]" % resource.relative_path)
return resource return resource


if not afile.is_descendant_of(self.source_folder): if not afile.is_descendant_of(self.source_folder):
@@ -305,7 +305,7 @@ class RootNode(Node):


resource = node.add_child_resource(afile) resource = node.add_child_resource(afile)
self.resource_map[str(afile)] = resource self.resource_map[str(afile)] = resource
logger.info("Added resource [%s] to [%s]" %
logger.debug("Added resource [%s] to [%s]" %
(resource.relative_path, self.source_folder)) (resource.relative_path, self.source_folder))
return resource return resource




+ 2
- 3
hyde/util.py View File

@@ -19,10 +19,9 @@ except:


def getLoggerWithConsoleHandler(logger_name): def getLoggerWithConsoleHandler(logger_name):
logger = logging.getLogger(logger_name) logger = logging.getLogger(logger_name)
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout) handler = logging.StreamHandler(sys.stdout)
formatter = ColorFormatter(fmt="$COLOR%(levelname)s "
"$RESET %(asctime)s "
formatter = ColorFormatter(fmt="$RESET %(asctime)s "
"$BOLD$COLOR%(name)s$RESET " "$BOLD$COLOR%(name)s$RESET "
"%(message)s", datefmt='%H:%M:%S') "%(message)s", datefmt='%H:%M:%S')
handler.setFormatter(formatter) handler.setFormatter(formatter)


Loading…
Cancel
Save