Fix setup script; proper escaping to make Systemd happy
This commit is contained in:
parent
fda03e28b0
commit
f31344fd71
|
@ -113,8 +113,7 @@ class GraspRequestHandler(BaseHTTPRequestHandler):
|
|||
|
||||
def run(port: str, capture_path: str, template: str):
|
||||
logger = get_logger()
|
||||
if template == repr(DEFAULT_TEMPLATE):
|
||||
template = DEFAULT_TEMPLATE # hack so argparse renders default template with \n characters...
|
||||
logger.info("Using template %s", template)
|
||||
|
||||
# not sure if there is a simpler way to communicate with the server...
|
||||
os.environ[CAPTURE_PATH_VAR] = capture_path
|
||||
|
@ -126,7 +125,7 @@ def run(port: str, capture_path: str, template: str):
|
|||
def setup_parser(p):
|
||||
p.add_argument('--port', type=str, default='12212', help='Port for communicating with extension')
|
||||
p.add_argument('--path', type=str, default='~/capture.org', help='File to capture into')
|
||||
p.add_argument('--template', type=str, default=repr(DEFAULT_TEMPLATE), help=f"""
|
||||
p.add_argument('--template', type=str, default=DEFAULT_TEMPLATE, help=f"""
|
||||
{as_org.__doc__}
|
||||
""")
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
|
||||
import shlex
|
||||
from pathlib import Path
|
||||
from subprocess import check_call, run
|
||||
|
||||
|
@ -32,15 +32,15 @@ def setup(args):
|
|||
|
||||
server_bin = Path(__file__).parent.joinpath('grasp_server.py').absolute()
|
||||
|
||||
template = args.template.replace('%', '%%') # escape for systemd...
|
||||
extra_args = f'--port {args.port} --path {args.path} --template \"{template}\"'
|
||||
template = args.template.replace('%', '%%').replace('\n', r'\n') # escape for systemd...
|
||||
template = shlex.quote(template)
|
||||
extra_args = f'--port {args.port} --path {args.path} --template {template}'
|
||||
|
||||
with out.open('w') as fo:
|
||||
fo.write(SYSTEMD_CONFIG.format(
|
||||
server=server_bin,
|
||||
extra_args=extra_args,
|
||||
))
|
||||
|
||||
try:
|
||||
systemd('stop' , unit_name, method=run) # ignore errors here if it wasn't running in the first place
|
||||
systemd('daemon-reload')
|
||||
|
|
Loading…
Reference in a new issue