refactor smal => mxsmal

This commit is contained in:
saces 2026-04-04 15:07:31 +02:00
parent 3f6be78685
commit 7e984ef129
37 changed files with 142 additions and 72 deletions

View file

@ -156,7 +156,7 @@ jobs:
env:
SOURCE_DATE_EPOCH: ${{ needs.timestamp.outputs.sepoch }}
run: |
cd smal/
cd mxsmal/
pip install build
python -m build --sdist
pip install ./dist/*.tar.gz
@ -165,7 +165,7 @@ jobs:
uses: actions/upload-artifact@v7
with:
name: smal-${{ github.sha }}-sdist.zip
path: ./smal/dist/*.tar.gz
path: ./mxsmal/dist/*.tar.gz
smal-wheel:
@ -183,7 +183,7 @@ jobs:
env:
SOURCE_DATE_EPOCH: ${{ needs.timestamp.outputs.sepoch }}
run: |
cd smal/
cd mxsmal/
pip install build
python -m build --wheel
pip install ./dist/*.whl
@ -192,7 +192,7 @@ jobs:
uses: actions/upload-artifact@v7
with:
name: smal-${{ github.sha }}-wheel.zip
path: ./smal/dist/*.whl
path: ./mxsmal/dist/*.whl
smal-pypi:

View file

@ -49,8 +49,8 @@ EOF
RUN --mount=type=bind,from=pybuilder,source=/pygomx-wheel,target=/pygomx-wheel pip install /pygomx-wheel/*.whl
FROM develop AS demobot
WORKDIR /smal
COPY smal /smal
WORKDIR /mxsmal
COPY mxsmal /mxsmal
RUN pip install .
WORKDIR /demobot

View file

@ -19,11 +19,8 @@ the bot follows each invite (autojoin) and have two commands:
binary/package install:
(only linux-amd64 for now)
pip install --index-url https://codeberg.org/api/packages/saces/pypi/simple/ --no-deps pygomx
pip install git+https://codeberg.org/saces/pygomx.git#subdirectory=pygomx-deps
pip install git+https://codeberg.org/saces/pygomx.git#subdirectory=smal
pip install pygomx
pip install mxsmal
install from source / develop (venv):
@ -45,7 +42,7 @@ install from source / develop (venv):
cd pygomx
pip install .
cd ../smal
cd ../mxsmal
pip install [-e] .
usage:

View file

@ -4,9 +4,9 @@ services:
context: .
dockerfile: Containerfile.debian
target: develop
working_dir: /smal
working_dir: /mxsmal
volumes:
- ./smal:/smal:ro
- ./mxsmal:/mxsmal:ro
- ./work:/work
demobot:

View file

@ -4,7 +4,7 @@ Simple Matrix Application Library
sub libs:
- pymxutils: matrix cli utils
- smal: the lib itself
- mxsmal: the lib itself
- smbl: simplematrixbotlib compat layer experiments (if any)
- demobot: simple demo bot

View file

@ -24,7 +24,7 @@ dependencies = [
[tool.setuptools.package-dir]
"pymxutils" = "src/pymxutils"
"mxsmal" = "src/smal"
"mxsmal" = "src/mxsmal"
"smbl" = "src/smbl"
"demobot" = "src/demobot"
@ -40,6 +40,6 @@ mxlogout = "pymxutils.mxutils:logout"
mxclearaccount = "pymxutils.mxutils:clearaccount"
mxserverinfo = "pymxutils.mxutils:serverinfo"
mxpassitem = "pymxutils.mxutils:passitem"
smalsetup = "smal.smalsetup:smalsetup"
smalsetup = "mxsmal.smalsetup:smalsetup"
demobot = "demobot:main"
simplebot = "demobot.simple:main"

View file

@ -1,7 +1,7 @@
# Copyright (C) 2026 saces@c-base.org
# SPDX-License-Identifier: AGPL-3.0-only
import logging
from smal.bot import SMALBot
from mxsmal.bot import SMALBot
# setup logging, we want timestamps
logging.basicConfig(

View file

@ -1,7 +1,7 @@
# Copyright (C) 2026 saces@c-base.org
# SPDX-License-Identifier: AGPL-3.0-only
import logging
from smal.simple.bot import SMALBot
from mxsmal.simple.bot import SMALBot
# setup logging, we want timestamps
logging.basicConfig(

View file

@ -0,0 +1,29 @@
# Copyright (C) 2026 saces@c-base.org
# SPDX-License-Identifier: AGPL-3.0-only
import click
import json
from _pygomx import lib, ffi
@click.command()
@click.option("-u", "--url", "hs_url", metavar="url", help="homeserver url")
@click.option("-t", "--token", "token", metavar="token", help="access token")
def accountinfo(hs_url, token):
"""print info about this account devices"""
if hs_url is None and token is None:
r = lib.cliv0_mxpassitem(b".mxpass", b"*", b"*", b"*")
result = ffi.string(r).decode("utf-8")
lib.FreeCString(r)
result_dict = json.loads(result)
hs_url = result_dict["Matrixhost"]
token = result_dict["Token"]
r = lib.cliv0_accountinfo(
hs_url.encode(encoding="utf-8"), token.encode(encoding="utf-8")
)
result = ffi.string(r)
lib.FreeCString(r)
print(result.decode("utf-8"))

View file

@ -0,0 +1,75 @@
# Copyright (C) 2026 saces@c-base.org
# SPDX-License-Identifier: AGPL-3.0-only
import click
import json
from _pygomx import lib, ffi
@click.group()
@click.option("-u", "--url", "hs_url", metavar="url", help="homeserver url")
@click.option("-t", "--token", "token", metavar="token", help="access token")
def clearaccount(hs_url, token):
"""remove various things from account"""
global _hs_url
global _token
if hs_url is None and token is None:
r = lib.cliv0_mxpassitem(b".mxpass", b"*", b"*", b"*")
result = ffi.string(r).decode("utf-8")
lib.FreeCString(r)
result_dict = json.loads(result)
_hs_url = result_dict["Matrixhost"]
_token = result_dict["Token"]
else:
_hs_url = hs_url
_token = token
r = lib.cliv0_accountinfo(
_hs_url.encode(encoding="utf-8"), _token.encode(encoding="utf-8")
)
result = ffi.string(r)
lib.FreeCString(r)
print(result.decode("utf-8"))
# r = lib.cliv0_clearaccount(hs_url, token)
# result = ffi.string(r)
# lib.FreeCString(r)
# print(result)
@clearaccount.group()
def logout(ctx):
"""Logout devices"""
pass
@logout.command("others")
def logout_others():
"""Logout all other devices"""
pass
@logout.command("all")
def logout_all():
"""Logout all devices"""
pass
@logout.command("self")
def logout_self():
"""Logout this device"""
pass
@clearaccount.command()
def sub1():
"""sub1"""
pass
@clearaccount.command()
def sub2():
"""sub2"""
pass

View file

@ -0,0 +1,22 @@
# Copyright (C) 2026 saces@c-base.org
# SPDX-License-Identifier: AGPL-3.0-only
import sys
import click
from _pygomx import ffi, lib
@click.command()
@click.option(
"--json", "show_json", is_flag=True, help="show json as returned from server."
)
@click.argument("domain", metavar="string")
def serverinfo(domain, show_json):
"""show server info for given server (federationstester light)"""
mxdomain = sys.argv[1].encode(encoding="utf-8")
r = lib.cliv0_serverinfo(mxdomain)
result = ffi.string(r).decode("utf-8")
lib.FreeCString(r)
print(result)

View file

@ -1,18 +0,0 @@
# Copyright (C) 2026 saces@c-base.org
# SPDX-License-Identifier: AGPL-3.0-only
import sys
from _pygomx import lib, ffi
def accountinfo():
if len(sys.argv) != 3:
print("usage: ", sys.argv[0], " url acesstoken")
return 1
url = sys.argv[1].encode(encoding="utf-8")
tk = sys.argv[2].encode(encoding="utf-8")
r = lib.cliv0_accountinfo(url, tk)
result = ffi.string(r)
lib.FreeCString(r)
print(result)

View file

@ -1,18 +0,0 @@
# Copyright (C) 2026 saces@c-base.org
# SPDX-License-Identifier: AGPL-3.0-only
import sys
from _pygomx import lib, ffi
def clearaccount():
if len(sys.argv) != 3:
print("usage: ", sys.argv[0], " url accesstoken")
return 1
url = sys.argv[1].encode(encoding="utf-8")
tk = sys.argv[2].encode(encoding="utf-8")
r = lib.cliv0_clearaccount(url, tk)
result = ffi.string(r)
lib.FreeCString(r)
print(result)

View file

@ -1,17 +0,0 @@
# Copyright (C) 2026 saces@c-base.org
# SPDX-License-Identifier: AGPL-3.0-only
import sys
from _pygomx import lib, ffi
def serverinfo():
if len(sys.argv) != 2:
print("usage: ", sys.argv[0], " url|domainname")
return 1
mxdomain = sys.argv[1].encode(encoding="utf-8")
r = lib.cliv0_serverinfo(mxdomain)
result = ffi.string(r).decode("utf-8")
lib.FreeCString(r)
print(result)