ae.oaio_client
Our Asynchronously Interchangeable Objects Client
this portion is providing a client interface to manage asynchronously interchangeable oai objectz.
each oai object has a user-definable values dictionary and can optionally have a file or folder attached to it.
an instance of the here implemented class OaioClient, represents a client interface
to the oaio server, a django server available as git repository.
Module Attributes
file name to store the last synchronization timestamp |
|
|
Classes
|
interface to manage creations, updates and deletions of oaio objects of a user. |
- LAST_SYNC_STAMP_FILE = 'last_sync_stamp.txt'
file name to store the last synchronization timestamp
- class OaioClient(host, credentials, app_id='', device_id='', csh_default_id='Digi', client_root='{usr}/oaio_root/')[source]
Bases:
ErrorMsgMixininterface to manage creations, updates and deletions of oaio objects of a user.
Note
after creating an instance, the
synchronize()method has to be called at least once.- __init__(host, credentials, app_id='', device_id='', csh_default_id='Digi', client_root='{usr}/oaio_root/')[source]
initialize a new client instance to connect to the oaio server.
- Parameters:
host¶ (
str) – oaio server host name/address and optional port number.credentials¶ (
dict[str,str]) – oaio server user identification credentials kwargs (dict with the keys ‘username’ and ‘password’).app_id¶ (
str) – optional id/name of the app from where the client is connecting from. defaults toapp_nameattribute value (if theae.coreportion/module got included in the project) or (if not set) to the return value of the functionapp_name_guess().device_id¶ (
str) – id of the client device. defaults toos_device_id.csh_default_id¶ (
str) – id for the default cloud storage server to use. defaults to ‘Digi’.client_root¶ (
str) – path to the folder on the local device where the oaio info and files get cached. defaults to the placeholder path “{usr}/oaio_root/”.
- client_objectz: MutableMapping[str, OaiObject]
- _client_file_root(oaio_id, values)[source]
determine the path on the client/device where the file(s) attached to an oaio get stored.
- _client_server_file_api_paths(oai_obj)[source]
get attached files, the cloud storage api id, and the file root paths on client and cloud storage host.
- _csh_api(csh_id)[source]
determine api and credentials of a cloud storage host specified by its id from the web server db/config.
- Return type:
- _delete_client_object(oaio_id)[source]
delete an object locally on the client from the file system and client_objectz dict.
- _download_object(oai_obj)[source]
save oaio info and download optional attached files to the local device/cache.
- _init_client_folders()[source]
called on the first start of the client to create the folders and files under
client_root.
- _load_client_object_info(oaio_id, info_path='')[source]
load actual client/local oaio info of the oaio specified by its id.
- Return type:
- _load_client_objectz()[source]
load actual client/local oaio infos of all local oai objects.
- Return type:
- Returns:
mapping/dict with objectz stored on the local device.
- _load_server_objectz()[source]
get from server all newly added and changed objectz of all the subscriptions of the current user.
- Return type:
- Returns:
mapping/dict with objectz subscribed by the user from oaio server. if the client is offline an empty mapping object.
- _reconnect_check()[source]
check if the server got already connected and (re)connect if not.
- Return type:
- Returns:
a boolean True value if still connected or successfully reconnected or False if offline, connection cannot be established, CSRF token not available or on any other server failure/error; in these cases check the message in the property
error_message(inherited fromErrorMsgMixin).
- _request(method, slug, _in_chk=False, **request_kwargs)[source]
oaio server request checking CSRF for POST and automatic reconnect.
- Parameters:
- Return type:
Optional[Response]- Returns:
http response, or None if connection cannot be established (offline, authentication, ..) or if any other error occurred (check self.error_message for details).
- _res_err(res, msg, failure='', add_err=True)[source]
web request response error checker, amending error message with status-code.
- Return type:
- _upload_object(oai_obj)[source]
save the specified local/client object and try to send changes to storage and oaio/web servers.
- property last_sync_stamp: str
timestamp of last synchronization with the oaio/storage servers.
- Getter:
timestamp of the last server synchronization.
- Setter:
any assigned error message will be accumulated to recent error messages. pass an empty string to reset the error message.
- register_file(file_name, file_content=None, root_path='', stamp='', csh_id='')[source]
register a new oaio file object.
- Parameters:
file_content¶ (
Optional[bytes]) – file content if the file does not exist on any file system, pass as bytes to create it.root_path¶ (
str) – root path on local-machine of the new file object to register. usingclient_rootif not specified.stamp¶ (
str) – optional timestamp (created bynow_stamp()if not specified).csh_id¶ (
str) – cloud storage server id or empty string to use the default cloud storage server.
- Return type:
- Returns:
new
OaiObjectinstance or None if either stamp or oaio_id are already registered (check self.error_message).- Raises:
AssertionError – if the file to register does not exist.
- register_folder(root_path, stamp='', csh_id='')[source]
register a new oaio folder object.
- Parameters:
- Return type:
- Returns:
new
OaiObjectinstance or None if either stamp or oaio_id are already registered (check self.error_message).- Raises:
AssertionError – if files to register do not exist.
- register_object(values, stamp='', oaio_id='', csh_id='')[source]
register a new oaio data object.
- Parameters:
- Return type:
- Returns:
new
OaiObjectinstance. or None if either stamp or oaio_id are already registered (check self.error_message).- Raises:
AssertionError – on invalid argument values/types or if the oaio_id got already registered.
- synchronize_with_server_if_online()[source]
synchronize local changes to server and any update/changes done on other clients from server to this client.
Hint
if not connected to the oaio server, then this method tries first to (re-)connect.
- Return type:
- Returns:
False if the client is offline or on sync error, else True.
- update_file(oaio_id, file_name='', file_content=None, root_path='', stamp='')[source]
update oai file object locally.
- Parameters:
file_name¶ (
str) – name (optionally with the file path) of the attached file.file_content¶ (
Optional[bytes]) – file content if the file name does not exist, pass as bytes to create the file.root_path¶ (
str) – root path on local-machine of the new file object to update. usingclient_rootif not specified.stamp¶ (
str) – optional timestamp (usingnow_stamp()if not specified).
- Return type:
- Returns:
the updated
OaiObjectdataclass instance.- Raises:
AssertionError – if the file to update does not exist.
- update_folder(oaio_id, root_path='', stamp='')[source]
update oai folder object locally.
- Parameters:
- Return type:
- Returns:
the updated
OaiObjectdataclass instance.- Raises:
AssertionError – if the same file is in add_files and in removed_files, or if one of the files to update does not exist.
- update_object(oaio_id, values, stamp='', reset=False)[source]
update oaio data object locally.
- Parameters:
- Return type:
- Returns:
the updated
OaiObjectdataclass instance.- Raises:
AssertionError – on invalid argument values/types or if the oaio_id did not get registered.
- upsert_subscription(oaio_id, user_name, access_right='r')[source]
add/delete the subscriber of an oai object or update the access right of an existing user subscription.
- Parameters:
oaio_id¶ (
str) – id of the oaio to subscribe to or to unsubscribe from.access_right¶ (
str) – eitherNO_ACCESS_RIGHTto unsubscribe user or a user access right (one ofACCESS_RIGHTS) to subscribe the oaio specified byoaio_idto a user specified byuser_name. e.g., to grant update rights, pass the valueUPDATE_ACCESS_RIGHT. if not specified then the valueREAD_ACCESS_RIGHTwill be used.
- Return type:
- Returns:
the primary key integer value (Pubz.Pid) of the added/updated Pubz subscription record or a zero integer (0) if an error occurred.
- userz_access(oaio_id)[source]
determine a list of all the registered users and their access right to the specified oaio.
- Parameters:
oaio_id¶ (
str) – id of the oaio determine users and access rights for or an empty or unregistered oaio id if the oaio is not yet registered.- Return type:
- Returns:
list of dicts with the keys ‘username’ and ‘access_right’, or empty list on error. the returned list is sorted by the access_right (create, delete, update, read) and username. if an empty/unregistered oaio id got specified, all registered userz will be returned with the
NO_ACCESS_RIGHTaccess right.