Commits (12)
......@@ -39,8 +39,10 @@ mypy:
run:
stage: build
script:
- python setup.py sdist bdist_wheel
- pip install -U dist/*.whl
- python setup.py bdist_wheel
- python setup.py sdist bdist_wheel --plat-name win32
- pip install -U dist/*any.whl
- yaqd --version
artifacts:
paths:
- dist/*
......
#! /usr/bin/env python3
import os
import sys
from setuptools import setup, find_packages
......@@ -14,16 +15,17 @@ def read(fname):
with open(os.path.join(here, "yaqd_control", "VERSION")) as version_file:
version = version_file.read().strip()
extra_files = {"yaqd_control": ["VERSION", "bin/nssm.exe"]}
extra_files = {"yaqd_control": ["VERSION"]}
if "win32" in sys.argv:
extra_files = {"yaqd_control": ["VERSION", "bin/nssm.exe"]}
setup(
name="yaqd-control",
packages=find_packages(exclude=("tests", "tests.*")),
package_data=extra_files,
python_requires=">=3.7",
setup_requires=["pytest-runner"],
tests_require=["pytest", "pytest-cov"],
install_requires=["appdirs", "toml", "click", "prettytable", "colorama"],
install_requires=["appdirs", "toml", "click", "prettytable", "colorama", "msgpack"],
extras_require={
"docs": ["sphinx", "sphinx-gallery>=0.3.0", "sphinx-rtd-theme"],
"dev": ["black", "pre-commit", "pydocstyle"],
......
from ._scan import *
from ._start import start
from ._cache import add_config, clear_cache, read_daemon_cache
from ._enablement import enable, disable, start, stop, reload, restart
from ._scan import scan
from ._status import status
from ._list import list as list_
......@@ -7,6 +7,8 @@ import sys
import appdirs # type: ignore
import click
from .__version__ import __version__
from ._cache import add_config, clear_cache, read_daemon_cache
from ._enablement import enable, disable, start, stop, reload, restart
from ._scan import scan
......@@ -15,6 +17,7 @@ from ._list import list as list_
@click.group()
@click.version_option(__version__)
def main():
pass
......
"""Define version."""
import pathlib
here = pathlib.Path(__file__).resolve().parent
__all__ = ["__version__", "__branch__"]
# read from VERSION file
with open(str(here / "VERSION")) as f:
__version__ = f.read().strip()
# add git branch, if appropriate
p = here.parent / ".git"
if p.is_file():
with open(str(p)) as f:
p = p.parent / f.readline()[8:].strip() # Strip "gitdir: "
p = p / "HEAD"
if p.exists():
with open(str(p)) as f:
__branch__ = f.readline().rstrip().split(r"/")[-1]
__version__ += "+" + __branch__
else:
__branch__ = ""
......@@ -59,11 +59,11 @@ def add_config(filepath):
filepath = pathlib.Path(filepath).absolute()
with open(filepath, "r") as f:
dic = toml.load(f)
kind = dic.get("entry", filepath.parent.name)
kind = filepath.parent.name
if kind.startswith("yaqd-"):
kind = kind[5:]
for k, v in dic.items():
if k in ("entry", "enable", "shared-settings"):
if k in ("enable", "shared-settings"):
continue
dd = DaemonData(
kind=kind,
......
__all__ = ["scan"]
import json
import socket
from pprint import pprint
from dataclasses import fields
import msgpack # type: ignore
from ._daemon_data import DaemonData
from ._cache import read_daemon_cache, write_to_daemon_cache
......@@ -23,12 +25,16 @@ def scan(host="127.0.0.1", start=36000, stop=39999):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((host, i))
s.sendall(b'{"jsonrpc":"2.0", "method": "id", "id":"find"}')
ident = json.loads(s.recv(1024))
s.sendall(msgpack.packb({"ver": "1.0", "method": "id", "id": "find"}))
ident = msgpack.unpackb(s.recv(1024))
kind = ident["result"]["kind"]
name = ident["result"]["name"]
s.sendall(b'{"jsonrpc":"2.0", "method": "config_filepath", "id":"find"}')
config_filepath = json.loads(s.recv(1024))["result"]
s.sendall(
msgpack.packb(
{"ver": "1.0", "method": "get_config_filepath", "id": "find"}
)
)
config_filepath = msgpack.unpackb(s.recv(1024))["result"]
except Exception as e:
if i in old_ports.keys():
kind = old_ports[i].kind
......@@ -36,7 +42,11 @@ def scan(host="127.0.0.1", start=36000, stop=39999):
print(f"...known daemon {kind}:{name} on port {i} not responding")
continue
# format result
kwargs = {k: v for k, v in ident["result"].items() if k in DaemonData.get_field_names()}
kwargs = {
k: v
for k, v in ident["result"].items()
if k in DaemonData.get_field_names()
}
kwargs["host"] = host
kwargs["port"] = i
kwargs["config_filepath"] = config_filepath
......
import argparse
import pathlib
import subprocess
import sys
import appdirs # type: ignore
import toml
def start(config_dir=None):
if config_dir is None:
config_dir = appdirs.user_config_dir("yaqd", "yaq")
config = pathlib.Path(config_dir)
tomls = config.rglob("*.toml")
if not tomls:
print(f"No config files found in {config}")
for fp in config.rglob("*.toml"):
if fp.stem.endswith("state"):
continue
with open(fp, "r") as f:
try:
cd = toml.load(f)
except toml.TomlDecodeError as e:
print(e, file=sys.stderr)
print(fp, file=sys.stderr)
continue
if not cd.get("enable", True):
continue
if "entry" not in cd:
continue
cmd = [cd["entry"], "--config", str(fp)]
print(fp)
proc = subprocess.Popen(
cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL
)
print(f"PID: {proc.pid} - {' '.join(cmd)}")
__all__ = ["status"]
import json
import socket
import prettytable # type: ignore
import colorama # type: ignore
from colorama import Fore
import msgpack # type: ignore
from ._cache import read_daemon_cache
......@@ -22,8 +24,8 @@ def status():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((daemon.host, daemon.port))
s.sendall(b'{"jsonrpc":"2.0", "method": "busy", "id":"status"}')
ident = json.loads(s.recv(1024))
s.sendall(msgpack.packb({"ver": "1.0", "method": "busy", "id": "status"}))
ident = msgpack.unpackb(s.recv(1024))
out.add_row(
[
daemon.host,
......