Skip to content

Commit

Permalink
nc_app: implemented verify_version
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 committed Sep 28, 2023
1 parent fe10135 commit 10b1b9e
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 28 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file.

## [0.3.0 - 2023-09-28]

### Added

- NextcloudApp: The `ex_app.verify_version` function to simply check whether the application has been updated.

### Changed

- NextcloudApp: Updated `info.xml` in examples to reflect upcoming changes in the [AppStore](https://github.com/nextcloud/appstore/pull/1145)

## [0.2.2 - 2023-09-26]

### Added
Expand Down
8 changes: 5 additions & 3 deletions docs/reference/ExApp.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. py:currentmodule:: nc_py_api.ex_app
External Application
====================
AppAPI Application
==================

Constants
---------
Expand All @@ -17,6 +17,8 @@ Special functions

.. autofunction:: persistent_storage

.. autofunction:: verify_version

User Interface(UI)
------------------

Expand All @@ -26,7 +28,7 @@ UI methods should be accessed with the help of :class:`~nc_py_api.nextcloud.Next
# this is an example, in most cases you will get `NextcloudApp` class instance as input param.
nc = NextcloudApp()
nc.ui.files_dropdown_menu.register(...)
nc.ex_app.ui.files_dropdown_menu.register(...)
.. autoclass:: nc_py_api.ex_app.ui.ui.UiApi
:members:
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/Nextcloud.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Nextcloud
=========

Two base classes for working with NextCloud. The first for working as a client, the second as an application.
Two base classes for working with Nextcloud. The first for working as a client, the second as an application.

All required functionality is incorporated in them, they contains all other classes required to work with the Nextcloud.

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Reference
:maxdepth: 2

Nextcloud
ExApp
Apps
ActivityApp
Files/index.rst
Users/index.rst
ExApp
Exceptions
Talk
TalkBot
Expand Down
6 changes: 3 additions & 3 deletions examples/as_app/skeleton/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependencies>
<nextcloud min-version="27" max-version="28"/>
</dependencies>
<ex-app>
<external-app>
<docker-install>
<registry>ghcr.io</registry>
<image>cloud-py-api/skeleton</image>
Expand All @@ -31,6 +31,6 @@
</optional>
</scopes>
<protocol>http</protocol>
<system>0</system>
</ex-app>
<system>false</system>
</external-app>
</info>
2 changes: 1 addition & 1 deletion examples/as_app/skeleton/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nc_py_api[app]>=0.2.0
nc_py_api[app]>=0.3.0
6 changes: 3 additions & 3 deletions examples/as_app/talk_bot/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependencies>
<nextcloud min-version="27" max-version="28"/>
</dependencies>
<ex-app>
<external-app>
<docker-install>
<registry>ghcr.io</registry>
<image>cloud-py-api/talk_bot</image>
Expand All @@ -33,6 +33,6 @@
</optional>
</scopes>
<protocol>http</protocol>
<system>0</system>
</ex-app>
<system>false</system>
</external-app>
</info>
2 changes: 1 addition & 1 deletion examples/as_app/talk_bot/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nc_py_api[app]>=0.2.0
nc_py_api[app]>=0.3.0
6 changes: 3 additions & 3 deletions examples/as_app/talk_bot_ai/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependencies>
<nextcloud min-version="27" max-version="28"/>
</dependencies>
<ex-app>
<external-app>
<docker-install>
<registry>ghcr.io</registry>
<image>cloud-py-api/talk_bot_ai</image>
Expand All @@ -33,6 +33,6 @@
</optional>
</scopes>
<protocol>http</protocol>
<system>0</system>
</ex-app>
<system>false</system>
</external-app>
</info>
2 changes: 1 addition & 1 deletion examples/as_app/talk_bot_ai/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nc_py_api[app]>=0.2.1
nc_py_api[app]>=0.3.0
transformers>=4.33
torch
torchvision
Expand Down
6 changes: 3 additions & 3 deletions examples/as_app/talk_bot_multi/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependencies>
<nextcloud min-version="27" max-version="28"/>
</dependencies>
<ex-app>
<external-app>
<docker-install>
<registry>ghcr.io</registry>
<image>cloud-py-api/talk_bot_multi</image>
Expand All @@ -33,6 +33,6 @@
</optional>
</scopes>
<protocol>http</protocol>
<system>0</system>
</ex-app>
<system>false</system>
</external-app>
</info>
2 changes: 1 addition & 1 deletion examples/as_app/talk_bot_multi/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nc_py_api[app]>=0.2.0
nc_py_api[app]>=0.3.0
6 changes: 3 additions & 3 deletions examples/as_app/to_gif/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependencies>
<nextcloud min-version="27" max-version="28"/>
</dependencies>
<ex-app>
<external-app>
<docker-install>
<registry>ghcr.io</registry>
<image>cloud-py-api/to_gif</image>
Expand All @@ -33,6 +33,6 @@
</optional>
</scopes>
<protocol>http</protocol>
<system>0</system>
</ex-app>
<system>false</system>
</external-app>
</info>
2 changes: 1 addition & 1 deletion examples/as_app/to_gif/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nc_py_api[app]>=0.2.0
nc_py_api[app]>=0.3.0
pygifsicle
imageio
opencv-python
Expand Down
2 changes: 1 addition & 1 deletion nc_py_api/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version of nc_py_api."""

__version__ = "0.2.2"
__version__ = "0.3.0.dev0"
2 changes: 1 addition & 1 deletion nc_py_api/ex_app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""All possible ExApp stuff for NextcloudApp that can be used."""
from .defs import ApiScope, LogLvl
from .integration_fastapi import nc_app, set_handlers, talk_bot_app
from .misc import persistent_storage
from .misc import persistent_storage, verify_version
from .ui.files import UiActionFileInfo, UiFileActionHandlerInfo
from .uvicorn_fastapi import run_app
21 changes: 21 additions & 0 deletions nc_py_api/ex_app/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Different miscellaneous optimization/helper functions for the Nextcloud Applications."""

import os
import typing
from sys import platform


Expand All @@ -23,3 +24,23 @@ def _get_app_cache_dir() -> str:
r = os.path.join(root_cache_path, os.environ["APP_ID"])
os.makedirs(r, exist_ok=True)
return r


def verify_version(finalize_update: bool = True) -> typing.Optional[tuple[str, str]]:
"""Returns tuple with an old version and new version or ``None`` if there was no update taken.
:param finalize_update: Flag indicating whether update information should be updated.
If ``True``, all subsequent calls to this function will return that there is no update.
"""
version_file_path = os.path.join(persistent_storage(), "_version.info")
r = None
with open(version_file_path, "a+t", encoding="UTF-8") as version_file:
version_file.seek(0)
old_version = version_file.read()
if old_version != os.environ["APP_VERSION"]:
r = (old_version, os.environ["APP_VERSION"])
if finalize_update:
version_file.seek(0)
version_file.write(os.environ["APP_VERSION"])
version_file.truncate()
return r
19 changes: 18 additions & 1 deletion tests/actual_tests/misc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from nc_py_api import NextcloudException
from nc_py_api import NextcloudException, ex_app
from nc_py_api._deffered_error import DeferredError # noqa
from nc_py_api._exceptions import check_error # noqa
from nc_py_api._misc import nc_iso_time_to_datetime, require_capabilities # noqa
Expand Down Expand Up @@ -74,3 +74,20 @@ def test_persist_transformers_cache(nc_app):
from nc_py_api.ex_app import persist_transformers_cache # noqa

assert os.environ["TRANSFORMERS_CACHE"]
os.environ.pop("TRANSFORMERS_CACHE")


def test_verify_version(nc_app):
version_file_path = os.path.join(ex_app.persistent_storage(), "_version.info")
if os.path.exists(version_file_path):
os.remove(version_file_path)
r = ex_app.verify_version(False)
assert not os.path.getsize(version_file_path)
assert isinstance(r, tuple)
assert r[0] == ""
assert r[1] == os.environ["APP_VERSION"]
r = ex_app.verify_version(True)
assert os.path.getsize(version_file_path)
assert r[0] == ""
assert r[1] == os.environ["APP_VERSION"]
assert ex_app.verify_version() is None

0 comments on commit 10b1b9e

Please sign in to comment.