csvsql 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- csvsql/__init__.py +3 -0
- csvsql/__main__.py +5 -0
- csvsql/cli.py +58 -0
- csvsql/static/app.js +882 -0
- csvsql/static/index.html +64 -0
- csvsql/static/style.css +581 -0
- csvsql-0.1.0.dist-info/METADATA +75 -0
- csvsql-0.1.0.dist-info/RECORD +12 -0
- csvsql-0.1.0.dist-info/WHEEL +5 -0
- csvsql-0.1.0.dist-info/entry_points.txt +2 -0
- csvsql-0.1.0.dist-info/licenses/LICENSE +21 -0
- csvsql-0.1.0.dist-info/top_level.txt +1 -0
csvsql/__init__.py
ADDED
csvsql/__main__.py
ADDED
csvsql/cli.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""CLI entry point — serves the CSVSQL web app and opens a browser."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import os
|
|
5
|
+
import signal
|
|
6
|
+
import sys
|
|
7
|
+
import threading
|
|
8
|
+
import webbrowser
|
|
9
|
+
from functools import partial
|
|
10
|
+
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main():
|
|
14
|
+
parser = argparse.ArgumentParser(
|
|
15
|
+
prog="csvsql",
|
|
16
|
+
description="Browser-based CSV database with SQL query support.",
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"-p", "--port", type=int, default=8000, help="port to serve on (default: 8000)"
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"--no-browser", action="store_true", help="don't open a browser automatically"
|
|
23
|
+
)
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"--host", default="127.0.0.1", help="host to bind to (default: 127.0.0.1)"
|
|
26
|
+
)
|
|
27
|
+
args = parser.parse_args()
|
|
28
|
+
|
|
29
|
+
static_dir = os.path.join(os.path.dirname(__file__), "static")
|
|
30
|
+
handler = partial(SimpleHTTPRequestHandler, directory=static_dir)
|
|
31
|
+
|
|
32
|
+
# Try the requested port, increment if unavailable
|
|
33
|
+
port = args.port
|
|
34
|
+
for attempt in range(10):
|
|
35
|
+
try:
|
|
36
|
+
server = HTTPServer((args.host, port), handler)
|
|
37
|
+
break
|
|
38
|
+
except OSError:
|
|
39
|
+
port += 1
|
|
40
|
+
else:
|
|
41
|
+
print(f"Error: Could not find an available port.", file=sys.stderr)
|
|
42
|
+
sys.exit(1)
|
|
43
|
+
|
|
44
|
+
url = f"http://{args.host}:{port}"
|
|
45
|
+
print(f"Serving CSVSQL at {url}")
|
|
46
|
+
print("Press Ctrl+C to stop.")
|
|
47
|
+
|
|
48
|
+
if not args.no_browser:
|
|
49
|
+
threading.Timer(0.5, webbrowser.open, args=(url,)).start()
|
|
50
|
+
|
|
51
|
+
signal.signal(signal.SIGINT, lambda *_: sys.exit(0))
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
server.serve_forever()
|
|
55
|
+
except KeyboardInterrupt:
|
|
56
|
+
pass
|
|
57
|
+
finally:
|
|
58
|
+
server.server_close()
|