pyslk.base package

Contents

pyslk.base package#

Submodules#

pyslk.base.file_group module#

class pyslk.base.file_group.FileGroup(group_dict: dict)#

Bases: object

dump() dict#

Dump all details of this job as a dictionary

Returns:

a dictionary of all job details

Return type:

dict

get_files() list[str] | list[pathlib.Path]#
get_job_id() int#

Returns the current job id of this job

Returns:

job id

Return type:

int

get_job_ids() list[int]#

Prints the history of job IDs of this job. The first one is the oldest and the last one the newest.

Returns:

all job ids which have been associated to this job

Return type:

list[int]

get_job_status() StatusJob#
get_pid() int#

Same as get_process_id(). Returns the process id slk call which submitted the last recall job

Returns:

process id

Return type:

int

get_pids() list[int]#

Same as get_process_ids(). Returns the history of the process ids of the slk calls which submitted the recalls

Returns:

all process ids which have been associated to this group

Return type:

list[int]

get_process_id() int#

Returns the process id slk call which submitted the last recall job

Returns:

process id

Return type:

int

get_process_ids() list[int]#

Returns the history of the process ids of the slk calls which submitted the recall jobs

Returns:

all process ids which have been associated to this group

Return type:

list[int]

get_search_id() int#
get_search_query() str#
get_tape_barcodes() list[str]#
get_tape_ids() list[int]#
has_files() bool#
has_job_id() bool#
has_pid() bool#
has_process_id() bool#
has_search_id() bool#
has_search_query() bool#
has_tape_barcodes() bool#
has_tape_ids() bool#
is_cached() bool#
is_recall_error() bool#
json() str#

print a JSON string of all details of this job

Returns:

JSON string of all details of this job

Return type:

str

merge_group(group: FileGroup)#
put_files(files: list[str] | list[pathlib.Path])#
put_job_id(job_id: int)#
put_pid(process_id: int)#

Same as put_process_id(). Set the current pid / process id of slk call which submitted the current recall job

Parameters:

process_id (int) – process id / pid to be set

put_process_id(process_id: int)#

Set the current pid / process id of slk call which submitted the current recall job

Parameters:

process_id (int) – process id / pid to be set

put_tape_barcode(tape_barcode: str)#
put_tape_id(tape_id: int)#
set_recall_error(recall_error)#
updated_caching_info() bool#

Check is all files of this job are cached. Throws an error if this job is associated to no file.

Returns:

info if all files of this job are cached

Return type:

bool

pyslk.base.group_collection module#

class pyslk.base.group_collection.GroupCollection#

Bases: object

add_group(group: FileGroup | dict) int#
dump() dict[int, dict]#
get_group(search_id: int) FileGroup#
json() str#

print a JSON string of all jobs in this job collection

Returns:

JSON strong of all jobs in this job collection

Return type:

str

size() int#

pyslk.base.listing module#

pyslk.base.listing.list_clone_file(resource_path: str | Path | list[str] | list[pathlib.Path] | set[str] | set[pathlib.Path], column_names=['permissions', 'owner', 'group', 'filesize', 'timestamp_mtime', 'timestamp_created', 'timestamp_modified', 'timestamp_storage', 'tape_id', 'filename']) <Mock name='mock.DataFrame' id='139757892385232'>#

Return pandas.DataFrame containing results from search id

Calls list_clone_file_raw() and parses the return string into a pandas.DataFrame(). Assumes six output columns of ‘slk_helpers list_clone_file’ having the widths 12, 16, 999 (999 => as wide as necessary).

Parameters:
  • resource_path (str or path-like or list[str] or list[Path] or set[str] or set[Path]) – namespace or resource

  • column_names (list) – names of the columns in the pandas.DataFrame

Returns:

output of ‘slk_helpers list_search’ parsed into a pandas.DataFrame with three columns (permissions, size, filename)

Return type:

pandas.DataFrame

Return pandas.DataFrame containing results from search id

Calls list_clone_search_raw() and parses the return string into a pandas.DataFrame(). Assumes six output columns of ‘slk_helpers list_clone_search’ having the widths 12, 16, 999 (999 => as wide as necessary).

Parameters:
  • search_id (str, int, list, set) – search id of search which results should be printed

  • only_files (bool) – print only files (like default for slk list)

  • only_namespaces (bool) – print only namespaces

  • start (int) – collect search results starting with the result ‘start’; if set to 1 then collect from the beginning

  • count (int) – Collect as many search results as defined by this parameter. If set to 0 then collect until end.

  • column_names (list) – names of the columns in the pandas.DataFrame

Returns:

output of ‘slk_helpers list_search’ parsed into a pandas.DataFrame with three columns (permissions, size, filename)

Return type:

pandas.DataFrame

pyslk.base.listing.ls(path_or_id: str | int | Path | list[str] | list[int] | list[pathlib.Path] | set[str] | set[int] | set[pathlib.Path], show_hidden: bool = False, numeric_ids: bool = False, recursive: bool = False, column_names: list = ['permissions', 'owner', 'group', 'filesize', 'day', 'month', 'year', 'time', 'filename'], parse_dates: bool = True, parse_sizes: bool = True, full_path: bool = True) <Mock name='mock.DataFrame' id='139757892385232'>#

Return pandas.DataFrame containing results from search id or GNS path

Calls list_raw() and parses the return string into a pandas.DataFrame. All arguments are copied 1:1 except for ‘column_widths’. Assumes six output columns of ‘slk list’ having the widths 12, 12, 12, 9, 4, 4, 5 and 999 (999 => as wide as necessary).

Note: list_raw() currently only print the modification date and no modification time. The output of this parser might be modified in future when modification times are printed as well.

Parameters:
  • path_or_id (str or Path or int) – search id or gns path

  • show_hidden (bool) – show ‘.’ files, default: False (don’t show these files)

  • numeric_ids (bool) – show numeric values for user and group, default: False (show user and group names)

  • recursive (bool) – use the -R flag to list recursively, default: False

  • column_names (list) – names of the columns in the pandas.DataFrame

  • parse_dates (bool) – parse day, month and year into a datetime column.

  • parse_sizes (bool) – parse ‘filesize’ column into bytes integer.

  • full_path (bool) – add full filepath to filename column.

Returns:

output of ‘slk list’ parsed into a pandas.DataFrame with eight columns (permissions, owner, group, size, day, month, year, filename)

Return type:

pandas.DataFrame

See also

pyslk.base.login module#

pyslk.base.login.expiration_date() datetime#

Shows expiration date of your token

Returns:

expiration date of the login token

Return type:

datetime

pyslk.base.login.hostname() str#

Shows current hostname you are connected to

Returns:

hostname of the StrongLink system to which slk and slk_helpers currently connect to

Return type:

str

pyslk.base.login.session() datetime#

Shows expiration date of your token

Returns:

expiration date of the login token

Return type:

datetime

pyslk.base.login.valid_session() bool#

Returns whether session token is valid or not

Returns:

True if valid token exists; False otherwise

Return type:

bool

pyslk.base.login.valid_token() bool#

Returns whether session token is valid or not

Returns:

True if valid token exists; False otherwise

Return type:

bool

pyslk.base.resource_path module#

pyslk.base.resource_path.get_resource_path(resource_id: str | int) Path | None#

Get path for a resource id

Parameters:

resource_id (str or int) – a resource_id

Returns:

path of the resource; None if resource does not exist

Return type:

Path or None

pyslk.base.searching module#

pyslk.base.searching.get_search_status(search_id: int) dict#

return status of a search as dictionary

Parameters:

search_id (int) – search id

Returns:

dictionary which contains the search status and, if failed, a detailed error message

Return type:

dict

pyslk.base.searching.is_search_incomplete(search_id: int) bool#

check if search is still running

Parameters:

search_id (int) – search id

Returns:

True if search is still running; False otherwise (might also be failed)

Return type:

bool

pyslk.base.searching.is_search_successful(search_id: int) bool#

check if search was successfully finished

Parameters:

search_id (int) – search id

Returns:

True if search finished successfully; False if still running; False if search failed

Return type:

bool

pyslk.base.searching.search(search_string: str) int#

Performs a search based on a search_string can be provided. returns search id

search_string has to be a valid JSON search string as described in the SLK-CLI manual. Simple double quotes have to be used in the JSON expression (no escaped double quotes, no escaped special characters).

Parameters:

search_string (str) – JSON search query string

Returns:

search id of the performed search

Return type:

int

Examples

search_string='{"resources.mtime": {"$gt": "2021-09-02"}}'
pyslk.base.searching.search_immediately(search_string: str) int#

Performs a search based on a search_string and directly returns a search id while search is in progress

search_string has to be a valid JSON search string as described in the SLK-CLI manual. Simple double quotes has to be used in the JSON expression (no escaped double quotes, no escaped special characters).

Parameters:

search_string (str) – JSON search query string

Returns:

search id of the performed search

Return type:

int

Examples

search_string='{"resources.mtime": {"$gt": "2021-09-02"}}'
pyslk.base.searching.searchid_exists(search_id: str | int) bool#

Get path for a resource id

Parameters:

search_id (str or int) – a search_id

Returns:

whether provided search id exists (True) or not (False)

Return type:

bool

pyslk.base.searching.total_number_search_results(search_id: [<class 'int'>, <class 'str'>]) int | None#

Print the total number of search results regardless of read permissions of the current user

Parameters:

search_id (str or int) – a search_id

Returns:

total number of search results

Return type:

int or None

pyslk.base.stati module#

class pyslk.base.stati.StatusJob(status_str: str)#

Bases: object

ABORTED = 2#
COMPLETED = -1#
FAILED = 1#
PAUSED = -4#
PROCESSING = -2#
QUEUED = -3#
STATI = {}#
SUCCESSFUL = 0#
get_possible_stati() dict#
get_status() int#

return the status as integer

Meaning of the output * -4: PAUSED / PAUSING * -3: QUEUED * -2: PROCESSING / COMPLETING * -1: COMPLETED * 0: SUCCESSFUL * 1: FAILED * 2: ABORTED / ABORTING

Returns:

status as integer value (-4 to 2)

Return type:

int

get_status_name() str#
has_failed() bool#
is_completed() bool#
is_finished() bool#
is_paused() bool#
is_processing() bool#
is_queued() bool#
is_successful() bool#
status: int#

pyslk.base.versioning module#

pyslk.base.versioning.cli_versions(cli: list[str] | tuple[str] | str | None = None) dict[str, str]#

Return the version of slk and/or slk_helpers

Uses version_slk_raw() and version_slk_helpers_raw()

Similar to ~pyslk.version_slk and ~pyslk.version_slk_helpers

Parameters:

cli (list[str], tuple[str], str) – names of the commands for which the version should be obtained

Returns:

dictionary containing the versions of clis slk and/or slk_helpers

Return type:

dict

pyslk.base.versioning.version_slk() str#

List the version of slk

Uses version_slk_raw()

Returns:

stdout of the slk call

Return type:

str

pyslk.base.versioning.version_slk_helpers() str#

List the version of slk_helpers

Uses version_slk_helpers_raw()

Returns:

stdout of the slk_helpers call

Return type:

str

Module contents#

class pyslk.base.FileGroup(group_dict: dict)#

Bases: object

dump() dict#

Dump all details of this job as a dictionary

Returns:

a dictionary of all job details

Return type:

dict

get_files() list[str] | list[pathlib.Path]#
get_job_id() int#

Returns the current job id of this job

Returns:

job id

Return type:

int

get_job_ids() list[int]#

Prints the history of job IDs of this job. The first one is the oldest and the last one the newest.

Returns:

all job ids which have been associated to this job

Return type:

list[int]

get_job_status() StatusJob#
get_pid() int#

Same as get_process_id(). Returns the process id slk call which submitted the last recall job

Returns:

process id

Return type:

int

get_pids() list[int]#

Same as get_process_ids(). Returns the history of the process ids of the slk calls which submitted the recalls

Returns:

all process ids which have been associated to this group

Return type:

list[int]

get_process_id() int#

Returns the process id slk call which submitted the last recall job

Returns:

process id

Return type:

int

get_process_ids() list[int]#

Returns the history of the process ids of the slk calls which submitted the recall jobs

Returns:

all process ids which have been associated to this group

Return type:

list[int]

get_search_id() int#
get_search_query() str#
get_tape_barcodes() list[str]#
get_tape_ids() list[int]#
has_files() bool#
has_job_id() bool#
has_pid() bool#
has_process_id() bool#
has_search_id() bool#
has_search_query() bool#
has_tape_barcodes() bool#
has_tape_ids() bool#
is_cached() bool#
is_recall_error() bool#
json() str#

print a JSON string of all details of this job

Returns:

JSON string of all details of this job

Return type:

str

merge_group(group: FileGroup)#
put_files(files: list[str] | list[pathlib.Path])#
put_job_id(job_id: int)#
put_pid(process_id: int)#

Same as put_process_id(). Set the current pid / process id of slk call which submitted the current recall job

Parameters:

process_id (int) – process id / pid to be set

put_process_id(process_id: int)#

Set the current pid / process id of slk call which submitted the current recall job

Parameters:

process_id (int) – process id / pid to be set

put_tape_barcode(tape_barcode: str)#
put_tape_id(tape_id: int)#
set_recall_error(recall_error)#
updated_caching_info() bool#

Check is all files of this job are cached. Throws an error if this job is associated to no file.

Returns:

info if all files of this job are cached

Return type:

bool

class pyslk.base.GroupCollection#

Bases: object

add_group(group: FileGroup | dict) int#
dump() dict[int, dict]#
get_group(search_id: int) FileGroup#
json() str#

print a JSON string of all jobs in this job collection

Returns:

JSON strong of all jobs in this job collection

Return type:

str

size() int#
class pyslk.base.StatusJob(status_str: str)#

Bases: object

ABORTED = 2#
COMPLETED = -1#
FAILED = 1#
PAUSED = -4#
PROCESSING = -2#
QUEUED = -3#
STATI = {}#
SUCCESSFUL = 0#
get_possible_stati() dict#
get_status() int#

return the status as integer

Meaning of the output * -4: PAUSED / PAUSING * -3: QUEUED * -2: PROCESSING / COMPLETING * -1: COMPLETED * 0: SUCCESSFUL * 1: FAILED * 2: ABORTED / ABORTING

Returns:

status as integer value (-4 to 2)

Return type:

int

get_status_name() str#
has_failed() bool#
is_completed() bool#
is_finished() bool#
is_paused() bool#
is_processing() bool#
is_queued() bool#
is_successful() bool#
status: int#
pyslk.base.cli_versions(cli: list[str] | tuple[str] | str | None = None) dict[str, str]#

Return the version of slk and/or slk_helpers

Uses version_slk_raw() and version_slk_helpers_raw()

Similar to ~pyslk.version_slk and ~pyslk.version_slk_helpers

Parameters:

cli (list[str], tuple[str], str) – names of the commands for which the version should be obtained

Returns:

dictionary containing the versions of clis slk and/or slk_helpers

Return type:

dict

pyslk.base.expiration_date() datetime#

Shows expiration date of your token

Returns:

expiration date of the login token

Return type:

datetime

pyslk.base.get_resource_path(resource_id: str | int) Path | None#

Get path for a resource id

Parameters:

resource_id (str or int) – a resource_id

Returns:

path of the resource; None if resource does not exist

Return type:

Path or None

pyslk.base.get_search_status(search_id: int) dict#

return status of a search as dictionary

Parameters:

search_id (int) – search id

Returns:

dictionary which contains the search status and, if failed, a detailed error message

Return type:

dict

pyslk.base.hostname() str#

Shows current hostname you are connected to

Returns:

hostname of the StrongLink system to which slk and slk_helpers currently connect to

Return type:

str

pyslk.base.is_search_incomplete(search_id: int) bool#

check if search is still running

Parameters:

search_id (int) – search id

Returns:

True if search is still running; False otherwise (might also be failed)

Return type:

bool

pyslk.base.is_search_successful(search_id: int) bool#

check if search was successfully finished

Parameters:

search_id (int) – search id

Returns:

True if search finished successfully; False if still running; False if search failed

Return type:

bool

pyslk.base.list_clone_file(resource_path: str | Path | list[str] | list[pathlib.Path] | set[str] | set[pathlib.Path], column_names=['permissions', 'owner', 'group', 'filesize', 'timestamp_mtime', 'timestamp_created', 'timestamp_modified', 'timestamp_storage', 'tape_id', 'filename']) <Mock name='mock.DataFrame' id='139757892385232'>#

Return pandas.DataFrame containing results from search id

Calls list_clone_file_raw() and parses the return string into a pandas.DataFrame(). Assumes six output columns of ‘slk_helpers list_clone_file’ having the widths 12, 16, 999 (999 => as wide as necessary).

Parameters:
  • resource_path (str or path-like or list[str] or list[Path] or set[str] or set[Path]) – namespace or resource

  • column_names (list) – names of the columns in the pandas.DataFrame

Returns:

output of ‘slk_helpers list_search’ parsed into a pandas.DataFrame with three columns (permissions, size, filename)

Return type:

pandas.DataFrame

Return pandas.DataFrame containing results from search id

Calls list_clone_search_raw() and parses the return string into a pandas.DataFrame(). Assumes six output columns of ‘slk_helpers list_clone_search’ having the widths 12, 16, 999 (999 => as wide as necessary).

Parameters:
  • search_id (str, int, list, set) – search id of search which results should be printed

  • only_files (bool) – print only files (like default for slk list)

  • only_namespaces (bool) – print only namespaces

  • start (int) – collect search results starting with the result ‘start’; if set to 1 then collect from the beginning

  • count (int) – Collect as many search results as defined by this parameter. If set to 0 then collect until end.

  • column_names (list) – names of the columns in the pandas.DataFrame

Returns:

output of ‘slk_helpers list_search’ parsed into a pandas.DataFrame with three columns (permissions, size, filename)

Return type:

pandas.DataFrame

pyslk.base.ls(path_or_id: str | int | Path | list[str] | list[int] | list[pathlib.Path] | set[str] | set[int] | set[pathlib.Path], show_hidden: bool = False, numeric_ids: bool = False, recursive: bool = False, column_names: list = ['permissions', 'owner', 'group', 'filesize', 'day', 'month', 'year', 'time', 'filename'], parse_dates: bool = True, parse_sizes: bool = True, full_path: bool = True) <Mock name='mock.DataFrame' id='139757892385232'>#

Return pandas.DataFrame containing results from search id or GNS path

Calls list_raw() and parses the return string into a pandas.DataFrame. All arguments are copied 1:1 except for ‘column_widths’. Assumes six output columns of ‘slk list’ having the widths 12, 12, 12, 9, 4, 4, 5 and 999 (999 => as wide as necessary).

Note: list_raw() currently only print the modification date and no modification time. The output of this parser might be modified in future when modification times are printed as well.

Parameters:
  • path_or_id (str or Path or int) – search id or gns path

  • show_hidden (bool) – show ‘.’ files, default: False (don’t show these files)

  • numeric_ids (bool) – show numeric values for user and group, default: False (show user and group names)

  • recursive (bool) – use the -R flag to list recursively, default: False

  • column_names (list) – names of the columns in the pandas.DataFrame

  • parse_dates (bool) – parse day, month and year into a datetime column.

  • parse_sizes (bool) – parse ‘filesize’ column into bytes integer.

  • full_path (bool) – add full filepath to filename column.

Returns:

output of ‘slk list’ parsed into a pandas.DataFrame with eight columns (permissions, owner, group, size, day, month, year, filename)

Return type:

pandas.DataFrame

See also

pyslk.base.search(search_string: str) int#

Performs a search based on a search_string can be provided. returns search id

search_string has to be a valid JSON search string as described in the SLK-CLI manual. Simple double quotes have to be used in the JSON expression (no escaped double quotes, no escaped special characters).

Parameters:

search_string (str) – JSON search query string

Returns:

search id of the performed search

Return type:

int

Examples

search_string='{"resources.mtime": {"$gt": "2021-09-02"}}'
pyslk.base.search_immediately(search_string: str) int#

Performs a search based on a search_string and directly returns a search id while search is in progress

search_string has to be a valid JSON search string as described in the SLK-CLI manual. Simple double quotes has to be used in the JSON expression (no escaped double quotes, no escaped special characters).

Parameters:

search_string (str) – JSON search query string

Returns:

search id of the performed search

Return type:

int

Examples

search_string='{"resources.mtime": {"$gt": "2021-09-02"}}'
pyslk.base.searchid_exists(search_id: str | int) bool#

Get path for a resource id

Parameters:

search_id (str or int) – a search_id

Returns:

whether provided search id exists (True) or not (False)

Return type:

bool

pyslk.base.session() datetime#

Shows expiration date of your token

Returns:

expiration date of the login token

Return type:

datetime

pyslk.base.total_number_search_results(search_id: [<class 'int'>, <class 'str'>]) int | None#

Print the total number of search results regardless of read permissions of the current user

Parameters:

search_id (str or int) – a search_id

Returns:

total number of search results

Return type:

int or None

pyslk.base.valid_session() bool#

Returns whether session token is valid or not

Returns:

True if valid token exists; False otherwise

Return type:

bool

pyslk.base.valid_token() bool#

Returns whether session token is valid or not

Returns:

True if valid token exists; False otherwise

Return type:

bool

pyslk.base.version_slk() str#

List the version of slk

Uses version_slk_raw()

Returns:

stdout of the slk call

Return type:

str

pyslk.base.version_slk_helpers() str#

List the version of slk_helpers

Uses version_slk_helpers_raw()

Returns:

stdout of the slk_helpers call

Return type:

str