Skip to content

Commit

Permalink
Merge branch 'release/v0.11.4'
Browse files Browse the repository at this point in the history
* release/v0.11.4: (28 commits)
  Bump version from 0.11.3 to 0.11.4
  add missing newsfragment
  mypy warn_unused_ignores=false as workaround
  lock
  Add missing newsfragment
  Fix empty json body issue
  Implement delete room API v2
  chore(pre-commit): update dependencies
  build(deps-dev): bump flake8-bugbear from 21.11.28 to 21.11.29
  build(deps): bump actions/setup-python from 2.3.0 to 2.3.1
  build(deps-dev): bump types-jinja2 from 2.11.8 to 2.11.9
  build(deps-dev): bump flake8-bugbear from 21.9.2 to 21.11.28
  build(deps-dev): bump types-paramiko from 2.8.1 to 2.8.2
  build(deps): bump paramiko from 2.8.0 to 2.8.1
  build(deps-dev): bump coverage from 6.1.2 to 6.2
  build(deps): bump sphinx from 4.3.0 to 4.3.1
  build(deps-dev): bump pylint from 2.11.1 to 2.12.1
  build(deps-dev): bump types-paramiko from 2.8.0 to 2.8.1
  build(deps): bump actions/cache from 2.1.6 to 2.1.7
  build(deps): bump snok/install-poetry from 1.2 to 1.3
  ...
  • Loading branch information
MichaelSasser committed Dec 1, 2021
2 parents b121faf + 7900536 commit 1d04506
Show file tree
Hide file tree
Showing 11 changed files with 387 additions and 227 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ jobs:
steps:
- uses: actions/[email protected]
- name: Set up Python 3.9
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2.3.1
with:
python-version: 3.9

- name: Install Poetry
uses: snok/install-poetry@v1.2
uses: snok/install-poetry@v1.3
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/[email protected].6
uses: actions/[email protected].7
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ jobs:
- name: Checkout code
uses: actions/[email protected]
- name: Set up Python 3.9
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2.3.1
with:
python-version: 3.9

- name: Install Poetry
uses: snok/install-poetry@v1.2
uses: snok/install-poetry@v1.3
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/[email protected].6
uses: actions/[email protected].7
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ jobs:
- name: Checkout code
uses: actions/[email protected]
- name: Set up Python 3.9
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2.3.1
with:
python-version: 3.9

- name: Install Poetry
uses: snok/install-poetry@v1.2
uses: snok/install-poetry@v1.3
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/[email protected].6
uses: actions/[email protected].7
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
Expand Down
27 changes: 13 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
# Checks for a common error of placing code before the docstring.
- id: check-docstring-first
# check-executables-have-shebangs
#- id: check-executables-have-shebangs
# - id: check-executables-have-shebangs
# Attempts to load all json files to verify syntax.
# - id: check-json
# Check for files that contain merge conflict strings.
Expand All @@ -54,23 +54,23 @@ repos:
# - id: double-quote-string-fixer (KEEP DISABLED)
# Makes sure files end in a newline and only a newline.
- id: end-of-file-fixer
exclude: '^CHANGELOG.rst'
exclude: "^CHANGELOG.rst"
# Removes "# -*- coding: utf-8 -*-" on the top of python files.
- id: fix-encoding-pragma
args: ['--remove']
args: ["--remove"]
# Sort the lines in specified files (defaults to alphabetical).
# - id: file-contents-sorter (KEEP DISABLED)
# Replaces or checks mixed line ending to LF.
- id: mixed-line-ending
args: ['--fix=lf']
args: ["--fix=lf"]
# Assert that files in tests/ match test*.py.
- id: name-tests-test
args: ['--django']
args: ["--django"]
# Protect specific branches from direct checkins.
- id: no-commit-to-branch
args:
- '-b master'
- '-p release/.*'
- "-b master"
- "-p release/.*"
# Checks that all your JSON files are pretty.
# - id: pretty-format-json
# args: ["--autofix"]
Expand Down Expand Up @@ -118,7 +118,7 @@ repos:

# format: black
- repo: https://github.com/ambv/black
rev: 21.10b0
rev: 21.11b1
hooks:
- id: black

Expand All @@ -127,14 +127,14 @@ repos:
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: ['flake8-bugbear']
additional_dependencies: ["flake8-bugbear"]

# check docstrings
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle
args: ['--ignore=D10,D21,D202']
args: ["--ignore=D10,D21,D202"]
additional_dependencies:
- toml

Expand All @@ -160,7 +160,7 @@ repos:

# vulture
- repo: https://github.com/jendrikseipp/vulture
rev: 'v2.3'
rev: "v2.3"
hooks:
- id: vulture

Expand All @@ -169,7 +169,7 @@ repos:
rev: v2.29.1
hooks:
- id: pyupgrade
exclude: docs/source/conf.py # Py3.8 needed by rtd
exclude: docs/source/conf.py

# pycln
- repo: https://github.com/hadialqattan/pycln
Expand All @@ -189,7 +189,6 @@ repos:
# - id: prospector
# PEP 585 Upgrade (Type Hints)
- repo: https://github.com/sondrelg/pep585-upgrade
# Use the sha / tag you want to point at
rev: v1
hooks:
- id: upgrade-type-hints
- id: upgrade-type-hints
25 changes: 25 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@ This is the changelog of MatrixCtl. You can find the issue tracker on

.. towncrier release notes start
0.11.4 (2021-12-01)
===================

Features & Improvements
-----------------------

- Update to *Delete Room API v2*. (`#305
<https://github.com/MichaelSasser/matrixctl/issues/305>`_)


Bugfixes
--------

- Fix a bug introduced in ``be411cf0c1a9413bf25ca1b72004150c032555c2``, after
the last release because the ``httpx`` typehints are incorrect. (`#307
<https://github.com/MichaelSasser/matrixctl/issues/307>`_)


Miscellaneous
-------------

- Fix incorrect typehints in the API handler (`#287
<https://github.com/MichaelSasser/matrixctl/issues/287>`_)


0.11.3 (2021-11-16)
===================

Expand Down
110 changes: 109 additions & 1 deletion matrixctl/addons/delroom/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import logging

from argparse import Namespace
from time import sleep

from matrixctl.errors import InternalResponseError
from matrixctl.handlers.api import RequestBuilder
Expand Down Expand Up @@ -62,7 +63,7 @@ def addon(arg: Namespace, yaml: YAML) -> int:
domain=yaml.get("server", "api", "domain"),
path=f"rooms/{arg.room}",
method="DELETE",
api_version="v1",
api_version="v2",
json=body,
timeout=1200,
)
Expand All @@ -79,11 +80,117 @@ def addon(arg: Namespace, yaml: YAML) -> int:
logger.fatal("The JSON response could not be loaded by MatrixCtl.")
raise InternalResponseError(f"The response was: {response = }") from e

try:
json_response = handle_status(yaml, json_response["delete_id"])
except InternalResponseError as e:
if e.message:
logger.fatal(e.message)
logger.fatal(
"MatrixCtl was not able to verify the status of the request."
)
return 1

print(json.dumps(json_response, indent=4))

return 0


def handle_status(yaml: YAML, delete_id: str) -> JsonDict: # noqa: C901
"""Handle the status of a delete room request.
Parameters
----------
yaml : matrixctl.handlers.yaml.YAML
The configuration file handler.
delete_id: str
The delete id of a delete room request.
Returns
-------
response: matrixctl.typehints.JsonDict, optional
The response as dict, containing the status.
"""
req: RequestBuilder = RequestBuilder(
token=yaml.get("server", "api", "token"),
domain=yaml.get("server", "api", "domain"),
path=f"rooms/delete_status/{delete_id}",
method="GET",
api_version="v2",
timeout=1200.0,
)

# Lock messages to only print them once
msglock_shutting_down: bool = False
msglock_purging: bool = False

while True:

sleep(1)
try:
response: Response = request(req)
except InternalResponseError as e:
raise InternalResponseError(
"The delete room request was probably successful but the"
" status request failed. You just have to wait a bit."
) from e

try:
json_response: JsonDict = response.json()
except json.decoder.JSONDecodeError as e:
logger.fatal(
"The JSON status response could not be loaded by MatrixCtl."
)
raise InternalResponseError(
f"The response was: {response = }"
) from e

if response is not None:
logger.debug(f"{response=}")
# complete
if json_response["status"] == "complete":
print(
"Status: Complete (the room has been deleted successfully"
)
break
# shutting_down
if json_response["status"] == "shutting_down":
if not msglock_shutting_down:
print(
"Status: Shutting Down (removing users from the room)"
)
msglock_shutting_down = True
logger.info(
"The server is still shutting_down the room. "
"Please wait..."
)
sleep(5)
continue
# purging
if json_response["status"] == "purging":
if not msglock_purging:
print(
"Status: Purging (purging the room and event data from"
" database)"
)
msglock_purging = True
logger.info(
"The server is still purging the room. Please wait..."
)
sleep(5)
continue
# failed
if json_response["status"] == "failed":
logger.critical(
"The server returned, that the approach failed with the"
f" following message: {json_response['status']}."
)
break
break

return json_response


def handle_arguments(arg: Namespace) -> JsonDict:
"""Build the parameters used for the delroom request.
Expand Down Expand Up @@ -113,6 +220,7 @@ def handle_arguments(arg: Namespace) -> JsonDict:
else:
body["message"] = arg.message

logger.debug("Body: %s", body)
return body


Expand Down
2 changes: 1 addition & 1 deletion matrixctl/addons/purge_history/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


def handle_purge_status(yaml: YAML, purge_id: str) -> int:
"""Check the status pf the purge history request.
"""Check the status of the purge history request.
Parameters
----------
Expand Down
3 changes: 2 additions & 1 deletion matrixctl/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
) -> None: # pylint: disable=keyword-arg-before-vararg
"""Use this error like a normal error in your day-to-day programming.
This is a commandline application. Therefor no user should ever see an
This is a commandline application. Therefore no user should ever see an
exception (except in debug-mode). This error informs the user that,
getting a traceback is a bug in this application. It gives the person
instructions, how to hand in a bug report, to contain them asap.
Expand All @@ -63,6 +63,7 @@ def __init__(
None
"""
self.message = message
self.payload: Any = payload
msg: str = self.__class__.BUGMSG

Expand Down
Loading

0 comments on commit 1d04506

Please sign in to comment.