Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit c9d336d
Author: Henrik Norin <henrik.norin@highdefinitionrender.com>
Date:   Thu Nov 9 15:15:29 2023 +0100

    [API,CORE] Include and exclude filter  (regexp supported) argument to ls and getsize operations.
  • Loading branch information
henriknorin committed Nov 9, 2023
1 parent 57445b4 commit ee3c7e8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
7 changes: 7 additions & 0 deletions doc/release_notes.rst
Expand Up @@ -14,6 +14,13 @@ Release Notes
`https://support.accsyn.com <https://support.accsyn.com>`_.


.. release:: 2.2.0
:date: 2023-11-09

.. change:: feat

* Include and exclude filter expressions to file 'ls' & 'getsize' operations.

.. release:: 2.1.4
:date: 2023-10-17

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='accsyn-python-api',
version='2.1.4',
version='2.2.0',
package_dir={'': 'source'},
packages=['accsyn_api'],
setup_requires=[
Expand Down
35 changes: 33 additions & 2 deletions source/accsyn_api/session.py
Expand Up @@ -806,6 +806,8 @@ def ls(
getsize=False,
files_only=False,
directories_only=False,
include=None,
exclude=None,
):
"""
List files on a share.
Expand All @@ -816,7 +818,18 @@ def ls(
:param getsize: If True - file sizes will be returned.
:param files_only: If True - only return files, no directories.
:param directories_only: If True - only return directories, no files.
:param include: Filter expression (string or list) dictating what to include in result: "word" - exact match,
"*word" - ends with word, "word*" - starts with word, "*word*" - contains word and "re('...')" - regular
expression. Has precedence over *exclude*.
:param exclude: Filter expression (string or list) dictating what to exclude from result: "word" - exact match,
"*word" - ends with word, "word*" - starts with word, "*word*" - contains word and "re('...')" - regular
expression.
:return: A dictionary containing result of file listing.
Include and exclude filters are case-insensitive, to make regular expression case-sensitive, use the following
syntax: "re('...', 'I')".
.. versionadded:: 2.6-20
"""
assert 0 < len(path or "") and (
Session._is_str(path) or isinstance(path, dict) or isinstance(path, list)
Expand All @@ -834,16 +847,30 @@ def ls(
data["directories_only"] = directories_only
if files_only:
data["files_only"] = files_only
if include:
data["include"] = include
if exclude:
data["exclude"] = exclude
response = self._event("GET", "organization/file", data)
if response:
return response["result"]

def getsize(self, path):
def getsize(self, path, include=None, exclude=None):
"""
Get size of a file or directory.
:param path: The accsyn path, on the form 'share=<the share>/<path>/<somewhere>'.
:param include: Filter expression (string or list) dictating what to include in result: "word" - exact match,
"*word" - ends with word, "word*" - starts with word, "*word*" - contains word and "re('...')" - regular
expression. Has precedence over *exclude*.
:param exclude: Filter expression (string or list) dictating what to exclude from result: "word" - exact match,
"*word" - ends with word, "word*" - starts with word, "*word*" - contains word and "re('...')" - regular
expression.
:return: A number representing the file size.
Include and exclude filters are case-insensitive, to make regular expression case-sensitive, use the following
syntax: "re('...', 'I')".
"""
assert 0 < len(path or "") and (
Session._is_str(path) or isinstance(path, dict) or isinstance(path, list)
Expand All @@ -852,6 +879,10 @@ def getsize(self, path):
"op": "getsize",
"path": path,
}
if include:
data["include"] = include
if exclude:
data["exclude"] = exclude
response = self._event("GET", "organization/file", data)
if response:
return response["result"]
Expand Down Expand Up @@ -1316,7 +1347,7 @@ def _rest(
)
do_retry = False
if not retval.get("message") is None:
# Some thing went wrong
# Something went wrong
if retval.get("session_expired") is True:
if self._api_key is not None:
# We should be able to get a new session and retry
Expand Down

0 comments on commit ee3c7e8

Please sign in to comment.