2022-07-01 14:28:39 +04:00
|
|
|
"""File info object used by `python_aternos.atfm`"""
|
|
|
|
|
2022-03-18 18:38:36 +04:00
|
|
|
import enum
|
2022-08-22 09:55:08 +04:00
|
|
|
|
2021-10-14 17:56:01 +04:00
|
|
|
from typing import Union
|
2021-10-15 19:31:47 +04:00
|
|
|
from typing import TYPE_CHECKING
|
2021-10-14 17:56:01 +04:00
|
|
|
|
2022-08-22 09:55:08 +04:00
|
|
|
import lxml.html
|
|
|
|
|
2022-03-18 18:38:36 +04:00
|
|
|
from .aterrors import FileError
|
2021-10-14 17:56:01 +04:00
|
|
|
|
2021-10-15 19:31:47 +04:00
|
|
|
if TYPE_CHECKING:
|
2022-06-23 15:13:56 +04:00
|
|
|
from .atserver import AternosServer
|
|
|
|
|
2021-10-15 19:31:47 +04:00
|
|
|
|
2022-03-18 18:38:36 +04:00
|
|
|
class FileType(enum.IntEnum):
|
2022-06-17 12:30:58 +04:00
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
"""File or dierctory"""
|
|
|
|
|
|
|
|
file = 0
|
|
|
|
directory = 1
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
dir = 1
|
2022-06-17 12:30:58 +04:00
|
|
|
|
2021-10-14 17:56:01 +04:00
|
|
|
|
|
|
|
class AternosFile:
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
"""File class which contains info
|
|
|
|
about its path, type and size"""
|
2022-06-23 15:13:56 +04:00
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
atserv: 'AternosServer',
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
path: str, rmable: bool,
|
|
|
|
dlable: bool, editable: bool,
|
2022-06-23 15:13:56 +04:00
|
|
|
ftype: FileType = FileType.file,
|
|
|
|
size: Union[int, float] = 0) -> None:
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
"""File class which contains info
|
|
|
|
about its path, type and size
|
|
|
|
|
|
|
|
Args:
|
|
|
|
atserv (python_aternos.atserver.AternosServer):
|
|
|
|
atserver.AternosServer instance
|
|
|
|
path (str): Absolute path to the file
|
|
|
|
rmable (bool): Is the file deleteable (removeable)
|
|
|
|
dlable (bool): Is the file downloadable
|
|
|
|
ftype (python_aternos.atfile.FileType): File or directory
|
|
|
|
size (Union[int,float], optional): File size
|
|
|
|
"""
|
|
|
|
|
|
|
|
path = path.lstrip('/')
|
|
|
|
path = '/' + path
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
self.atserv = atserv
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
|
|
|
|
self._path = path
|
|
|
|
self._name = path[path.rfind('/') + 1:]
|
|
|
|
self._dirname = path[:path.rfind('/')]
|
|
|
|
|
|
|
|
self._deleteable = rmable
|
|
|
|
self._downloadable = dlable
|
|
|
|
self._editable = editable
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
self._ftype = ftype
|
|
|
|
self._size = float(size)
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
def create(
|
|
|
|
self,
|
|
|
|
name: str,
|
|
|
|
ftype: FileType = FileType.file) -> None:
|
|
|
|
|
|
|
|
"""Creates a file or a directory inside this one
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name (str): Filename
|
|
|
|
ftype (FileType, optional): File type
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
RuntimeWarning: Messages about probabilty of FileError
|
|
|
|
(if `self` file object is not a directory)
|
|
|
|
FileError: If Aternos denied file creation
|
|
|
|
"""
|
|
|
|
|
|
|
|
if self.is_file:
|
|
|
|
raise RuntimeWarning(
|
|
|
|
'Creating files only available '
|
|
|
|
'inside directories'
|
|
|
|
)
|
|
|
|
|
|
|
|
name = name.strip().replace('/', '_')
|
|
|
|
req = self.atserv.atserver_request(
|
|
|
|
'https://aternos.org/panel/ajax/files/create.php',
|
|
|
|
'POST', data={
|
|
|
|
'file': f'{self._path}/{name}',
|
|
|
|
'type': 'file'
|
|
|
|
if ftype == FileType.file
|
|
|
|
else 'directory'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if req.content == b'{"success":false}':
|
|
|
|
raise FileError('Unable to create a file')
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
def delete(self) -> None:
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
"""Deletes the file
|
2022-06-23 15:13:56 +04:00
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Raises:
|
|
|
|
RuntimeWarning: Message about probability of FileError
|
|
|
|
FileError: If deleting this file is disallowed by Aternos
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not self._deleteable:
|
|
|
|
raise RuntimeWarning(
|
|
|
|
'The file seems to be protected (undeleteable). '
|
|
|
|
'Always check it before calling delete()'
|
|
|
|
)
|
|
|
|
|
|
|
|
req = self.atserv.atserver_request(
|
2022-06-23 15:13:56 +04:00
|
|
|
'https://aternos.org/panel/ajax/delete.php',
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
'POST', data={'file': self._path},
|
2022-06-23 15:13:56 +04:00
|
|
|
sendtoken=True
|
|
|
|
)
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
if req.content == b'{"success":false}':
|
|
|
|
raise FileError('Unable to delete the file')
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
def get_content(self) -> bytes:
|
|
|
|
|
|
|
|
"""Requests file content in bytes (downloads it)
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Raises:
|
|
|
|
RuntimeWarning: Message about probability of FileError
|
|
|
|
FileError: If downloading this file is disallowed by Aternos
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
File content
|
2022-06-23 15:13:56 +04:00
|
|
|
"""
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
if not self._downloadable:
|
|
|
|
raise RuntimeWarning(
|
|
|
|
'The file seems to be undownloadable. '
|
|
|
|
'Always check it before calling get_content()'
|
|
|
|
)
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
file = self.atserv.atserver_request(
|
|
|
|
'https://aternos.org/panel/ajax/files/download.php',
|
|
|
|
'GET', params={
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
'file': self._path
|
2022-06-23 15:13:56 +04:00
|
|
|
}
|
|
|
|
)
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
if file.content == b'{"success":false}':
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
raise FileError(
|
|
|
|
'Unable to download the file. '
|
|
|
|
'Try to get text'
|
|
|
|
)
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
return file.content
|
|
|
|
|
|
|
|
def set_content(self, value: bytes) -> None:
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
"""Modifies file content
|
2022-06-23 15:13:56 +04:00
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Args:
|
|
|
|
value (bytes): New content
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
FileError: If Aternos denied file saving
|
2022-06-23 15:13:56 +04:00
|
|
|
"""
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
req = self.atserv.atserver_request(
|
2022-07-01 14:28:39 +04:00
|
|
|
'https://aternos.org/panel/ajax/save.php',
|
2022-06-23 15:13:56 +04:00
|
|
|
'POST', data={
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
'file': self._path,
|
2022-06-23 15:13:56 +04:00
|
|
|
'content': value
|
|
|
|
}, sendtoken=True
|
|
|
|
)
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
if req.content == b'{"success":false}':
|
|
|
|
raise FileError('Unable to save the file')
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
def get_text(self) -> str:
|
|
|
|
|
|
|
|
"""Requests editing the file as a text
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Raises:
|
|
|
|
RuntimeWarning: Message about probability of FileError
|
|
|
|
FileError: If unable to parse text from response
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
File text content
|
2022-06-23 15:13:56 +04:00
|
|
|
"""
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
if not self._editable:
|
|
|
|
raise RuntimeWarning(
|
|
|
|
'The file seems to be uneditable. '
|
|
|
|
'Always check it before calling get_text()'
|
|
|
|
)
|
|
|
|
|
|
|
|
if self.is_dir:
|
|
|
|
raise RuntimeWarning(
|
|
|
|
'Use get_content() to download '
|
|
|
|
'a directory as a ZIP file!'
|
|
|
|
)
|
|
|
|
|
|
|
|
filepath = self._path.lstrip("/")
|
2022-06-23 15:13:56 +04:00
|
|
|
editor = self.atserv.atserver_request(
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
f'https://aternos.org/files/{filepath}', 'GET'
|
2022-06-23 15:13:56 +04:00
|
|
|
)
|
|
|
|
edittree = lxml.html.fromstring(editor.content)
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
editblock = edittree.xpath('//div[@id="editor"]')
|
2022-06-23 15:13:56 +04:00
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
if len(editblock) < 1:
|
|
|
|
raise FileError(
|
|
|
|
'Unable to open editor. '
|
|
|
|
'Try to get file content'
|
|
|
|
)
|
|
|
|
|
|
|
|
return editblock[0].text_content()
|
2022-06-23 15:13:56 +04:00
|
|
|
|
|
|
|
def set_text(self, value: str) -> None:
|
|
|
|
|
|
|
|
"""Modifies the file content,
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
but unlike `set_content` takes
|
|
|
|
a string as an argument
|
2022-06-23 15:13:56 +04:00
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Args:
|
|
|
|
value (str): New content
|
2022-06-23 15:13:56 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
self.set_content(value.encode('utf-8'))
|
|
|
|
|
|
|
|
@property
|
2022-07-01 14:28:39 +04:00
|
|
|
def path(self) -> str:
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
"""Abslute path to the file
|
|
|
|
without leading slash
|
|
|
|
including filename
|
2022-07-01 14:28:39 +04:00
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Returns:
|
|
|
|
Full path to the file
|
2022-07-01 14:28:39 +04:00
|
|
|
"""
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
return self._path
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self) -> str:
|
2022-07-01 14:28:39 +04:00
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
"""Filename with extension
|
2022-07-01 14:28:39 +04:00
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Returns:
|
|
|
|
Filename
|
2022-07-01 14:28:39 +04:00
|
|
|
"""
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
def dirname(self) -> str:
|
2022-07-01 14:28:39 +04:00
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
"""Full path to the directory
|
|
|
|
which contains the file
|
|
|
|
without leading slash.
|
|
|
|
Empty path means root (`/`)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Path to the directory
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self._dirname
|
|
|
|
|
|
|
|
@property
|
|
|
|
def deleteable(self) -> bool:
|
|
|
|
|
|
|
|
"""True if the file can be deleted,
|
|
|
|
otherwise False
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Can the file be deleted
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self._deleteable
|
|
|
|
|
|
|
|
@property
|
|
|
|
def downloadable(self) -> bool:
|
|
|
|
|
|
|
|
"""True if the file can be downloaded,
|
|
|
|
otherwise False
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Can the file be downloaded
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self._downloadable
|
|
|
|
|
|
|
|
@property
|
|
|
|
def editable(self) -> bool:
|
|
|
|
|
|
|
|
"""True if the file can be
|
|
|
|
opened in Aternos editor,
|
|
|
|
otherwise False
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Can the file be edited
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self._editable
|
|
|
|
|
|
|
|
@property
|
|
|
|
def ftype(self) -> FileType:
|
|
|
|
|
|
|
|
"""File object type: file or directory
|
2022-07-01 14:28:39 +04:00
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Returns:
|
|
|
|
File type
|
2022-07-01 14:28:39 +04:00
|
|
|
"""
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
return self._ftype
|
2022-06-23 15:13:56 +04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_dir(self) -> bool:
|
2022-07-01 14:28:39 +04:00
|
|
|
|
|
|
|
"""Check if the file object is a directory
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Returns:
|
|
|
|
True if it is a directory, otherwise False
|
2022-07-01 14:28:39 +04:00
|
|
|
"""
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
return self._ftype == FileType.dir
|
2022-06-23 15:13:56 +04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_file(self) -> bool:
|
2022-07-01 14:28:39 +04:00
|
|
|
|
|
|
|
"""Check if the file object is not a directory
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Returns:
|
|
|
|
True if it is a file, otherwise False
|
2022-07-01 14:28:39 +04:00
|
|
|
"""
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
return self._ftype == FileType.file
|
2022-06-23 15:13:56 +04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def size(self) -> float:
|
2022-07-01 14:28:39 +04:00
|
|
|
|
|
|
|
"""File size in bytes
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Returns:
|
|
|
|
File size
|
2022-07-01 14:28:39 +04:00
|
|
|
"""
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
return self._size
|