-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
serve.py
29 lines (22 loc) · 877 Bytes
/
serve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import shutil
import socketserver
import webbrowser
from http.server import SimpleHTTPRequestHandler
import click
from dbt.task.base import ConfiguredTask
from dbt.task.docs import DOCS_INDEX_FILE_PATH
class ServeTask(ConfiguredTask):
def run(self):
os.chdir(self.config.project_target_path)
shutil.copyfile(DOCS_INDEX_FILE_PATH, "index.html")
port = self.args.port
host = self.args.host
if self.args.browser:
webbrowser.open_new_tab(f"http://localhost:{port}")
with socketserver.TCPServer((host, port), SimpleHTTPRequestHandler) as httpd:
click.echo(f"Serving docs at {port}")
click.echo(f"To access from your browser, navigate to: http://localhost:{port}")
click.echo("\n\n")
click.echo("Press Ctrl+C to exit.")
httpd.serve_forever()