[server] add server stub and command line clients
This commit is contained in:
parent
3a09e301c0
commit
589286fad1
10
.mkdocs.yml
10
.mkdocs.yml
@ -13,8 +13,10 @@ markdown_extensions:
|
||||
|
||||
nav:
|
||||
- Home: 'index.md'
|
||||
- 'User Guide':
|
||||
- 'configuration': 'configuration.md'
|
||||
- 'getting started': 'getting_started.md'
|
||||
- 'todos': 'todos.md'
|
||||
- User Guide:
|
||||
- 'Configuration': 'configuration.md'
|
||||
- Introduction:
|
||||
- getting started: 'getting_started.md'
|
||||
- database: 'database_layout.md'
|
||||
- TODOs: 'todos.md'
|
||||
- API reference: 'api/index.html'
|
@ -1,4 +1,4 @@
|
||||
#!/bin/python3
|
||||
#!/usr/bin/python3
|
||||
import argparse
|
||||
import glob
|
||||
import os
|
||||
|
@ -1,13 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import socket
|
||||
import selectors
|
||||
import traceback
|
||||
|
||||
import libclient
|
||||
import fishbook_server.libclient as libclient
|
||||
|
||||
from IPython import embed
|
||||
sel = selectors.DefaultSelector()
|
||||
|
||||
|
||||
@ -70,17 +67,7 @@ def send_request(host, port, request):
|
||||
return message.payload if message else "no response"
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 5:
|
||||
print("usage:", sys.argv[0], "<host> <port> <action> <value>")
|
||||
sys.exit(1)
|
||||
|
||||
host, port = sys.argv[1], int(sys.argv[2])
|
||||
action, value = sys.argv[3], sys.argv[4]
|
||||
def run(host, port, action="search", value="test"):
|
||||
request = create_request(action, value)
|
||||
|
||||
response = send_request(host, port, request)
|
||||
print(response.shape)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
print(response)
|
26
fishbook_server/cmd/runserver.py
Normal file
26
fishbook_server/cmd/runserver.py
Normal file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import fishbook_server.server as server
|
||||
|
||||
|
||||
def run(arguments):
|
||||
server.runserver(arguments.host, arguments.port)
|
||||
|
||||
|
||||
def create_parser():
|
||||
parser = argparse.ArgumentParser(description="Run fishbook dataserver")
|
||||
parser.add_argument("-hs", "--host", type=str, default="", help="The host for which to listen. Use 127.0.0.1 for localhost or any other hosts simply leave it empty.")
|
||||
parser.add_argument("-pr", "--port", type=int, default=65432, help="The port on which the server should be listening which to listen. Default 9000.")
|
||||
return parser
|
||||
|
||||
|
||||
def main():
|
||||
parser = create_parser()
|
||||
args = parser.parse_args()
|
||||
run(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
27
fishbook_server/cmd/test_client.py
Normal file
27
fishbook_server/cmd/test_client.py
Normal file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import fishbook_server.client as client
|
||||
|
||||
def run(arguments):
|
||||
client.run(arguments.host, arguments.port, arguments.action, arguments.value)
|
||||
|
||||
|
||||
def create_parser():
|
||||
parser = argparse.ArgumentParser(description="Run fishbook dataserver")
|
||||
parser.add_argument("-hs", "--host", type=str, default="", help="The host for which to listen. Use 127.0.0.1 for localhost or any other hosts simply leave it empty.")
|
||||
parser.add_argument("-pr", "--port", type=int, default=65432, help="The port on which the server should be listening which to listen. Default 9000.")
|
||||
parser.add_argument("-a", "--action", type=str, default="search", help="")
|
||||
parser.add_argument("-v", "--value", type=str, default="test", help="")
|
||||
return parser
|
||||
|
||||
|
||||
def main():
|
||||
parser = create_parser()
|
||||
args = parser.parse_args()
|
||||
run(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1,29 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import socket
|
||||
import selectors
|
||||
import traceback
|
||||
|
||||
import libserver
|
||||
import fishbook_server.libserver as libserver
|
||||
|
||||
sel = selectors.DefaultSelector()
|
||||
|
||||
|
||||
def accept_wrapper(sock):
|
||||
conn, addr = sock.accept() # Should be ready to read
|
||||
print("accepted connection from", addr)
|
||||
# print("accepted connection from", addr)
|
||||
conn.setblocking(False)
|
||||
message = libserver.Message(sel, conn, addr)
|
||||
sel.register(conn, selectors.EVENT_READ, data=message)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
print("usage:", sys.argv[0], "<host> <port>")
|
||||
sys.exit(1)
|
||||
|
||||
host, port = sys.argv[1], int(sys.argv[2])
|
||||
def runserver(host, port):
|
||||
lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
# Avoid bind() exception: OSError: [Errno 48] Address already in use
|
||||
lsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
@ -51,7 +43,3 @@ def main():
|
||||
print("caught keyboard interrupt, exiting")
|
||||
finally:
|
||||
sel.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
4
setup.py
4
setup.py
@ -6,9 +6,9 @@ assert(sys.version_info >= (3, 0))
|
||||
__version__ = 0.1
|
||||
# exec(open('fishbook/version.py').read())
|
||||
|
||||
requires = ['datajoint', 'nixio', 'numpy', 'PyYAML', 'scipy', 'tqdm', 'yaml', 'backports-datetime-fromisoformat']
|
||||
requires = ['datajoint', 'nixio', 'numpy', 'PyYAML', 'scipy', 'tqdm', 'backports-datetime-fromisoformat']
|
||||
print(find_packages(exclude=['contrib', 'doc', 'tests*', 'site']))
|
||||
|
||||
print(find_packages(exclude=['contrib', 'doc', 'tests*']))
|
||||
setup(name='fishbook',
|
||||
version = __version__,
|
||||
packages = find_packages(exclude=['contrib', 'doc', 'tests*']),
|
||||
|
Loading…
Reference in New Issue
Block a user