Skip to content

Commit

Permalink
add server-version command
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Dec 22, 2023
1 parent 874e082 commit ce3647c
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 9 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ interpreter. In order to install `pip` on Ubuntu use following command:

$ sudo apt install python3-pip


## REST API/CLI Version Compatibility

REST API column - is version of Papermerge REST API server. This value
you can get from:

$ papermerge-cli --server-version

CLI column - is version of papermege-cli command line utility. This value
you can get from:

$ papermerge-cli --version


| REST API | CLI |
|----------|------|
| =3.0 | =0.7 |
| =2.1 | = 0.3.3|

## Usage

Get you REST API authentication token from your instance:
Expand Down
13 changes: 6 additions & 7 deletions papermerge_cli/lib/nodes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import uuid
from typing import List

from papermerge_cli.rest import (get_me, get_nodes, node_add_tags,
node_assign_tags, node_remove_tags)
from papermerge_cli import rest
from papermerge_cli.schema import Node, Paginator, User
from papermerge_cli.types import NodeActionEnum

Expand All @@ -17,7 +16,7 @@ def list_nodes(
order_by: str = '-title'
) -> Paginator[Node]:

user: User = get_me(host=host, token=token)
user: User = rest.get_me(host=host, token=token)

if parent_id is None:
# in case no specific parent uuid is requested
Expand All @@ -37,7 +36,7 @@ def list_nodes(
'order_by': order_by
}

data: Paginator[Node] = get_nodes(
data: Paginator[Node] = rest.get_nodes(
node_id=node_id,
host=host,
token=token,
Expand All @@ -56,21 +55,21 @@ def perform_node_command(
tags: List[str]
):
if action in (NodeActionEnum.assign_tags, NodeActionEnum.replace_tags):
node_assign_tags(
rest.node_assign_tags(
host=host,
token=token,
node_id=node_id,
tags=tags
)
elif action in (NodeActionEnum.add_tags, NodeActionEnum.append_tags):
node_add_tags(
rest.node_add_tags(
host=host,
token=token,
node_id=node_id,
tags=tags
)
elif action in (NodeActionEnum.remove_tags, NodeActionEnum.delete_tags):
node_remove_tags(
rest.node_remove_tags(
host=host,
token=token,
node_id=node_id,
Expand Down
8 changes: 8 additions & 0 deletions papermerge_cli/lib/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from papermerge_cli import rest


def perform_server_version_command(
host: str,
token: str
):
return rest.get_server_version(host=host, token=token)
12 changes: 12 additions & 0 deletions papermerge_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from papermerge_cli.lib.importer import upload_file_or_folder
from papermerge_cli.lib.nodes import list_nodes, perform_node_command
from papermerge_cli.lib.users import me as perform_me
from papermerge_cli.lib.version import perform_server_version_command
from papermerge_cli.schema import Node, Paginator, User
from papermerge_cli.types import NodeActionEnum

Expand Down Expand Up @@ -217,6 +218,17 @@ def node_command(
)


@app.command(name="server-version")
def server_version_command(ctx: typer.Context):
"""Get REST API version used on server side"""
output = perform_server_version_command(
host=ctx.obj['HOST'],
token=ctx.obj['TOKEN'],
)

console.print(output)


"""
@click.command
@click.option(
Expand Down
4 changes: 3 additions & 1 deletion papermerge_cli/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .nodes import (create_folder, get_nodes, node_add_tags, node_assign_tags,
node_remove_tags)
from .users import get_me
from .version import get_server_version

__all__ = [
get_me,
Expand All @@ -10,5 +11,6 @@
node_remove_tags,
node_assign_tags,
upload_document,
create_folder
create_folder,
get_server_version
]
16 changes: 16 additions & 0 deletions papermerge_cli/rest/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from papermerge_cli.api_client import ApiClient
from papermerge_cli.schema.version import Version
from papermerge_cli.utils import host_required, token_required


@host_required
@token_required
def get_server_version(
host: str,
token: str
) -> Version:
"""Returns current user instance"""
api_client = ApiClient[Version](token=token, host=host)
version = api_client.get('/api/version/', response_model=Version)

return version
5 changes: 5 additions & 0 deletions papermerge_cli/schema/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pydantic import BaseModel


class Version(BaseModel):
version: str
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "papermerge-cli"
version = "0.6.0"
version = "0.7.0"
description = "Command line utility for your Papermerge DMS instance"
authors = ["Eugen Ciur <[email protected]>"]
license = "Apache 2.0"
Expand Down

0 comments on commit ce3647c

Please sign in to comment.