diff --git a/hyde/engine.py b/hyde/engine.py index 45ab14a..d1f53a5 100644 --- a/hyde/engine.py +++ b/hyde/engine.py @@ -25,7 +25,8 @@ class Engine(Application): @command(description='hyde - a python static website generator', 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") def main(self, args): """ @@ -33,7 +34,9 @@ class Engine(Application): to provide common parameters for the subcommands and some generic stuff like version and metadata """ - pass + if args.verbose: + import logging + logger.setLevel(logging.DEBUG) @subcommand('create', help='Create a new hyde 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 sitepath. """ + self.main(args) sitepath = Folder(Folder(args.sitepath).fully_expanded_path) if sitepath.exists and not args.overwrite: raise HydeException( @@ -70,6 +74,7 @@ class Engine(Application): The generate command. Generates the site at the given deployment directory. """ + self.main(args) site = self.make_site(args.sitepath, args.config) from hyde.generator import Generator gen = Generator(site) @@ -90,12 +95,20 @@ class Engine(Application): deployment directory, address and port. Regenerates the entire site or specific files based on ths request. """ + self.main(args) sitepath = Folder(Folder(args.sitepath).fully_expanded_path) config_file = sitepath.child(args.config) site = self.make_site(args.sitepath, args.config) from hyde.server import HydeWebServer 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): """ diff --git a/hyde/generator.py b/hyde/generator.py index 1b83dca..99dafa1 100644 --- a/hyde/generator.py +++ b/hyde/generator.py @@ -78,7 +78,7 @@ class Generator(object): if not self.template: logger.info("Generating site at [%s]" % self.site.sitepath) 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__) logger.info("Configuring the template environment") @@ -224,7 +224,7 @@ class Generator(object): def __generate_node__(self, node): for node in node.walk(): - logger.info("Generating Node [%s]", node) + logger.debug("Generating Node [%s]", node) self.events.begin_node(node) for resource in node.resources: self.__generate_resource__(resource) @@ -232,15 +232,15 @@ class Generator(object): def __generate_resource__(self, resource): if not resource.is_processable: - logger.info("Skipping [%s]", resource) + logger.debug("Skipping [%s]", resource) return - logger.info("Processing [%s]", resource) + logger.debug("Processing [%s]", resource) with self.context_for_resource(resource) as context: if resource.source_file.is_text: text = resource.source_file.read_all() text = self.events.begin_text_resource(resource, text) or text if resource.uses_template: - logger.info("Rendering [%s]", resource) + logger.debug("Rendering [%s]", resource) text = self.template.render(text, context) text = self.events.text_resource_complete( resource, text) or text @@ -249,7 +249,7 @@ class Generator(object): target.parent.make() target.write(text) else: - logger.info("Copying binary file [%s]", resource) + logger.debug("Copying binary file [%s]", resource) self.events.begin_binary_resource(resource) target = File(self.site.config.deploy_root_path.child( resource.relative_deploy_path)) diff --git a/hyde/loader.py b/hyde/loader.py index 2a173cd..9b94618 100644 --- a/hyde/loader.py +++ b/hyde/loader.py @@ -20,7 +20,7 @@ def load_python_object(name): if module_name == '': (module_name, object_name) = (object_name, module_name) try: - logger.info('Loading module [%s]' % module_name) + logger.debug('Loading module [%s]' % module_name) module = __import__(module_name) except ImportError: raise HydeException("The given module name [%s] is invalid." % @@ -36,7 +36,7 @@ def load_python_object(name): module_name) try: - logger.info('Getting object [%s] from module [%s]' % + logger.debug('Getting object [%s] from module [%s]' % (object_name, module_name)) return getattr(module, object_name) except AttributeError: diff --git a/hyde/site.py b/hyde/site.py index 507258d..902a0de 100644 --- a/hyde/site.py +++ b/hyde/site.py @@ -254,7 +254,7 @@ class RootNode(Node): folder = Folder(a_folder) node = self.node_from_path(folder) if node: - logger.info("Node exists at [%s]" % node.relative_path) + logger.debug("Node exists at [%s]" % node.relative_path) return node if not folder.is_descendant_of(self.source_folder): @@ -275,7 +275,7 @@ class RootNode(Node): for h_folder in hierarchy: node = node.add_child_node(h_folder) 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)) return node @@ -290,7 +290,7 @@ class RootNode(Node): resource = self.resource_from_path(afile) if resource: - logger.info("Resource exists at [%s]" % resource.relative_path) + logger.debug("Resource exists at [%s]" % resource.relative_path) return resource if not afile.is_descendant_of(self.source_folder): @@ -305,7 +305,7 @@ class RootNode(Node): resource = node.add_child_resource(afile) 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)) return resource diff --git a/hyde/util.py b/hyde/util.py index d500768..8ea7f96 100644 --- a/hyde/util.py +++ b/hyde/util.py @@ -19,10 +19,9 @@ except: def getLoggerWithConsoleHandler(logger_name): logger = logging.getLogger(logger_name) - logger.setLevel(logging.DEBUG) + logger.setLevel(logging.INFO) 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 " "%(message)s", datefmt='%H:%M:%S') handler.setFormatter(formatter)