From 682c25b72f6f1ea73f3b5d6f4cd0111d795ec965 Mon Sep 17 00:00:00 2001 From: luffah Date: Wed, 16 Jun 2021 23:08:12 +0200 Subject: [PATCH 1/3] Update setup.py to publish properly on PyPi --- AUTHORS.rst | 1 + README.md => README.rst | 48 +++++++++++++++++++++++++++++------------ setup.cfg | 4 ++-- setup.py | 3 ++- 4 files changed, 39 insertions(+), 17 deletions(-) rename README.md => README.rst (56%) diff --git a/AUTHORS.rst b/AUTHORS.rst index e2deb87..e882d75 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -11,6 +11,7 @@ Main contributors Original code ````````````` The repo was originally nammed NEXT-OCS-API-forPy in 2017 + - どまお `@Dosugamea ` diff --git a/README.md b/README.rst similarity index 56% rename from README.md rename to README.rst index 70771a5..373610a 100644 --- a/README.md +++ b/README.rst @@ -1,6 +1,8 @@ -# NextCloud Python api +NextCloud Python API +==================== -## Overview +Overview +-------- Python wrapper for NextCloud's API. @@ -22,42 +24,60 @@ Tested with : * NextCloud 20, python 2.7 * NextCloud 20, python 3.6 -The main lines: +The main lines : * `NextCloud(URL, auth=…)` provide you a connection manager. You can use it with `with … as nxc:` to open a session. * The session is the connection object that make the requests. * The requests are initiated by a requester associated to an API wrapper. * API wrappers are the definition of how to use the NextCloud REST API : it provide functions that will be attached to the `NextCloud` object. * Functions can return : - - Response object with attributes `is_ok`, `data`. If `is_ok` is False, you can use `get_error_message`. - - Data objects (File, Tag…) or None. + - Response object with attributes `is_ok`, `data`. If `is_ok` is False, you can use `get_error_message`. + - Data objects (File, Tag…) or None. * Data objects are useable as dict object or with attribute. They provide operations. If the operation fails, you'll get an exception. -For quick start, check out [examples](examples) and the [unit tests directory](tests). +For quick start, check out `examples`_ and the `tests`_. +Install +------- -## Fork Change +.. code-block:: sh + + # use 'pip3' for python3 or 'python -m pip' instead of pip + pip install nextcloud-api-wrapper + # the associated python lib is nammed 'nextcloud' + # beware the conflicts -This version is a fork (mainly refactoring, fixes and optimization) of [nextcloud-API](https://github.com/EnterpriseyIntranet/nextcloud-API). -#### Testing +Fork Changes +------------ + +This version is a fork (mainly refactoring, fixes and optimization) of `nextcloud-API `_ . + +Testing +~~~~~~~ The integration to Travis and CodeCov provided by the original repository are lost. There is now 2 branches `develop` and `main`. -All [tests](tests) are validated using `test.sh docker` before merging `develop` to `main`. +All `tests`_ are validated using `test.sh docker` before merging `develop` to `main`. -#### Documentation +Documentation +~~~~~~~~~~~~~ The integration with readthedoc.io is lost. You still can build the documentation with Sphinx source. Looking at the code docstrings is recommended. Significative changes will be reported in `CHANGELOG.md` file. -Too, you can check out the original [nextcloud API documentation](https://nextcloud-api.readthedocs.io/en/latest/introduction.html), but the use could have changed. +Too, you can check out the original `nextcloud API documentation `_, but the use could have changed. -## Contribution +Contributing +------------ -### Pull Request +Pull Request +~~~~~~~~~~~~ According to the testing procedure, you shall fork and PR on branch `develop`. + +.. _tests: https://github.com/luffah/nextcloud-API/tree/main/tests +.. _examples: https://github.com/luffah/nextcloud-API/tree/main/examples diff --git a/setup.cfg b/setup.cfg index fe370c0..fda74aa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,9 @@ [metadata] name = nextcloud-api-wrapper -version = 0.2.1 +version = 0.2.1.5 description= Python wrapper for NextCloud api -long_description = file: README.md +long_description = file: README.rst keywords = requests, api, wrapper, nextcloud, owncloud license = GPLv3 diff --git a/setup.py b/setup.py index da2469f..c99fe7b 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ # 'setup.py publish' shortcut. if sys.argv[-1] == 'publish': # see https://twine.readthedocs.io/en/latest/ + os.system('rm -rf dist build') os.system('python %s sdist bdist_wheel' % (sys.argv[0])) os.system('python3 %s sdist bdist_wheel' % (sys.argv[0])) os.system('twine upload dist/*') @@ -28,5 +29,5 @@ # some variables are defined here for retro compat with setuptools >= 33 package_dir = {'': 'src'}, packages=find_packages(where=r'./src'), - long_description_content_type = 'text/markdown' + long_description_content_type = 'text/x-rst' ) From bebeb22d55ce5ae35621d103f3e0dcb9bbe72d58 Mon Sep 17 00:00:00 2001 From: svierne Date: Sat, 18 Sep 2021 23:50:01 +0200 Subject: [PATCH 2/3] Add new share types for OCS Share API. --- src/nextcloud/api_wrappers/share.py | 13 +++++++++++-- src/nextcloud/codes.py | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/nextcloud/api_wrappers/share.py b/src/nextcloud/api_wrappers/share.py index a295ccc..db846ba 100644 --- a/src/nextcloud/api_wrappers/share.py +++ b/src/nextcloud/api_wrappers/share.py @@ -7,6 +7,14 @@ from nextcloud import base from nextcloud.codes import ShareType +SHARE_WITH_ENABLED_SHARE_TYPES = [ + ShareType.USER, + ShareType.GROUP, + ShareType.EMAIL, + ShareType.CIRCLE, + ShareType.FEDERATED_CLOUD_SHARE, + ShareType.TALK_CONVERSATION +] class Share(base.OCSv2ApiWrapper): """ Share API wrapper """ @@ -34,7 +42,7 @@ def validate_share_parameters(path, share_type, share_with): if ( path is None or not isinstance(share_type, int) or ( share_with is None and - share_type in [ShareType.GROUP, ShareType.USER, ShareType.FEDERATED_CLOUD_SHARE] + share_type in SHARE_WITH_ENABLED_SHARE_TYPES ) ): return False @@ -106,7 +114,8 @@ def create_share( public_upload = "true" data = {"path": path, "shareType": share_type} - if share_type in [ShareType.GROUP, ShareType.USER, ShareType.FEDERATED_CLOUD_SHARE]: + + if share_type in SHARE_WITH_ENABLED_SHARE_TYPES: data["shareWith"] = share_with if public_upload: data["publicUpload"] = public_upload diff --git a/src/nextcloud/codes.py b/src/nextcloud/codes.py index e6c980d..ea3d65e 100644 --- a/src/nextcloud/codes.py +++ b/src/nextcloud/codes.py @@ -17,7 +17,10 @@ class ShareType: USER = 0 GROUP = 1 PUBLIC_LINK = 3 + EMAIL = 4 FEDERATED_CLOUD_SHARE = 6 + CIRCLE = 7 + TALK_CONVERSATION = 10 class Permission: From eb6a59bc57efb3ee81b35b45fe098d03f345729b Mon Sep 17 00:00:00 2001 From: svierne Date: Wed, 6 Oct 2021 21:49:02 +0200 Subject: [PATCH 3/3] Turn SHARE_WITH_ENABLED_SHARE_TYPES into a class property. --- src/nextcloud/api_wrappers/share.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/nextcloud/api_wrappers/share.py b/src/nextcloud/api_wrappers/share.py index db846ba..3d33e98 100644 --- a/src/nextcloud/api_wrappers/share.py +++ b/src/nextcloud/api_wrappers/share.py @@ -7,19 +7,19 @@ from nextcloud import base from nextcloud.codes import ShareType -SHARE_WITH_ENABLED_SHARE_TYPES = [ - ShareType.USER, - ShareType.GROUP, - ShareType.EMAIL, - ShareType.CIRCLE, - ShareType.FEDERATED_CLOUD_SHARE, - ShareType.TALK_CONVERSATION -] class Share(base.OCSv2ApiWrapper): """ Share API wrapper """ API_URL = "/ocs/v2.php/apps/files_sharing/api/v1" LOCAL = "shares" + SHARE_WITH_ENABLED_SHARE_TYPES = [ + ShareType.USER, + ShareType.GROUP, + ShareType.EMAIL, + ShareType.CIRCLE, + ShareType.FEDERATED_CLOUD_SHARE, + ShareType.TALK_CONVERSATION + ] def get_local_url(self, additional_url=""): if additional_url: @@ -42,7 +42,7 @@ def validate_share_parameters(path, share_type, share_with): if ( path is None or not isinstance(share_type, int) or ( share_with is None and - share_type in SHARE_WITH_ENABLED_SHARE_TYPES + share_type in Share.SHARE_WITH_ENABLED_SHARE_TYPES ) ): return False @@ -115,7 +115,7 @@ def create_share( data = {"path": path, "shareType": share_type} - if share_type in SHARE_WITH_ENABLED_SHARE_TYPES: + if share_type in self.SHARE_WITH_ENABLED_SHARE_TYPES: data["shareWith"] = share_with if public_upload: data["publicUpload"] = public_upload