Skip to content

Commit

Permalink
Merge pull request #138 from marksie1988/add_episode_monitor_endpoint
Browse files Browse the repository at this point in the history
feat: Add episode/book monitor endpoint
  • Loading branch information
marksie1988 authored Apr 15, 2023
2 parents 581b692 + d337403 commit af27338
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 97 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/docker-compose.workspace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---

version: '3'
services:
pyarr-workspace:
build:
context: .
dockerfile: Dockerfile
container_name: pyarr-workspace
volumes:
- type: bind
source: ${HOME}/.ssh
target: /home/vscode/.ssh
consistency: cached
- type: bind
source: ${HOME}/.gitconfig
target: /home/vscode/.gitconfig
consistency: cached
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
command: sleep infinity
14 changes: 14 additions & 0 deletions .devcontainer/post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -ex

# Convenience workspace directory for later use
WORKSPACE_DIR=$(pwd)

# Change some Poetry settings to better deal with working in a container
poetry config cache-dir ${WORKSPACE_DIR}/.cache

# Now install all dependencies
poetry install
poetry run pre-commit install -t pre-commit -t commit-msg

echo "Done!"
25 changes: 11 additions & 14 deletions .devcontainer/recommended-devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"name": "pyarr",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
// Options
//"POETRY_VERSION": "1.2.2",
//"NOX_VERSION": "2022.11.21"
}
},
"dockerComposeFile": [
"docker-compose.workspace.yml"
],
"service": "pyarr-workspace",
"workspaceFolder": "/workspace",
"forwardPorts": [
"sonarr:8989",
"radarr:7878",
Expand Down Expand Up @@ -48,17 +44,18 @@
}
},
"features": {
"docker-in-docker": "latest",
"git": "latest"
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {}
},
"remoteUser": "vscode",
"postCreateCommand": "zsh ./.devcontainer/post-install.sh",
"mounts": [
// Re-use local SSH keys (useful if you use SSH keys for Git repo access or other SSH work)
"source=${localEnv:HOME}/repos/pyarrfork,target=/workspace,type=bind,consistency=cached",
/* Re-use local SSH keys (useful if you use SSH keys for Git repo access or other SSH work)*/
"source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached",
// Re-use local Git configuration
/* Re-use local Git configuration*/
"source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig,type=bind,consistency=cached",
// map docker socket of host
/* map docker socket of host*/
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
]
}
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[flake8]
max-line-length = 88
max-complexity = 18
exclude = build/*, tests/*, .nox/*
exclude = build/*, tests/*, .nox/*, .cache/*
extend-ignore =
# See https://github.com/PyCQA/pycodestyle/issues/373
E203,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ _build
!.devcontainer/Dockerfile
!.devcontainer/recommended-docker-compose.yml
!.devcontainer/docker-compose.workspace.yml
!.devcontainer/post-install.sh

tests/docker_configs/sonarr/*
!tests/docker_configs/sonarr/config.xml
Expand Down
16 changes: 10 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def docker_test(session: Session) -> None:
@nox.session(reuse_venv=True)
def test_create_containers(session: Session) -> None:
session.run(
"sudo",
"docker",
"compose",
"-f",
Expand All @@ -49,6 +50,7 @@ def test_create_containers(session: Session) -> None:
)
hostname = subprocess.check_output(["hostname"]).strip().decode("utf-8")
inspect_command = [
"sudo",
"docker",
"inspect",
"--format",
Expand All @@ -58,6 +60,7 @@ def test_create_containers(session: Session) -> None:
project_name = subprocess.check_output(inspect_command).strip().decode("utf-8")

session.run(
"sudo",
"docker",
"compose",
"--project-name",
Expand All @@ -75,6 +78,7 @@ def test_cleanup_containers(session: Session) -> None:
# Get the container IDs using the filter
hostname = subprocess.check_output(["hostname"]).strip().decode("utf-8")
project_name_command = [
"sudo",
"docker",
"inspect",
"--format",
Expand All @@ -85,7 +89,7 @@ def test_cleanup_containers(session: Session) -> None:
container_filter = f"label=com.docker.compose.project={project_name}"

# Execute the `docker ps` command and filter the output using grep
cmd1 = ["docker", "ps", "-a", "-q", "--filter", container_filter]
cmd1 = ["sudo", "docker", "ps", "-a", "-q", "--filter", container_filter]
cmd2 = ["grep", "-v", hostname]
output1 = subprocess.run(cmd1, stdout=subprocess.PIPE)
output2 = subprocess.run(cmd2, input=output1.stdout, stdout=subprocess.PIPE)
Expand All @@ -96,8 +100,8 @@ def test_cleanup_containers(session: Session) -> None:
# Kill and remove the containers, cant use docker compose down as that kills
# the workspace container for devcontainer. this works just as well.
for container_id in container_ids:
session.run("docker", "kill", container_id, silent=True, external=True)
session.run("docker", "rm", container_id, silent=True, external=True)
session.run("sudo", "docker", "kill", container_id, silent=True, external=True)
session.run("sudo", "docker", "rm", container_id, silent=True, external=True)


@nox.session(reuse_venv=True)
Expand Down Expand Up @@ -134,11 +138,11 @@ def test_style(session: Session) -> None:
session.run("flake8", "pyarr", "tests")
session.run(
"black",
".",
"pyarr",
"--check",
)
session.run("isort", ".", "--check-only")
session.run("autoflake", ".")
session.run("isort", "pyarr", "--check-only")
session.run("autoflake", "-r", "pyarr")
session.run("interrogate", "pyarr")


Expand Down
19 changes: 19 additions & 0 deletions pyarr/readarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,25 @@ def upd_book(self, id_: int, data: JsonObject) -> JsonObject:
"""
return self._put(f"book/{id_}", self.ver_uri, data=data)

# PUT /book/monitor
def upd_book_monitor(
self, book_ids: list[int], monitored: bool = True
) -> JsonArray:
"""Update book monitored status
Args:
book_ids (list[int]): All book IDs to be updated
monitored (bool, optional): True or False. Defaults to True.
Returns:
JsonArray: list of dictionaries containing updated records
"""
return self._put(
"book/monitor",
self.ver_uri,
data={"bookIds": book_ids, "monitored": monitored},
)

# DELETE /book/{id}
def del_book(
self,
Expand Down
19 changes: 19 additions & 0 deletions pyarr/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ def upd_episode(self, id_: int, data: JsonObject) -> JsonObject:
"""
return self._put(f"episode/{id_}", self.ver_uri, data=data)

# PUT /episode/monitor
def upd_episode_monitor(
self, episode_ids: list[int], monitored: bool = True
) -> JsonArray:
"""Update episode monitored status
Args:
episode_ids (list[int]): All episode IDs to be updated
monitored (bool, optional): True or False. Defaults to True.
Returns:
JsonArray: list of dictionaries containing updated records
"""
return self._put(
"episode/monitor",
self.ver_uri,
data={"episodeIds": episode_ids, "monitored": monitored},
)

## EPISODE FILE

# GET /episodefile
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ exclude = '''
| \.tox
| \.nox
| \.venv
| \.cache
| _build
| buck-out
| build
Expand Down Expand Up @@ -96,6 +97,7 @@ known_first_party = [
forced_separate = [
"tests",
]
skip = [".cache", ".nox"]
combine_as_imports = true

[tool.autoflake]
Expand All @@ -116,7 +118,7 @@ ignore-nested-functions = false
ignore-nested-classes = true
ignore-setters = false
fail-under = 100
exclude = ["setup.py", "sphinx-docs", "build", ".devcontainer", ".nox"]
exclude = ["setup.py", "sphinx-docs", "build", ".devcontainer", ".nox", ".cache"]
ignore-regex = ["^get$", "^mock_.*", ".*BaseClass.*"]
verbose = 0
quiet = false
Expand Down
6 changes: 4 additions & 2 deletions sphinx-docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Setup your environment

#. Fork the `repository <https://github.com/totaldebug/pyarr>`_
#. Open the repository in VSCode
#. Copy the ``.devcontainer/recommended-***`` files and remove the "recommended-" text
#. Update the renamed ``recommended-***`` files to suite your environment
#. Copy the ``.devcontainer/recommended-devcontainer.json`` files and rename the copy to ``devcontainer.json``.
#. Modify the ``mounts`` section as required for your environment
#. Copy the ``.devcontainer/recommended-docker-compose.yml`` files and rename the copy to ``docker.compose.yml``
#. You may need to modify the ``volumes`` for your environment
#. Press ``ctrl + shift + p`` and select ``Remote-Container: Reopen in Container``
#. Once loaded you can begin modification of the module or Documentation

Expand Down
Loading

0 comments on commit af27338

Please sign in to comment.