Skip to content

Commit 734f4fa

Browse files
authored
Preparing AppStore support (#134)
### 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](nextcloud/appstore#1145) --- Hopefully, starting from this version there will be availability to upload applications into the AppStore(will be in beta stage) Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent fe10135 commit 734f4fa

File tree

18 files changed

+78
-28
lines changed

18 files changed

+78
-28
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

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

5+
## [0.3.0 - 2023-09-28]
6+
7+
### Added
8+
9+
- NextcloudApp: The `ex_app.verify_version` function to simply check whether the application has been updated.
10+
11+
### Changed
12+
13+
- NextcloudApp: Updated `info.xml` in examples to reflect upcoming changes in the [AppStore](https://github.com/nextcloud/appstore/pull/1145)
14+
515
## [0.2.2 - 2023-09-26]
616

717
### Added

docs/reference/ExApp.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. py:currentmodule:: nc_py_api.ex_app
22
3-
External Application
4-
====================
3+
AppAPI Application
4+
==================
55

66
Constants
77
---------
@@ -17,6 +17,8 @@ Special functions
1717

1818
.. autofunction:: persistent_storage
1919

20+
.. autofunction:: verify_version
21+
2022
User Interface(UI)
2123
------------------
2224

@@ -26,7 +28,7 @@ UI methods should be accessed with the help of :class:`~nc_py_api.nextcloud.Next
2628
2729
# this is an example, in most cases you will get `NextcloudApp` class instance as input param.
2830
nc = NextcloudApp()
29-
nc.ui.files_dropdown_menu.register(...)
31+
nc.ex_app.ui.files_dropdown_menu.register(...)
3032
3133
.. autoclass:: nc_py_api.ex_app.ui.ui.UiApi
3234
:members:

docs/reference/Nextcloud.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Nextcloud
44
=========
55

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

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

docs/reference/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ Reference
55
:maxdepth: 2
66

77
Nextcloud
8+
ExApp
89
Apps
910
ActivityApp
1011
Files/index.rst
1112
Users/index.rst
12-
ExApp
1313
Exceptions
1414
Talk
1515
TalkBot

examples/as_app/skeleton/appinfo/info.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<dependencies>
1919
<nextcloud min-version="27" max-version="28"/>
2020
</dependencies>
21-
<ex-app>
21+
<external-app>
2222
<docker-install>
2323
<registry>ghcr.io</registry>
2424
<image>cloud-py-api/skeleton</image>
@@ -31,6 +31,6 @@
3131
</optional>
3232
</scopes>
3333
<protocol>http</protocol>
34-
<system>0</system>
35-
</ex-app>
34+
<system>false</system>
35+
</external-app>
3636
</info>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nc_py_api[app]>=0.2.0
1+
nc_py_api[app]>=0.3.0

examples/as_app/talk_bot/appinfo/info.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<dependencies>
1919
<nextcloud min-version="27" max-version="28"/>
2020
</dependencies>
21-
<ex-app>
21+
<external-app>
2222
<docker-install>
2323
<registry>ghcr.io</registry>
2424
<image>cloud-py-api/talk_bot</image>
@@ -33,6 +33,6 @@
3333
</optional>
3434
</scopes>
3535
<protocol>http</protocol>
36-
<system>0</system>
37-
</ex-app>
36+
<system>false</system>
37+
</external-app>
3838
</info>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nc_py_api[app]>=0.2.0
1+
nc_py_api[app]>=0.3.0

examples/as_app/talk_bot_ai/appinfo/info.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<dependencies>
1919
<nextcloud min-version="27" max-version="28"/>
2020
</dependencies>
21-
<ex-app>
21+
<external-app>
2222
<docker-install>
2323
<registry>ghcr.io</registry>
2424
<image>cloud-py-api/talk_bot_ai</image>
@@ -33,6 +33,6 @@
3333
</optional>
3434
</scopes>
3535
<protocol>http</protocol>
36-
<system>0</system>
37-
</ex-app>
36+
<system>false</system>
37+
</external-app>
3838
</info>

examples/as_app/talk_bot_ai/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
nc_py_api[app]>=0.2.1
1+
nc_py_api[app]>=0.3.0
22
transformers>=4.33
33
torch
44
torchvision

examples/as_app/talk_bot_multi/appinfo/info.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<dependencies>
1919
<nextcloud min-version="27" max-version="28"/>
2020
</dependencies>
21-
<ex-app>
21+
<external-app>
2222
<docker-install>
2323
<registry>ghcr.io</registry>
2424
<image>cloud-py-api/talk_bot_multi</image>
@@ -33,6 +33,6 @@
3333
</optional>
3434
</scopes>
3535
<protocol>http</protocol>
36-
<system>0</system>
37-
</ex-app>
36+
<system>false</system>
37+
</external-app>
3838
</info>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nc_py_api[app]>=0.2.0
1+
nc_py_api[app]>=0.3.0

examples/as_app/to_gif/appinfo/info.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<dependencies>
1919
<nextcloud min-version="27" max-version="28"/>
2020
</dependencies>
21-
<ex-app>
21+
<external-app>
2222
<docker-install>
2323
<registry>ghcr.io</registry>
2424
<image>cloud-py-api/to_gif</image>
@@ -33,6 +33,6 @@
3333
</optional>
3434
</scopes>
3535
<protocol>http</protocol>
36-
<system>0</system>
37-
</ex-app>
36+
<system>false</system>
37+
</external-app>
3838
</info>

examples/as_app/to_gif/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
nc_py_api[app]>=0.2.0
1+
nc_py_api[app]>=0.3.0
22
pygifsicle
33
imageio
44
opencv-python

nc_py_api/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Version of nc_py_api."""
22

3-
__version__ = "0.2.2"
3+
__version__ = "0.3.0.dev0"

nc_py_api/ex_app/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""All possible ExApp stuff for NextcloudApp that can be used."""
22
from .defs import ApiScope, LogLvl
33
from .integration_fastapi import nc_app, set_handlers, talk_bot_app
4-
from .misc import persistent_storage
4+
from .misc import persistent_storage, verify_version
55
from .ui.files import UiActionFileInfo, UiFileActionHandlerInfo
66
from .uvicorn_fastapi import run_app

nc_py_api/ex_app/misc.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Different miscellaneous optimization/helper functions for the Nextcloud Applications."""
22

33
import os
4+
import typing
45
from sys import platform
56

67

@@ -23,3 +24,23 @@ def _get_app_cache_dir() -> str:
2324
r = os.path.join(root_cache_path, os.environ["APP_ID"])
2425
os.makedirs(r, exist_ok=True)
2526
return r
27+
28+
29+
def verify_version(finalize_update: bool = True) -> typing.Optional[tuple[str, str]]:
30+
"""Returns tuple with an old version and new version or ``None`` if there was no update taken.
31+
32+
:param finalize_update: Flag indicating whether update information should be updated.
33+
If ``True``, all subsequent calls to this function will return that there is no update.
34+
"""
35+
version_file_path = os.path.join(persistent_storage(), "_version.info")
36+
r = None
37+
with open(version_file_path, "a+t", encoding="UTF-8") as version_file:
38+
version_file.seek(0)
39+
old_version = version_file.read()
40+
if old_version != os.environ["APP_VERSION"]:
41+
r = (old_version, os.environ["APP_VERSION"])
42+
if finalize_update:
43+
version_file.seek(0)
44+
version_file.write(os.environ["APP_VERSION"])
45+
version_file.truncate()
46+
return r

tests/actual_tests/misc_test.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from nc_py_api import NextcloudException
6+
from nc_py_api import NextcloudException, ex_app
77
from nc_py_api._deffered_error import DeferredError # noqa
88
from nc_py_api._exceptions import check_error # noqa
99
from nc_py_api._misc import nc_iso_time_to_datetime, require_capabilities # noqa
@@ -74,3 +74,20 @@ def test_persist_transformers_cache(nc_app):
7474
from nc_py_api.ex_app import persist_transformers_cache # noqa
7575

7676
assert os.environ["TRANSFORMERS_CACHE"]
77+
os.environ.pop("TRANSFORMERS_CACHE")
78+
79+
80+
def test_verify_version(nc_app):
81+
version_file_path = os.path.join(ex_app.persistent_storage(), "_version.info")
82+
if os.path.exists(version_file_path):
83+
os.remove(version_file_path)
84+
r = ex_app.verify_version(False)
85+
assert not os.path.getsize(version_file_path)
86+
assert isinstance(r, tuple)
87+
assert r[0] == ""
88+
assert r[1] == os.environ["APP_VERSION"]
89+
r = ex_app.verify_version(True)
90+
assert os.path.getsize(version_file_path)
91+
assert r[0] == ""
92+
assert r[1] == os.environ["APP_VERSION"]
93+
assert ex_app.verify_version() is None

0 commit comments

Comments
 (0)