def test_on_moved_for_file_regenerates_output(self): markdown = os.path.join(self.site.path, 'index.md') open(markdown, 'w').close() handler = SiteHandler(self.director) event = events.FileMovedEvent('', markdown) handler.on_moved(event) html = os.path.join(self.director.config.outdir, 'index.html') self.assertTrue(os.path.exists(html))
def test_on_moved_for_directory_makes_new_directory(self): directory = os.path.join(self.site.path, 'directory') os.mkdir(directory) handler = SiteHandler(self.director) event = events.DirMovedEvent('', directory) handler.on_moved(event) out_directory = os.path.join(self.director.config.outdir, 'directory') self.assertTrue(os.path.exists(out_directory)) self.assertTrue(os.path.isdir(out_directory))
def test_on_create_generates_directory(self): """Test that creation of a directory in the site source creates a directory in the output.""" directory = os.path.join(self.site.path, 'directory') os.mkdir(directory) handler = SiteHandler(self.director) event = events.DirCreatedEvent(directory) handler.on_created(event) out_directory = os.path.join(self.director.config.outdir, 'directory') self.assertTrue(os.path.exists(out_directory)) self.assertTrue(os.path.isdir(out_directory))
def serve(site, director): """Run a simple web server that serve the output directory and watches for changes to the site. When something is changed, it should be generated. """ # Override the log level to display some interactive messages with the # user. With the dev server running, there's no sense in being silent. logger.setLevel(logging.INFO) # Start the watchdog. event_handler = SiteHandler(director) observer = Observer() observer.schedule(event_handler, site.path, recursive=True) observer.start() # The simple HTTP server is pretty dumb and does not even take a path to # serve. The only way to serve the right path is to change the directory. outdir = director.outdir os.chdir(outdir) socketserver.TCPServer.allow_reuse_address = True httpd = socketserver.TCPServer(('', PORT), SimpleHTTPRequestHandler) logger.info( _('Serving {outdir} at http://localhost:{port}/.' '\nPress Ctrl-C to quit.').format(outdir=outdir, port=PORT)) try: httpd.serve_forever() except KeyboardInterrupt: logger.info(_('\nBye.')) observer.stop() observer.join()