示例#1
0
 def cmd_build(self):
     t0 = time.time()
     self.current_project().build(['html'])
     t1 = time.time()
     log.success("Project build time: %.2fms" % (1000.0 * (t1 - t0)))
     log.message("Run '%(name)s serve' command for serving or '%(name)s serve --watch'." %
         {'name': self.script_name()})
示例#2
0
    def cmd_serve(self):
        project = self.current_project()

        # Check config
        if 'server' in project.config:
            config = project.config['server']
        else:
            exit_with_error("No 'server' section found in '%s'." % self.args.config)

        log.message("Starting server at %s " % 
            datetime.datetime.now().strftime('%d %B %Y - %H:%M:%S'))
        
        # Watch - doesn't lock thread without explicit .join()
        if self.args.watch:
            import docta.utils.watcher as watcher
            watcher.watch(project)

        # Prepare output dir
        output_dir = project.output_dir('html')
        fs.mkdirs(output_dir)

        # Server - runs and locks current thread
        docta.utils.server.run(output_dir,
                               host=config.get('host', None),
                               port=config.get('port', None))
示例#3
0
文件: watcher.py 项目: 05bit/docta
 def schedule_all(self):
     """
     Schedule all project directories handlers.
     """
     log.message("Watching directory: %s" % self.project.input_dir())
     self.schedule(ProjectPathEventHandler(self),
                   self.project.input_dir(),
                   recursive=True)
示例#4
0
文件: watcher.py 项目: 05bit/docta
    def __init__(self, observer, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # setup
        self.observer = observer
        self.project = observer.project
        self.config = self.project.config.copy()
        self.events_file = (events.FileModifiedEvent, events.FileCreatedEvent, events.FileDeletedEvent)
        self.events_dirs = (events.DirMovedEvent, events.DirDeletedEvent)
        log.message("Watching patterns: %s" % ' '.join(WATCH_PATTERNS_DEFAULT))
示例#5
0
文件: server.py 项目: 05bit/docta
def run(path, host=None, port=None):
    """
    Start simple HTTP server at specified web root directory and port.
    """
    os.chdir(path)
    server_address = (host or DEFAULT_HOST, port or DEFAULT_PORT)
    log.message("Serving directory: %s" % path)
    log.message("Running at http://%s:%s" % server_address)
    log.message("Press ^C to stop server")
    httpd = HTTPServer(server_address, HTTPRequestHandler)

    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        httpd.shutdown()
        log.message("...\nServer was stopped at %s " %
            datetime.datetime.now().strftime('%d %B %Y - %H:%M:%S'))