Browse Source

Moved the types command line option to config

main
Lakshmi Vyasarajan 13 years ago
parent
commit
8f722a6a36
2 changed files with 18 additions and 8 deletions
  1. +2
    -8
      hyde/engine.py
  2. +16
    -0
      hyde/server.py

+ 2
- 8
hyde/engine.py View File

@@ -99,9 +99,6 @@ class Engine(Application):
help='The configuration used to generate the site')
@store('-d', '--deploy-path', dest='deploy', default=None,
help='Where should the site be generated?')
@append('-t', '--type', dest='types', default=[], nargs='+',
metavar=('TYPE', 'EXT'), help='Add a MIME type mapping for'
' one or more extensions, or set the default MIME type.')
def serve(self, args):
"""
The serve command. Serves the site at the given
@@ -112,10 +109,7 @@ class Engine(Application):
sitepath = Folder(Folder(args.sitepath).fully_expanded_path)
config_file = sitepath.child(args.config)
site = self.make_site(args.sitepath, args.config, args.deploy)
from hyde.server import HydeWebServer, HydeRequestHandler
for t in args.types:
for e in t[1:] or ['']:
HydeRequestHandler.extensions_map[e] = t[0]
from hyde.server import HydeWebServer
server = HydeWebServer(site, args.address, args.port)
logger.info("Starting webserver at [%s]:[%d]", args.address, args.port)
try:
@@ -156,4 +150,4 @@ class Engine(Application):
config = Config(sitepath, config_file=config)
if deploy:
config.deploy_root = deploy
return Site(sitepath, config)
return Site(sitepath, config)

+ 16
- 0
hyde/server.py View File

@@ -130,8 +130,24 @@ class HydeWebServer(HTTPServer):
self.regeneration_time = datetime.strptime('1-1-1998', '%m-%d-%Y')
self.__is_shut_down = threading.Event()
self.__shutdown_request = False
self.map_extensions()
HTTPServer.__init__(self, (address, port),
HydeRequestHandler)

def map_extensions(self):
"""
Maps extensions specified in the configuration.
"""
try:
extensions = self.site.config.server.extensions.to_dict()
except AttributeError:
extensions = {}

for extension, type in extensions.iteritems():
ext = "." + extension if not extension == 'default' else ''
HydeRequestHandler.extensions_map[ext] = type


####### Code from python 2.7.1: Socket server
####### Duplicated to make sure shutdown works in Python v > 2.6
#######


Loading…
Cancel
Save