Skip to content

Commit d141a43

Browse files
committed
add setup.cfg for a more readable package config + add test for systemtags + test.sh script to ease test
1 parent 288d5d6 commit d141a43

27 files changed

+365
-104
lines changed

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ services:
44
- docker
55

66
python:
7-
- "3.6"
7+
- 2.7
8+
- 3.6
89

910
before_script:
1011
- cd tests && docker-compose up --build -d
@@ -14,7 +15,7 @@ before_script:
1415
# commands to run tests
1516
script:
1617
- docker-compose run --rm python-api python3 -m pytest --cov . --cov-report xml --cov-report term ..
17-
- docker-compose run --rm python-api python ../example.py
18+
- docker-compose run --rm python-api python ../examples/user_management.py
1819

1920
after_script:
2021
- codecov

AUTHORS.rst

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
This is Python wrapper for NextCloud's API had been made by…
3+
4+
Main contributors
5+
`````````````````
6+
- Matěj Týč `@matejak <https://github.com/matejak>` active from 2018
7+
- Danil Topchiy `@danil-topchiy <https://github.com/danil-topchiy>` active 2018-2019
8+
9+
10+
Refactoring contributors
11+
````````````````````````
12+
- Matěj Týč `@matejak <https://github.com/matejak>` active from 2018
13+
- Danil Topchiy `@danil-topchiy <https://github.com/danil-topchiy>` active 2018-2019
14+
- luffah `@luffah <https://github.com/luffah>` active 2021
15+
16+
17+
Original code
18+
`````````````
19+
The repo was originally nammed NEXT-OCS-API-forPy in 2017
20+
- どまお `@Dosugamea <https://github.com/Dosugamea>`
21+
22+
23+
Patches
24+
```````
25+
- Hendrik Eckardt `@heck-gd <https://github.com/heck-gd>`
26+
- Anonymous `@xr-muc <https://github.com/xr-muc>`
27+
- tthmmts `@tthmmts <https://github.com/tthmmts>`
28+
- Dylann Cordel `@webu <https://github.com/webu>` `@DylannCordel <https://github.com/DylannCordel>`
29+
- scouderc `@scouderc <https://github.com/scouderc>`

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This is Python wrapper for NextCloud's API.
1313
With it you can manage your NextCloud instances from Python scripts.
1414

1515
Tested with :
16-
* NextCloud 14, python 3.7
16+
* NextCloud 14, python 3.7 (automated test)
1717
* NextCloud 20, python 2.7
1818
* NextCloud 20, python 3.6
1919

requirements.in

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
requests>=2.0.1
22
pytest>=4.6
3+
six

requirements.txt

+1-11
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,5 @@
44
#
55
# pip-compile --output-file requirements.txt requirements.in
66
#
7-
atomicwrites==1.2.1 # via pytest
8-
attrs==18.2.0 # via pytest
9-
certifi==2018.11.29 # via requests
10-
chardet==3.0.4 # via requests
11-
idna==2.7 # via requests
12-
more-itertools==4.3.0 # via pytest
13-
pluggy==0.8.0 # via pytest
14-
py==1.7.0 # via pytest
15-
pytest==4.0.1
7+
pytest==4.6.1
168
requests==2.20.1
17-
six==1.11.0 # via more-itertools, pytest
18-
urllib3==1.24.1 # via requests

setup.cfg

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[metadata]
2+
3+
name = nextcloud
4+
version = 0.2
5+
description= Python wrapper for NextCloud api
6+
long_description = file: README.md
7+
keywords = requests, api, wrapper, nextcloud, owncloud
8+
license = GPLv3
9+
10+
url = https://nextcloud-api.readthedocs.io
11+
project_urls =
12+
Documentation = https://nextcloud-api.readthedocs.io
13+
Source = https://github.com/EnterpriseyIntranet/nextcloud-API
14+
15+
author = EnterpriseyIntranet
16+
author_email = [email protected]
17+
18+
platforms = any
19+
20+
classifiers =
21+
Programming Language :: Python
22+
Programming Language :: Python :: 2
23+
Programming Language :: Python :: 3
24+
Development Status :: 4 - Beta
25+
Environment :: Web Environment
26+
Intended Audience :: Developers
27+
Topic :: Internet :: WWW/HTTP
28+
Topic :: Software Development :: Libraries :: Python Modules
29+
License :: OSI Approved :: GNU General Public License (GPL)
30+
Operating System :: OS Independent
31+
32+
[options]
33+
zip_safe = False
34+
include_package_data = True
35+
36+
install_requires =
37+
requests >=2.0.1, <3.0
38+
six
39+
40+
[options.extras_require]
41+
tests =
42+
pytest >= 5.2
43+
44+
#[tool:pytest]
45+
#addopts = --verbose --pylint-rcfile=setup.cfg
46+
# --pylint --pycodestyle
47+
48+
[pycodestyle]
49+
max-line-length=120
50+
ignore=E4,E7,W3
51+
52+
# Configuration for pylint
53+
[MASTER]
54+
ignore=CVS
55+
good-names=logger,e,i,j,n,m,f,_
56+
57+
[MESSAGES CONTROL]
58+
disable=all
59+
enable=unused-import,
60+
fixme,
61+
useless-object-inheritance,
62+
unused-variable,
63+
unused-argument,
64+
unexpected-keyword-arg,
65+
string,
66+
unreachable,
67+
invalid-name,
68+
logging-not-lazy,
69+
unnecesary-pass

setup.py

+26-33
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
1-
import os
2-
import setuptools
1+
"""
2+
Setup script
3+
4+
Usage :
5+
python setup.py build
6+
python setup.py install
37
4-
SETUPDIR = os.path.dirname(__file__)
5-
PKGDIR = os.path.join(SETUPDIR, 'src')
8+
For repository admin:
9+
python setup.py publish
610
7-
with open(os.path.join(SETUPDIR, 'README.md'), 'r') as f:
8-
long_description = f.read()
11+
For testing:
12+
test.sh
13+
"""
14+
import os
15+
import sys
16+
from setuptools import setup, find_packages
917

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

11-
setuptools.setup(
12-
name='nextcloud',
13-
version='0.0.2',
14-
author='EnterpriseyIntranet',
15-
description="Python wrapper for NextCloud api",
16-
long_description=long_description,
17-
long_description_content_type="text/markdown",
18-
url="https://github.com/EnterpriseyIntranet/nextcloud-API",
19-
packages=setuptools.find_packages(PKGDIR),
20-
include_package_data=True,
21-
install_requires=[
22-
'requests >= 2.0.1',
23-
'six'
24-
],
25-
package_dir={'': 'src'},
26-
classifiers=[
27-
'Programming Language :: Python',
28-
'Programming Language :: Python :: 2',
29-
'Programming Language :: Python :: 3',
30-
'Development Status :: 4 - Beta',
31-
'Environment :: Web Environment',
32-
'Intended Audience :: Developers',
33-
'Topic :: Internet :: WWW/HTTP',
34-
'Topic :: Software Development :: Libraries :: Python Modules',
35-
'License :: OSI Approved :: GNU General Public License (GPL)',
36-
"Operating System :: OS Independent",
37-
],
25+
setup(
26+
# see setup.cfg
27+
# some variables are defined here for retro compat with setuptools >= 33
28+
package_dir = {'': 'src'},
29+
packages=find_packages(where=r'./src'),
30+
long_description_content_type = 'text/markdown'
3831
)

src/nextcloud/api_wrappers/systemtags.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ def get_related_files(self, path=''):
3737
)
3838
return ret.data or []
3939

40+
def delete(self):
41+
"""
42+
Delete current tag
43+
44+
:returns: True if success
45+
"""
46+
_id = int(self.id)
47+
ret = self._wrapper.delete_systemtag(tag_id=_id)
48+
return ret.is_ok
49+
4050

4151
class File(webdav.File):
4252

@@ -114,11 +124,11 @@ def get_systemtag(self, name):
114124
:returns: Tag
115125
"""
116126
return self._get_tags_from_response(
117-
self.fetch_sytemtag(name, json_output=False),
127+
self.fetch_systemtag(name, json_output=False),
118128
one=True
119129
)
120130

121-
def fetch_sytemtag(self, name, fields=None, json_output=None):
131+
def fetch_systemtag(self, name, fields=None, json_output=None):
122132
"""
123133
Get attributes of a nammed tag
124134
@@ -181,11 +191,11 @@ def delete_systemtag(self, name=None, tag_id=None):
181191
:returns: requester response
182192
"""
183193
if not tag_id:
184-
resp = self.get_sytemtag(name, ['id'], json_output=False)
194+
resp = self.fetch_systemtag(name, ['id'], json_output=False)
185195
if resp.data:
186196
tag_id = resp.data[0].id
187-
if not tag_id: # lint only
188-
return None
197+
if not tag_id: # lint only
198+
return resp
189199
resp = self.requester.delete(url=(str(tag_id)))
190200
return resp
191201

@@ -203,7 +213,7 @@ def _get_fileid_from_path(self, path):
203213
return _id
204214

205215
def _get_systemtag_id_from_name(self, name):
206-
resp = self.client.fetch_sytemtag(name, ['id'], json_output=False)
216+
resp = self.client.fetch_systemtag(name, ['id'], json_output=False)
207217
tag_id = None
208218
if resp.data:
209219
tag_id = int(resp.data[0].id)

src/nextcloud/common/simplexml.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
def _prepare_xml_parsing(string):
1111
return encode_string(string)
1212

13+
def _safe_xml_val(val):
14+
if isinstance(val, int):
15+
val = str(val)
16+
return val
1317

1418
class SimpleXml:
1519
"""
@@ -40,7 +44,7 @@ def _to_field_vals_list(cls, fields_hash):
4044
else:
4145
vals = fields_hash[field_type]
4246
for field in vals:
43-
props_xml['{}:{}'.format(field_type, field)] = vals[field]
47+
props_xml['{}:{}'.format(field_type, field)] = _safe_xml_val(vals[field])
4448

4549
return props_xml
4650

@@ -86,9 +90,7 @@ def build_propfind_datas(cls, instr=None, filter_rules=None, fields=None):
8690
for k in rules:
8791
rule = ET.SubElement(rule_group, k)
8892
val = rules[k]
89-
if isinstance(val, int):
90-
val = str(val)
91-
rule.text = val
93+
rule.text = _safe_xml_val(val)
9294

9395
return cls._tostring(root)
9496

src/nextcloud/common/value_parsing.py

+8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
Extra tools for value parsing
44
"""
55
from datetime import datetime
6+
import os
67
from nextcloud.compat import datetime_to_timestamp
78

89

10+
def datetime_to_expire_date(date):
11+
return date.strftime("%Y-%m-%d")
12+
13+
914
def timestamp_to_epoch_time(rfc1123_date=''):
1015
"""
1116
literal date time string (use in DAV:getlastmodified) to Epoch time
@@ -19,8 +24,11 @@ def timestamp_to_epoch_time(rfc1123_date=''):
1924
int or None : Epoch time, if date string value is invalid return None
2025
"""
2126
try:
27+
_tz = os.environ.get('TZ', '')
28+
os.environ['TZ'] = 'UTC'
2229
_time = datetime.strptime(
2330
rfc1123_date, '%a, %d %b %Y %H:%M:%S GMT')
31+
os.environ['TZ'] = _tz
2432
except ValueError:
2533
return
2634
else:

src/nextcloud/requester.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55
from .response import WebDAVResponse, OCSResponse
66
from .compat import encode_string
7-
from .session import catch_connection_error
7+
from .session import catch_connection_error, NextCloudConnectionError
88

99

1010
# from six.moves.urllib import parse

0 commit comments

Comments
 (0)