Commit 21671879 authored by Kirill Smelkov's avatar Kirill Smelkov

X wcfs: Teach entrypoint frontend to handle subcomannds: serve, status, stop

This will be used to implement both wcfs service and wcfs promise.
parent 481ffb89
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2020 Nexedi SA and Contributors.
# Copyright (C) 2018-2021 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
......@@ -68,7 +68,7 @@ import logging as log
from os.path import dirname
from errno import ENOENT, EEXIST
from golang import chan, select, default, func
from golang import chan, select, default, func, defer
from golang import sync, context
from golang.gcompat import qq
......@@ -377,21 +377,42 @@ def serve(zurl, optv, exec_=False):
# if called as main just -> exec serve()
# if called as main -> serve as frontend to wcfs service:
#
# wcfs serve <zurl>
# wcfs status <zurl>
# wcfs stop <zurl>
def _usage(w):
progname = os.path.basename(sys.argv[0])
print("Wcfs serves WCFS filesystem for ZODB at zurl for wendelin.core .\n", file=w)
print("Usage: %s [-h | wcfs.go options] zurl" % progname, file=w)
print("Usage: %s (serve|stop|status) [-h | wcfs.go options] zurl" % progname, file=w)
sys.exit(2)
@func
def main():
argv = sys.argv[1:]
if len(argv) == 0:
if len(argv) < 2 or argv[0] == '-h':
_usage(sys.stderr)
if argv[0] == '-h':
os.execv(_wcfs_exe(), [_wcfs_exe(), '-h'])
cmd = argv[0]
argv = argv[1:]
zurl = argv[-1] # -a -b zurl -> zurl
optv = argv[:-1] # -a -b zurl -> -a -b
if cmd == "serve":
if argv[0] == '-h':
os.execv(_wcfs_exe(), [_wcfs_exe(), '-h'])
serve(zurl, optv, exec_=True)
elif cmd == "status":
wc = join(zurl, autostart=False) # raises if wcfs is not started
defer(wc.close)
print("wcfs<%s>: serving ok" % zurl)
elif cmd == "stop":
mntpt = _mntpt_4zurl(zurl)
subprocess.check_call(["fusermount", "-u", mntpt])
else:
print("wcfs: unknown command %s" % qq(cmd), file=sys.stderr)
sys.exit(2)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment