@@ -288,6 +288,7 @@ def __repr__(self):
288
288
class Client ():
289
289
"""ownCloud client"""
290
290
291
+ OCS_BASEPATH = 'ocs/v1.php/'
291
292
OCS_SERVICE_SHARE = 'apps/files_sharing/api/v1'
292
293
OCS_SERVICE_PRIVATEDATA = 'privatedata'
293
294
OCS_SERVICE_CLOUD = 'cloud'
@@ -323,6 +324,9 @@ def __init__(self, url, **kwargs):
323
324
self .__verify_certs = kwargs .get ('verify_certs' , True )
324
325
self .__single_session = kwargs .get ('single_session' , True )
325
326
327
+ self .__capabilities = None
328
+ self .__version = None
329
+
326
330
url_components = urlparse .urlparse (url )
327
331
self .__davpath = url_components .path + 'remote.php/webdav'
328
332
self .__webdav_url = url + 'remote.php/webdav'
@@ -339,20 +343,13 @@ def login(self, user_id, password):
339
343
self .__session = requests .session ()
340
344
self .__session .verify = self .__verify_certs
341
345
self .__session .auth = (user_id , password )
342
- # TODO: use another path to prevent that the server renders the file list page
343
- res = self .__session .get (self .url + 'status.php' )
344
- if res .status_code == 200 :
345
- res = self .__make_ocs_request (
346
- 'GET' ,
347
- self .OCS_SERVICE_CLOUD ,
348
- 'capabilities'
349
- )
350
- if res .status_code == 200 :
351
- return
352
- raise HTTPResponseError (res )
353
- self .__session .close ()
354
- self .__session = None
355
- raise HTTPResponseError (res )
346
+
347
+ try :
348
+ self .__update_capabilities ()
349
+ except HTTPResponseError as e :
350
+ self .__session .close ()
351
+ self .__session = None
352
+ raise e
356
353
357
354
def logout (self ):
358
355
"""Log out the authenticated user and close the session.
@@ -1493,6 +1490,25 @@ def get_apps(self):
1493
1490
1494
1491
return ena_apps
1495
1492
1493
+ def get_version (self ):
1494
+ """Gets the ownCloud version of the connected server
1495
+
1496
+ :returns: ownCloud version as string
1497
+ """
1498
+ if self .__version is None :
1499
+ self .__update_capabilities ()
1500
+ return self .__version
1501
+
1502
+ def get_capabilities (self ):
1503
+ """Gets the ownCloud app capabilities
1504
+
1505
+ :returns: capabilities dictionary that maps from
1506
+ app name to another dictionary containing the capabilities
1507
+ """
1508
+ if self .__capabilities is None :
1509
+ self .__update_capabilities ()
1510
+ return self .__capabilities
1511
+
1496
1512
def enable_app (self , appname ):
1497
1513
"""Enable an app through provisioning_api
1498
1514
@@ -1596,7 +1612,7 @@ def __make_ocs_request(self, method, service, action, **kwargs):
1596
1612
slash = ''
1597
1613
if service :
1598
1614
slash = '/'
1599
- path = 'ocs/v1.php/' + service + slash + action
1615
+ path = self . OCS_BASEPATH + service + slash + action
1600
1616
1601
1617
attributes = kwargs .copy ()
1602
1618
@@ -1743,3 +1759,32 @@ def __get_shareinfo(self, data_el):
1743
1759
if (data_el is None ) or not (isinstance (data_el , ET .Element )):
1744
1760
return None
1745
1761
return ShareInfo (self .__xml_to_dict (data_el ))
1762
+
1763
+ def __update_capabilities (self ):
1764
+ res = self .__make_ocs_request (
1765
+ 'GET' ,
1766
+ self .OCS_SERVICE_CLOUD ,
1767
+ 'capabilities'
1768
+ )
1769
+ if res .status_code == 200 :
1770
+ tree = ET .fromstring (res .content )
1771
+ self .__check_ocs_status (tree )
1772
+
1773
+ data_el = tree .find ('data' )
1774
+ apps = {}
1775
+ for app_el in data_el .find ('capabilities' ):
1776
+ app_caps = {}
1777
+ for cap_el in app_el :
1778
+ app_caps [cap_el .tag ] = cap_el .text
1779
+ apps [app_el .tag ] = app_caps
1780
+
1781
+ self .__capabilities = apps
1782
+
1783
+ version_el = data_el .find ('version/string' )
1784
+ edition_el = data_el .find ('version/edition' )
1785
+ self .__version = version_el .text
1786
+ if edition_el .text is not None :
1787
+ self .__version += '-' + edition_el .text
1788
+
1789
+ return self .__capabilities
1790
+ raise HTTPResponseError (res )
0 commit comments