Skip to content

Commit 94cc3cb

Browse files
authored
Saimon/core search and permalink (#287)
1 parent e07a695 commit 94cc3cb

File tree

6 files changed

+48
-4
lines changed

6 files changed

+48
-4
lines changed

cterasdk/core/files/browser.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22

33
import cterasdk.settings
4-
from ...exceptions import CTERAException
4+
from ...exceptions import CTERAException, ObjectNotFoundException
55
from ..base_command import BaseCommand
66
from . import io, common, shares, file_access
77

@@ -83,6 +83,18 @@ def copy(self, *paths, destination=None):
8383
raise ValueError('Copy destination was not specified.')
8484
return io.copy(self._core, *[self.get_object_path(path) for path in paths], destination=self.get_object_path(destination))
8585

86+
def permalink(self, path):
87+
"""
88+
Get Permalink for Path.
89+
90+
:param str path: Path.
91+
"""
92+
p = self.get_object_path(path)
93+
contents = [e for e in io.listdir(self._core, p.parent(), 1, False, p.name(), 1)] # pylint: disable=unnecessary-comprehension
94+
if contents and contents[0].name == p.name():
95+
return contents[0].permalink
96+
raise ObjectNotFoundException('File not found.', path)
97+
8698
def get_object_path(self, elements):
8799
return common.get_object_path(self.base, elements)
88100

cterasdk/core/files/common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,18 @@ def depth(self, depth):
107107
self.param.depth = depth # pylint: disable=attribute-defined-outside-init
108108
return self
109109

110+
def searchCriteria(self, criteria):
111+
self.param.searchCriteria = criteria # pylint: disable=attribute-defined-outside-init
112+
return self
113+
110114
def include_deleted(self):
111115
self.param.includeDeleted = True # pylint: disable=attribute-defined-outside-init
112116
return self
113117

118+
def limit(self, limit):
119+
self.param.limit = limit
120+
return self
121+
114122
def build(self):
115123
return self.param
116124

cterasdk/core/files/io.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
from . import common
33

44

5-
def listdir(core, path, depth=None, include_deleted=False):
5+
def listdir(core, path, depth=None, include_deleted=False, criteria=None, limit=None):
66
depth = depth if depth is not None else 1
77
builder = common.FetchResourcesParamBuilder().root(path.encoded_fullpath()).depth(depth)
88
if include_deleted:
99
builder.include_deleted()
10+
if criteria:
11+
builder.searchCriteria(criteria)
12+
if limit:
13+
builder.limit(limit)
1014
param = builder.build()
1115
if depth > 0:
1216
return common.objects_iterator(core, param)

cterasdk/objects/synchronous/drive.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, drive, Portal):
1919
drive._Portal = Portal
2020
drive.default.close()
2121
drive._ctera_session.start_remote_session(Portal.session())
22-
self.api = drive.default.clone(clients.API, EndpointBuilder.new(drive.base), authenticator=lambda *_: True)
22+
self.api = Portal.default.clone(clients.API, EndpointBuilder.new(drive.base), authenticator=lambda *_: True)
2323
else:
2424
self.api = drive.default.clone(clients.API, EndpointBuilder.new(drive.base, '/admingui/api'))
2525

@@ -49,3 +49,7 @@ def _session_id_key(self):
4949
@property
5050
def _login_object(self):
5151
raise NotImplementedError("Logins to the 'Drive App' are not enabled.")
52+
53+
@property
54+
def _omit_fields(self):
55+
return super()._omit_fields + ['backup', 'cli', 'logs', 'services', 'support', 'sync']

docs/source/UserGuides/Portal/Files.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,22 @@ Create Public Link
147147
148148
user.files.public_link('My Files/Documents/Sample.docx', 'RW', 45)
149149
150+
151+
Create Permalink
152+
================
153+
154+
.. automethod:: cterasdk.core.files.browser.FileBrowser.permalink
155+
:noindex:
156+
157+
.. code:: python
158+
159+
"""Create permalink to a file"""
160+
user.files.permalink('My Files/Documents/Sample.docx')
161+
162+
"""Create permalink to a folder"""
163+
user.files.permalink('My Files/Documents')
164+
165+
150166
Create Directories
151167
==================
152168

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Key Features
1616
1. `Portal Management <UserGuides/Portal/Administration.html>`_
1717
2. `Edge Filer Management <UserGuides/Edge/Configuration.html>`_, including remote access.
1818
2. Managing `Data Discovery and Migration Jobs <UserGuides/Edge/Migration.html>`_
19-
3. File Data Management APIs for `CTERA Edge Filer <UserGuides/Edge/Index.html>`_ and `CTERA Portal <UserGuides/Portal/Index.html>`_.
19+
3. File Data Management APIs for `CTERA Edge Filer <UserGuides/Edge/Files.html>`_ and `CTERA Portal <UserGuides/Portal/Files.html>`_.
2020
4. Data Services Framework:
2121
1. `Subscribing to File System Notifications <UserGuides/DataServices/NotificationService.html>`_
2222
2. `CTERA Direct IO <UserGuides/DataServices/DirectIO.html>`_, enabling parallel high-performnace retrieval directly from object storage.

0 commit comments

Comments
 (0)