Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring for modulable wrappers / Python2 support + SystemTags wrapper #69

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ services:
- docker

python:
- "3.6"
- 2.7
- 3.6

before_script:
- cd tests && docker-compose up --build -d
Expand All @@ -14,7 +15,7 @@ before_script:
# commands to run tests
script:
- docker-compose run --rm python-api python3 -m pytest --cov . --cov-report xml --cov-report term ..
- docker-compose run --rm python-api python ../example.py
- docker-compose run --rm python-api python ../examples/user_management.py

after_script:
- codecov
Expand Down
29 changes: 29 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

This is Python wrapper for NextCloud's API had been made by…

Main contributors
`````````````````
- Matěj Týč `@matejak <https://github.com/matejak>` active from 2018
- Danil Topchiy `@danil-topchiy <https://github.com/danil-topchiy>` active 2018-2019


Refactoring contributors
````````````````````````
- Matěj Týč `@matejak <https://github.com/matejak>` active from 2018
- Danil Topchiy `@danil-topchiy <https://github.com/danil-topchiy>` active 2018-2019
- luffah `@luffah <https://github.com/luffah>` active 2021


Original code
`````````````
The repo was originally nammed NEXT-OCS-API-forPy in 2017
- どまお `@Dosugamea <https://github.com/Dosugamea>`


Patches
```````
- Hendrik Eckardt `@heck-gd <https://github.com/heck-gd>`
- Anonymous `@xr-muc <https://github.com/xr-muc>`
- tthmmts `@tthmmts <https://github.com/tthmmts>`
- Dylann Cordel `@webu <https://github.com/webu>` `@DylannCordel <https://github.com/DylannCordel>`
- scouderc `@scouderc <https://github.com/scouderc>`
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@

Python wrapper for NextCloud api

This is Python wrapper for NextCloud's API. With it you can manage your NextCloud instances from Python scripts.
Tested with python 3.7, NextCloud 14.
This is Python wrapper for NextCloud's API.
With it you can manage your NextCloud instances from Python scripts.

Tested with :
* NextCloud 14, python 3.7 (automated test)
* NextCloud 20, python 2.7
* NextCloud 20, python 3.6


## FAQ
Expand All @@ -23,7 +28,7 @@ Check out the corresponding [nextcloud API documentation](https://nextcloud-api.

#### How do I use it?

Check out [the simple example](example.py) and also check out the [unit tests directory](tests).
Check out [examples](examples) and also check out the [unit tests directory](tests).


#### What do I do if it doesn't work?
Expand Down
6 changes: 6 additions & 0 deletions api_implementation.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
"implementation status": "OK",
"date_last_checked": "2019-02-02"
},
{
"name": "Tags API",
"url": "https://doc.owncloud.com/server/developer_manual/webdav_api/tags.html",
"implementation status": "OK",
"date_last_checked": "2021-05-03"
},
{
"name": "Activity app API",
"url": "https://github.com/nextcloud/activity",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Examples
Users API methods
-----------------

.. include:: ../../example.py
.. include:: ../../examples/user_management.py
:literal:
File renamed without changes.
5 changes: 3 additions & 2 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
requests
pytest
requests>=2.0.1
pytest>=4.6
six
12 changes: 1 addition & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,5 @@
#
# pip-compile --output-file requirements.txt requirements.in
#
atomicwrites==1.2.1 # via pytest
attrs==18.2.0 # via pytest
certifi==2018.11.29 # via requests
chardet==3.0.4 # via requests
idna==2.7 # via requests
more-itertools==4.3.0 # via pytest
pluggy==0.8.0 # via pytest
py==1.7.0 # via pytest
pytest==4.0.1
pytest==4.6.1
requests==2.20.1
six==1.11.0 # via more-itertools, pytest
urllib3==1.24.1 # via requests
69 changes: 69 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[metadata]

name = nextcloud
version = 0.2
description= Python wrapper for NextCloud api
long_description = file: README.md
keywords = requests, api, wrapper, nextcloud, owncloud
license = GPLv3

url = https://nextcloud-api.readthedocs.io
project_urls =
Documentation = https://nextcloud-api.readthedocs.io
Source = https://github.com/EnterpriseyIntranet/nextcloud-API

author = EnterpriseyIntranet
author_email = [email protected]

platforms = any

classifiers =
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 3
Development Status :: 4 - Beta
Environment :: Web Environment
Intended Audience :: Developers
Topic :: Internet :: WWW/HTTP
Topic :: Software Development :: Libraries :: Python Modules
License :: OSI Approved :: GNU General Public License (GPL)
Operating System :: OS Independent

[options]
zip_safe = False
include_package_data = True

install_requires =
requests >=2.0.1, <3.0
six

[options.extras_require]
tests =
pytest >= 5.2

#[tool:pytest]
#addopts = --verbose --pylint-rcfile=setup.cfg
# --pylint --pycodestyle

[pycodestyle]
max-line-length=120
ignore=E4,E7,W3

# Configuration for pylint
[MASTER]
ignore=CVS
good-names=logger,e,i,j,n,m,f,_

[MESSAGES CONTROL]
disable=all
enable=unused-import,
fixme,
useless-object-inheritance,
unused-variable,
unused-argument,
unexpected-keyword-arg,
string,
unreachable,
invalid-name,
logging-not-lazy,
unnecesary-pass
50 changes: 26 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import os
import setuptools
"""
Setup script

Usage :
python setup.py build
python setup.py install

SETUPDIR = os.path.dirname(__file__)
PKGDIR = os.path.join(SETUPDIR, 'src')
For repository admin:
python setup.py publish

with open(os.path.join(SETUPDIR, 'README.md'), 'r') as f:
long_description = f.read()
For testing:
test.sh
"""
import os
import sys
from setuptools import setup, find_packages

# 'setup.py publish' shortcut.
if sys.argv[-1] == 'publish':
# see https://twine.readthedocs.io/en/latest/
os.system('%s %s sdist bdist_wheel' % (sys.executable, sys.argv[0]))
os.system('twine upload dist/*')
sys.exit()

setuptools.setup(
name='nextcloud',
version='0.0.1',
author='EnterpriseyIntranet',
description="Python wrapper for NextCloud api",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/EnterpriseyIntranet/nextcloud-API",
packages=setuptools.find_packages(PKGDIR),
include_package_data=True,
install_requires=['requests'],
package_dir={'': 'src'},
classifiers=[
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'License :: OSI Approved :: GNU General Public License (GPL)',
"Operating System :: OS Independent",
],
setup(
# see setup.cfg
# 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'
)
38 changes: 0 additions & 38 deletions src/nextcloud/NextCloud.py

This file was deleted.

89 changes: 88 additions & 1 deletion src/nextcloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,90 @@
# -*- coding: utf-8 -*-
from .NextCloud import NextCloud
from .session import Session
from .api_wrappers import API_WRAPPER_CLASSES


class NextCloud(object):
"""
A NextCloud/OwnCloud client.
Provides cookie persistence, connection-pooling, and configuration.

Basic Usage::

>>> from nextcloud import nextcloud
>>> s = Nextcloud('https://nextcloud.mysite.com', user='admin', password='admin')
>>> # or using use another auth method
>>> from requests.auth import HTTPBasicAuth
>>> s = Nextcloud('https://nextcloud.mysite.com', auth=HTTPBasicAuth('admin', 'admin'))
>>> #
>>> s.list_folders('/')
<Response [200] data={} is_ok=True>

For a persistent session::
>>> s.login() # if no user, password, or auth in parameter use existing
>>> # some actions #
>>> s.logout()

Or as a context manager::

>>> with Nextcloud('https://nextcloud.mysite.com',
... user='admin', password='admin') as nxc:
... # some actions #
"""

def __init__(self, endpoint=None,
user=None, password=None, json_output=True, auth=None,
session_kwargs=None,
session=None):
self.session = session or Session(
url=endpoint, user=user, password=password, auth=auth,
session_kwargs=session_kwargs
)
self.json_output = json_output
for functionality_class in API_WRAPPER_CLASSES:
functionality_instance = functionality_class(self)
for potential_method in dir(functionality_instance):
if not potential_method.startswith('_'):
if not callable(getattr(functionality_instance, potential_method)):
pass
else:
setattr(self, potential_method, getattr(
functionality_instance, potential_method))

@property
def user(self):
return self.session.user

@property
def url(self):
return self.session.url

def __enter__(self):
self.login()
return self

def __exit__(self, *args):
self.logout()

def login(self, user=None, password=None, auth=None):
self.logout()
return self.session.login(user=user, password=password, auth=auth,
client=self)

def with_attr(self, **kwargs):
if 'auth' in kwargs or 'endpoint' in kwargs or 'endpoint' in kwargs:
return self.with_auth(**kwargs)
if 'session_kwargs' in kwargs:
return self.with_auth(auth=self.session.auth, **kwargs)
return self.__class__(session=self.session, **kwargs)

def with_auth(self, auth=None, **kwargs):
init_kwargs = {'session_kwargs': self.session._session_kwargs,
'json_output': self.json_output}
init_kwargs.update(kwargs)
if 'endpoint' in kwargs:
return self.__class__(auth=auth, **init_kwargs)
return self.__class__(endpoint=self.session.url, auth=auth, **init_kwargs)

def logout(self):
if self.session.session:
self.session.logout()
9 changes: 3 additions & 6 deletions src/nextcloud/api_wrappers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from nextcloud.base import API_WRAPPER_CLASSES

from .activity import Activity
from .apps import Apps
from .capabilities import Capabilities
Expand All @@ -10,8 +11,4 @@
from .user import User
from .user_ldap import UserLDAP
from .webdav import WebDAV

OCS_API_CLASSES = [Activity, Apps, Capabilities, FederatedCloudShare, Group, GroupFolders,
Notifications, Share, User, UserLDAP]

WEBDAV_CLASS = WebDAV
from .systemtags import SystemTags, SystemTagsRelation
Loading