Auto-generated CK Python API¶
Submodules¶
ck.kernel module¶
-
ck.kernel.
access
(i)[source]¶ - Universal access to all CK actions with unified I/O as dictionaries
Target audience: end users
NOTE: If input is a string and it will be converted to the dictionary as follows (the same as CK command line):
key1=value1 -> converted to {key1:value1}
-key10 -> converted to {key10:”yes”}
-key11=value11 -> converted to {key11:value11}
—key12 -> converted to {key12:”yes”}
–key13=value13 -> converted to {key13:value13}
@file_json -> JSON from this file will be merged with INPUT
@@ -> CK will ask user ot enter manually JSON from console and merge with INPUT
@@key -> Enter JSON manually from console and merge with INPUT under this key
@@@cmd_json -> convert string to JSON (special format) and merge with INPUT
—xyz -> add everything after – to “unparsed_cmd” key in INPUT
When string is converted to INPUT dictionary, “cmd” variable is set to True
Parameters: Unified input as dictionary or string (converted to dict) – action (str): automation action
- module_uoa (str): CK module UOA for the automation action
or
(cid1) (str): if doesn’t have = and doesn’t start from – or - or @ -> appended to cids[] (cid2) (str): if doesn’t have = and doesn’t start from – or - or @ -> appended to cids[] (cid3) (str): if doesn’t have = and doesn’t start from – or - or @ -> appended to cids[]
(repo_uoa) (str): CK repo UOA if action is applied to some CK entry (data_uoa) (str): CK entry name(s)
- (out) (str): output for a given action
- if ‘’, none
- if ‘con’, console interaction (if from CMD, default)
- if ‘json’, print return dict as json to console
- if ‘json_with_sep’, separation line and return dict as json to console
- if ‘json_file’, save return dict to JSON file
(out_file) (str): Name of the file to save return dict if ‘out’==’json_file’
(con_encoding) (str): force encoding for I/O (ck_profile) (str): if ‘yes’, profile CK
Keys for a given CK automation action
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output from the given CK automation action
-
ck.kernel.
access_index_server
(i)[source]¶ - Access index server (usually ElasticSearch)
- Target audience: CK kernel and low-level developers
Parameters: - request (str) – request type (‘PUT’ | ‘DELETE’ | ‘TEST’ | ‘GET’)
- (path) (str) – ES “path” with indexing info
- (dict) (dict) – send this query as dict
- (limit_size) (int) – limit queries using this number (if ‘GET’)
- (start_from) (int) – start from a given entry in a query
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
dict (dict): dictionary from ElasticSearch with all entries
-
ck.kernel.
add
(i)[source]¶ - CK action: create CK entry with a given meta-description in a CK repository
- Target audience: should use via ck.kernel.access
Parameters: (repo_uoa) (str) – CK repo UOA
module_uoa (str) – CK module UOA
data_uoa (str) – CK entry (data) UOA
(data_uid) (str) – CK entry (data) UID (if UOA is an alias)
(data_name) (str) – User-friendly name of this entry
(dict) (dict) – meta description for this entry (will be recorded to meta.json)
(update) (str) – if == ‘yes’ and CK entry exists, update it
(substitute) (str) – if ‘yes’ and update==’yes’ substitute dictionaries, otherwise merge!
(dict_from_cid) (str) – if !=””, merge dict to meta description from this CID (analog of copy)
(dict_from_repo_uoa) (str) – merge dict from this CK repo UOA
(dict_from_module_uoa) (str) – merge dict from this CK module UOA
(dict_from_data_uoa) (str) – merge dict from this CK entry UOA
(desc) (dict) – under development - defining SPECs for meta description in the CK flat format
(extra_json_files) (dict) – dict with extra json files to save to this CK entry (keys in this dictionary are filenames)
(tags) (str) – list or comma separated list of tags to add to entry
(info) (dict) – entry info to record - normally, should not use it!
(extra_info) (dict) –
enforce extra info such as
- author
- author_email
- author_webpage
- license
- copyright
If not specified then take it from the CK kernel (prefix ‘default_’)
(updates) (dict) – entry updates info to record - normally, should not use it!
(ignore_update) (str) – if ‘yes’, do not add info about update
(ask) (str) – if ‘yes’, ask questions, otherwise silent
(unlock_uid) (str) – unlock UID if was previously locked
(sort_keys) (str) – by default, ‘yes’
(share) (str) – if ‘yes’, try to add via GIT
(skip_indexing) (str) – if ‘yes’, skip indexing even if it is globally on
(allow_multiple_aliases) (str) – if ‘yes’, allow multiple aliases for the same UID (needed for cKnowledge.io to publish renamed components with the same UID)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output from the ‘create_entry’ function
-
ck.kernel.
add_action
(i)[source]¶ - Add a new action to the given CK module
- Target audience: should use via ck.kernel.access
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – must be “module”
- data_uoa (str) – UOA of the module for the new action
- func (str) – action name
- (desc) (str) – action description
- (for_web) (str) – if ‘yes’, make it compatible with the CK web API, i.e. allow an access to this function in the CK server
- (skip_appending_dummy_code) (str) – if ‘yes’, do not append code
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output from the ‘update’ function for the given CK module
-
ck.kernel.
add_index
(i)[source]¶ - Index CK entries using ElasticSearch or similar tools
- Target audience: CK kernel and low-level developers
Parameters: - (repo_uoa) (str) – CK repo UOA with wild cards
- (module_uoa) (str) – CK module UOA with wild cards
- (data_uoa) (str) – CK entry (data) UOA with wild cards
- (print_full) (str) – if ‘yes’, show CID (repo_uoa:module_uoa:data_uoa)
- (print_time) (str) – if ‘yes’. print elapse time at the end
- (time_out) (float) – time out in sec. (default -1, i.e. no timeout)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
browser
(i)[source]¶ - Open web browser with the API if exists
- Target audience: CK kernel and low-level developers
Parameters: - (template) (str) – use this web template (CK wfe module)
- (repo_uoa) (str) – CK repo UOA
- (module_uoa) (str) – CK module UOA
- (data_uoa) (str) – CK entry (data) UOA
- (extra_url) (str) – Extra URL
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
cd
(i)[source]¶ - CK action: print ‘cd {path to CID}’
- Target audience: end users
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK entry (data) UOA or
- cid (str) – CK CID
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output from the ‘load’ function
string (str): prepared string ‘cd {path to entry}’
-
ck.kernel.
cdc
(i)[source]¶ - CK action: print ‘cd {path to CID}’ and copy to clipboard
- Target audience: end users
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK entry (data) UOA or
- cid (str) – CK CID
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output from the ‘load’ function
-
ck.kernel.
check_lock
(i)[source]¶ - Check if a given path is locked. Unlock if requested.
- Target audience: CK kernel and low-level developers
Parameters: - path (str) – path to be checked/unlocked
- (unlock_uid) (str) – UID of the lock to release it
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
check_version
(i)[source]¶ - Compare a given version with the CK version
- Target audience: CK kernel and low-level developers
Parameters: version (str) – your version Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
ok (str): if ‘yes’, your CK kernel version is outdated
current_version (str): your CK kernel version
-
ck.kernel.
check_writing
(i)[source]¶ - Check is writing to a given repo with a given module is allowed
- Target audience: CK kernel and low-level developers
Parameters: - (module_uoa) (str) – module UOA
- (module_uid) (str) – module UID
- (repo_uoa) (str) – repo UOA
- (repo_uid) (str) – repo UID
- (repo_dict) (dict) – repo meta description with potential read/write permissions
- (delete) (str) – if ‘yes’, check if global delete operation is allowed
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
(repo_dict) (dict): repo meta description if available
-
ck.kernel.
cid
(i)[source]¶ - CK action: get CID from the current path or from the input
- Target audience: end users
Parameters: - (repo_uoa) (str) – CK repo UOA
- (module_uoa) (str) – CK module UOA
- (data_uoa) (str) – CK entry (data) UOA
- If above is empty, detect CID in the current path !
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
data_uoa (str): CK entry (data) UOA
module_uoa (str): CK module UOA
(repo_uoa) (str): CK repo UOA
-
ck.kernel.
compare_dicts
(i)[source]¶ - Compare two dictionaries recursively
Target audience: end users
Note that if dict1 and dict2 has lists, the results will be as follows:
- dict1={“key”:[‘a’,’b’,’c’]} dict2={“key”:[‘a’,’b’]} EQUAL
- dict1={“key”:[‘a’,’b’]} dict2={“key”:[‘a’,’b’,’c’]} NOT EQUAL
Parameters: - dict1 (dict) – dictionary 1
- dict2 (dict) – dictionary 2
- (ignore_case) (str) – if ‘yes’, ignore case of letters
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
equal (str); if ‘yes’ then dictionaries are equal
-
ck.kernel.
compare_flat_dicts
(i)[source]¶ - Compare two CK flat dictionaries
- Target audience: end users
Parameters: - dict1 (dict) – dictionary 1
- dict2 (dict) – dictionary 2
- (ignore_case) (str) – if ‘yes’, ignore case of letters
- (space_as_none) (str) – if ‘yes’, consider “” as None
- (keys_to_ignore) (list) – list of keys to ignore (can be wildcards)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
equal (str); if ‘yes’ then dictionaries are equal
-
ck.kernel.
convert_ck_list_to_dict
(i)[source]¶ - Convert CK list to CK dict with unicode in UTF-8 (unification of interfaces)
- Target audience: CK kernel and low-level developers
Parameters: (list) – list from the ‘action’ function in this kernel Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
ck_dict (dict):
action (str): CK actioncid (str): CK module UOA or CID (x means that it may not be really CID and has to be processed specially
cids (list): a list of multple CIDs from CMD (commands like copy, move, etc) [cid1, cid2, cid3, …]
key1 (str): value1 from –key1=value1 or -key1=value1 or key1=value
key2 (str):
…
key10 (str):
…
keys (str): keys/values from file specified by “file_json”; if file extension is .tmp, it will be deleted after read!
keys (str): keys/values from cmd_json
unparsed (str): unparsed command line after –
-
ck.kernel.
convert_cm_to_ck
(i)[source]¶ - List files in a given CK entry
- Target audience: internal
Parameters: - (repo_uoa) (str) – CK repo UOA with wild cards
- (module_uoa) (str) – CK module UOA with wild cards
- (data_uoa) (str) – CK entry (data) UOA with wild cards
- (print_full) (str) – if ‘yes’, show CID (repo_uoa:module_uoa:data_uoa)
- (print_time) (str) – if ‘yes’. print elapse time at the end
- (ignore_update) (str) – if ‘yes’, do not add info about update
- (time_out) (float) – time out in sec. (default -1, i.e. no timeout)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
convert_entry_to_cid
(i)[source]¶ - Convert info about CK entry to CID
- Target audience: CK kernel and low-level developers
Parameters: - (repo_uoa) (str) – CK repo UOA
- (repo_uid) (str) – CK repo UID
- (module_uoa) (str) – CK module UOA
- (module_uid) (str) – CK module UID
- (data_uoa) (str) – CK entry (data) UOA
- (data_uid) (str) – CK entry (data) UID
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
cuoa (str); module_uoa:data_uoa (substituted with ? if can’t find)
cid (str): module_uid:data_uid (substituted with ? if can’t find)
xcuoa (str): repo_uoa:module_uoa:data_uoa (substituted with ? if can’t find)
xcid (str): repo_uid:module_uid:data_uid (substituted with ? if can’t find)
-
ck.kernel.
convert_file_to_upload_string
(i)[source]¶ - Convert file to a string for web-based upload
- Target audience: end users
Parameters: filename (str) – file name to convert Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
file_content_base64 (str): string that can be transmitted through Internet
-
ck.kernel.
convert_iso_time
(i)[source]¶ - Convert iso text time to a datetime object
- Target audience: end users
Parameters: iso_datetime (str) – date time as string in ISO standard Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
datetime_obj (obj): datetime object
-
ck.kernel.
convert_json_str_to_dict
(i)[source]¶ - Convert string in a special format to dict (JSON)
- Target audience: end users
Parameters: str (str) – string (use ‘ instead of “, i.e. {‘a’:’b’} to avoid issues in CMD in Windows and Linux!) Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
dict (dict): dict from json file
-
ck.kernel.
convert_str_key_to_int
(key)[source]¶ - Support function for safe convert str to int
- Target audience: end users
Parameters: key (str) – variable to be converted to int Returns: (int) – int(key) if key can be converted to int, or 0 otherwise
- Split string by comma into a list of stripped strings
Target audience: end users
Used to process and strip tags
Parameters: i (list or string) – list or string to be splitted and stripped Returns: (list) – list of stripped strings
-
ck.kernel.
convert_upload_string_to_file
(i)[source]¶ - Convert upload string to file
- Target audience: end users
Parameters: - file_content_base64 (str) – string transmitted through Internet
- (filename) (str) – file name to write (if empty, generate tmp file)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
filename (str): filename with full path
filename_ext (str): filename extension
-
ck.kernel.
copy
(i)[source]¶ - CK action: copy or move CK entry
- Target audience: should use via ck.kernel.access
Parameters: See “cp” function Returns: See “cp” function
-
ck.kernel.
copy_path_to_clipboard
(i)[source]¶ - Copy current path to clipboard (productivity function)
- Target audience: CK kernel and low-level developers
Parameters: (add_quotes) (str) – if ‘yes’, add quotes Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
copy_to_clipboard
(i)[source]¶ - Copy string to clipboard if supported by OS (requires Tk or pyperclip)
- Target audience: end users
Parameters: string (str) – string to copy Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
cp
(i)[source]¶ - CK action: copy or move CK entry
- Target audience: should use via ck.kernel.access
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK entry (data) UOA
- xcids (list) – use original name from xcids[0] and new name from xcids[1] ({‘repo_uoa’, ‘module_uoa’, ‘data_uoa’}) or
- (new_repo_uoa) (str) – new CK repo UOA
- (new_module_uoa) (str) – new CK module UOA
- new_data_uoa (str) – new CK data alias
- (new_data_uid) (str) – new CK entry (data) UID (leave empty to generate the new one)
- (move) (str) – if ‘yes’, remove the old entry
- (keep_old_uid) (str) – if ‘yes’, keep the old UID
- (without_files) (str) – if ‘yes’, do not move/copy files
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output from the “add” function
-
ck.kernel.
create_entry
(i)[source]¶ - Create a CK entry with UID or alias in the given path
- Target audience: CK kernel and low-level developers
Parameters: - path (str) – path where to create an entry
- (split_dirs) (int) – number of first characters to split directory into subdirectories to be able to handle many entries (similar to Mediawiki)
- (data_uoa) (str) – CK entry UOA
- (data_uid) (str) – if data_uoa is an alias, we can force data UID
- (force) (str) – if ‘yes’, force to create CK entry even if related directory already exists
- (allow_multiple_aliases) (str) – (needed for cKnowledge.io to publish renamed components with the same UID)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
path (str): path to the created CK entry
data_uid (str): UID of the created CK entry
data_alias (str): alias of the created CK entry
data_uoa (str): alias or UID (if alias==””) of the created CK entry
-
ck.kernel.
debug_out
(i)[source]¶ - Universal debug print of a dictionary while removing unprintable parts
- Target audience: end users
Parameters: i (dict) – dictionary to print Returns: (dict) – Unified CK dictionary:
return (int): 0
-
ck.kernel.
delete
(i)[source]¶ - CK action: delete CK entry or CK entries
- Target audience: should use via ck.kernel.access
Parameters: See “rm” function Returns: See “rm” function
-
ck.kernel.
delete_alias
(i)[source]¶ - Delete the CK entry alias from a given path
- Target audience: CK kernel and low-level developers
Parameters: - path (str) – path to the CK entry
- data_uid (str) – CK entry UID
- (data_alias) (str) – CK entry alias
- (repo_dict) (str) – meta description of a given CK repository to check if there is an automatic sync with a Git repository
- (share) (str) – if ‘yes’, try to delete using the Git client
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
delete_directory
(i)[source]¶ - Delete a given directory with all sub-directories (must be very careful)
- Target audience: CK kernel and low-level developers
Parameters: path (str) – path to delete Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
delete_file
(i)[source]¶ - Delete file from the CK entry
- Target audience: CK kernel and low-level developers
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK entry (data) UOA
- filename (str) – filename to delete including relative path
- (force) (str) – if ‘yes’, force deleting without questions
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
delete_index
(i)[source]¶ - Delete index for a given CK entry in the ElasticSearch or a similar services
- Target audience: CK kernel and low-level developers
Parameters: - (repo_uoa) (str) – CK repo UOA with wild cards
- (module_uoa) (str) – CK module UOA with wild cards
- (data_uoa) (str) – CK entry (data) UOA with wild cards
- (print_time) (str) – if ‘yes’. print elapse time at the end
- (time_out) (float) – in sec. (default -1, i.e. no timeout)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
detect_cid_in_current_path
(i)[source]¶ - Detect CID in the current directory
- Target audience: CK kernel and low-level developers
Parameters: (path) (str) – path, or current directory if path==”” Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
repo_uoa (str): CK repo UOA
repo_uid (str): CK repo UID
repo_alias (str): CK repo alias
(module_uoa) (str): CK module UOA
(module_uid) (str): CK module UID
(module_alias) (str): CK module alias
(data_uoa) (str): CK entry (data) UOA
(data_uid) (str): CK entry (data) UID
(data_alias) (str): CK entry (data) alias
-
ck.kernel.
download
(i)[source]¶ - Download CK entry from remote host (experimental)
- Target audience: end users
Parameters: - (repo_uoa) (str) – CK repo UOA
- (module_uoa) (str) – CK module UOA
- (data_uoa) (str) – CK data UOA
- (version) (str) – version (the latest one if skipped)
- (new_repo_uoa) (str) – target CK repo UOA, “local” by default
- (skip_module_check) (str) – if ‘yes’, do not check if module for a given component exists
- (all) (str) – if ‘yes’, download dependencies
- (force) (str) – if ‘yes, force download even if components already exists
- (tags) (str) – download components using tags separated by comma (usually soft/package)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
dump_json
(i)[source]¶ - Dump dictionary (json) to a string
- Target audience: end users
Parameters: - dict (dict) – dictionary to convert to a string
- (skip_indent) (str) – if ‘yes’, skip indent
- (sort_keys) (str) – if ‘yes’, sort keys
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
string (str): JSON string
-
ck.kernel.
dumps_json
(i)[source]¶ - Dump dictionary (json) to a string
- Target audience: end users
Parameters: - dict (dict) – dictionary to convert to a string
- (skip_indent) (str) – if ‘yes’, skip indent
- (sort_keys) (str) – if ‘yes’, sort keys
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
string (str): JSON string
-
ck.kernel.
edit
(i)[source]¶ - CK action: edit data meta-description through external editor
- Target audience: should use via ck.kernel.access
Parameters: - (repo_uoa) (str) – repo UOA
- module_uoa (str) – module UOA
- data_uoa (str) – data UOA
- (ignore_update) (str) – (default==yes) if ‘yes’, do not add info about update
- (sort_keys) (str) – (default==yes) if ‘yes’, sort keys
- (edit_desc) (str) – if ‘yes’, edit description rather than meta (useful for compiler descriptions)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
eout
(s)[source]¶ - Universal print of a unicode error string in the UTF-8 or other format to stderr
Target audience: end users
Supports: Python 2.x and 3.x
Parameters: s (str) – unicode string to print Returns: None
-
ck.kernel.
err
(r)[source]¶ - Print error to stderr and exit with a given return code
Target audience: end users
Used in Bash and Python scripts to exit on error
- Example:
import ck.kernel as ck
r=ck.access({‘action’:’load’, ‘module_uoa’:’tmp’, ‘data_uoa’:’some tmp entry’})
if r[‘return’]>0: ck.err(r)
Parameters: r (dict) – output dictionary of any standard CK function:
- return (int): return code
- (error) (str): error string if return>0
Returns: None - exits script!
-
ck.kernel.
find
(i)[source]¶ - CK action: find CK entry via the ‘load’ function
- Target audience: should use via ck.kernel.access
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK entry (data) UOA
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output from the ‘load’ function
number_of_entries (int): total number of found entries
-
ck.kernel.
find_path_to_data
(i)[source]¶ - Find path to CK sub-directory
Target audience: CK kernel and low-level developers
First search in the default repo, then in the local repo, and then in all installed repos
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK data UOA
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
path (str): path to CK entry (CK data)
path_module (str): path to CK module entry (part of the CK entry)
path_repo (str): path to the CK repository with this entry
repo_uoa (str): CK repo UOA
repo_uid (str): CK repo UID
repo_alias (str): CK repo alias
module_uoa (str): CK module UOA
module_uid (str): CK module UID
module_alias (str): CK module alias
uoa (str): CK sub-directory UOA
uid (str): CK sub-directory UID
alias (str): CK sub-directory alias
-
ck.kernel.
find_path_to_entry
(i)[source]¶ - Find path to CK entry (CK data) while checking both UID and alias.
- Target audience: CK kernel and low-level developers
Parameters: - path (str) – path to a data entry
- data_uoa (str) – CK entry UOA (CK data)
- (split_dirs) (int/str) – number of first characters to split directory into subdirectories to be able to handle many entries (similar to Mediawiki)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
path (str): path to CK entry
data_uid (str): CK entry UID
data_alias (str): CK entry alias
data_uoa (str): CK entry alias of UID, if alias is empty
-
ck.kernel.
find_path_to_repo
(i)[source]¶ - Find path for a given CK repo
- Target audience: end users
Parameters: (repo_uoa) (str) – CK repo UOA. If empty, get the path to the default repo (inside CK framework) Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
dict (dict): CK repo meta description from the cache path (str): path to this repo
repo_uoa (str): CK repo UOA
repo_uid (str): CK repo UID
repo_alias (str): CK repo alias
-
ck.kernel.
find_repo_by_path
(i)[source]¶ - Find CK repo info by path
- Target audience: CK kernel and low-level developers
Parameters: path (str) Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
repo_uoa (str): CK repo UOA
repo_uid (str): CK repo UID
repo_alias (str): CK repo alias
-
ck.kernel.
find_string_in_dict_or_list
(i)[source]¶ - Find a string in a dict or list
- Target audience: end users
Parameters: - dict (dict or list) – dict or list to search
- (search_string) (str) – search string
- (ignore_case) (str) – if ‘yes’ then ignore case of letters
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
found (str): if ‘yes’, string found
-
ck.kernel.
flatten_dict
(i)[source]¶ Any list item is converted to @number=value Any dict item is converted to #key=value # is always added at the beginning
- Input: {
dict - python dictionary
(prefix) - prefix (for recursion)
(prune_keys) - list of keys to prune (can have wildcards)
}
- Output: {
- return - return code = 0, if successful
- > 0, if error
(error) - error text if return > 0 dict - flattened dictionary
}
-
ck.kernel.
flatten_dict_internal
(a, aa, prefix, pk)[source]¶ - Convert dictionary into the CK flat format
- Target audience: internal use for recursion
Parameters: - a (any)
- aa (dict) – target dict
- prefix (str) – key prefix
- pk – aggregated key?
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
dict (dict): pass dict a from the input
-
ck.kernel.
flatten_dict_internal_check_key
(prefix, pk)[source]¶ - Convert dictionary into the CK flat format
- Target audience: internal use
Parameters: - prefix (str) – key prefix
- pk – aggregated key?
Returns: (bool) – key must be added if True
-
ck.kernel.
gen_tmp_file
(i)[source]¶ - Generate temporary files
- Target audience: end users
Parameters: - (suffix) (str) – temp file suffix
- (prefix) (str) – temp file prefix
- (remove_dir) (str) – if ‘yes’, remove dir
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
file_name (str): temp file name
-
ck.kernel.
gen_uid
(i)[source]¶ - Generate valid CK UID
- Target audience: end users
Parameters: None Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
data_uid (str): UID in string format (16 lowercase characters 0..9,a..f)
-
ck.kernel.
get_api
(i)[source]¶ - Print API from the CK module for a given action
- Target audience: CK kernel and low-level developers
Parameters: - (path) (str) – path to a CK module, if comes from the access function or
- (module_uoa) (str) – if comes from CMD
- (func) – API function name
- (out) – how to output this info
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
title (str): title string
desc (str): original description
module (str): CK module name
api (str): api
line (str): description string in the CK module
-
ck.kernel.
get_by_flat_key
(i)[source]¶ - Get a value from a dict by the CK flat key
- Target audience: end users
Parameters: - dict (dict) – dictionary
- key (str) – CK flat key
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
value (any): value or None, if key doesn’t exist
-
ck.kernel.
get_current_date_time
(i)[source]¶ - Get current date and time
- Target audience: end users
Parameters: (dict) – empty dict Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
array (dict); dict with date and time
- date_year (str)
- date_month (str)
- date_day (str)
- time_hour (str)
- time_minute (str)
- time_second (str)
iso_datetime (str): date and time in ISO format
-
ck.kernel.
get_default_repo
(i)[source]¶ - Print path to the default repo
- Target audience: CK kernel and low-level developers
Args:
Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
path (str): path
-
ck.kernel.
get_from_dicts
(dict1, key, default_value, dict2, extra='')[source]¶ - Get value from one dict, remove it from there and move to another
- Target audience: end users
Parameters: - dict1 (dict) – first check in this dict (and remove if there)
- key (str) – key in the dict1
- default_value (str) – default value if not found
- dict2 (dict) – then check key in this dict
Returns: (any) – value from the dictionary
-
ck.kernel.
get_os_ck
(i)[source]¶ - Get host platform name (currently win or linux) and OS bits
- Target audience: end users
Parameters: (bits) (int) – force OS bits Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
platform (str): ‘win’ or ‘linux’
bits (str): OS bits in string (32 or 64)
python_bits (str): Python installation bits (32 or 64)
-
ck.kernel.
get_split_dir_number
(repo_dict, module_uid, module_uoa)[source]¶ - Support function for checking splitting entry number
- Target audience: CK kernel and low-level developers
Parameters: - repo_dict (dict) – dictionary with CK repositories
- module_uid (str) – requested CK module UID
- module_uoa (str) – requested CK module UOA
Returns: (int) –
- number of sub-directories for CK entries -
useful when holding millions of entries
-
ck.kernel.
get_version
(i)[source]¶ - Get CK version
- Target audience: end users
Args: None
Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
version (list): list of sub-versions starting from major version number
version_str (str): version string
-
ck.kernel.
guide
(i)[source]¶ - Open web browser with the user/developer guide wiki
- Target audience: CK kernel and low-level developers
Parameters: (dict) – empty dict Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
help
(i)[source]¶ - CK action: print help for a given module
- Target audience: end users
Parameters: (module_uoa) (str) – CK module UOA Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
help (str): string with the help text
-
ck.kernel.
index_module
(module_uoa, repo_uoa)[source]¶ - Support function for checking whether to index data using ElasticSearch or not …
Target audience: CK kernel and low-level developers
Useful to skip some sensitive data from global indexing.
Parameters: - module_uoa (str) – CK module UID or alias
- repo_uoa (str) – CK repo UID or alias
Returns: (bool) – True if needs to index
-
ck.kernel.
info
(i)[source]¶ - CK action: print CK info about a given CK entry
- Target audience: end users
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- (data_uoa) (str) – CK entry (data) UOA
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Keys from the “load” function
-
ck.kernel.
init
(i)[source]¶ - Inititalize CK (current instance - has a global state!)
- Target audience: internal use
Parameters: (dict) – empty dict Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
inp
(i)[source]¶ - Universal input of unicode string in UTF-8 or other format
Target audience: end users
Supports Python 2.x and 3.x
Parameters: text (str) – text to print before the input Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
string (str): entered string
-
ck.kernel.
input_json
(i)[source]¶ - Input JSON from console (double enter to finish)
- Target audience: end users
Parameters: text (str) – text to print Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
string (str): entered string
dict (str): dictionary from JSON string
-
ck.kernel.
is_uid
(s)[source]¶ - Check if a string is a valid CK UID
- Target audience: end users
Parameters: s (str) – string Returns: (bool) – True if a string is a valid CK UID
-
ck.kernel.
is_uoa
(s)[source]¶ - Check if string is correct CK UOA, i.e. it does not have special characters including *, ?
- Target audience: end users
Parameters: s (str) – string Returns: (bool) – True if a string is a valid CK UID or alias
-
ck.kernel.
jerr
(r)[source]¶ - Print error message for CK functions in the Jupyter Notebook and raise KeyboardInterrupt
Target audience: end users
Used in Jupyter Notebook
- Example:
import ck.kernel as ck
r=ck.access({‘action’:’load’, ‘module_uoa’:’tmp’, ‘data_uoa’:’some tmp entry’})
if r[‘return’]>0: ck.jerr(r)
Parameters: r (dict) – output dictionary of any standard CK function:
- return (int): return code
- (error) (str): error string if return>0
Returns: None - exits script with KeyboardInterrupt!
-
ck.kernel.
list_actions
(i)[source]¶ - List actions in the given CK module
- Target audience: should use via ck.kernel.access
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – must be “module”
- data_uoa (str) – UOA of the module for the new action
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
actions (dict): dict with actions in the given CK module
-
ck.kernel.
list_all_files
(i)[source]¶ - List all files recursively in a given directory
- Target audience: all users
Parameters: - path (str) – top level path
- (file_name) (str) – search for a specific file name
- (pattern) (str) – return only files with this pattern
- (path_ext) (str) – path extension (needed for recursion)
- (limit) (str) – limit number of files (if directories with a large number of files)
- (number) (int) – current number of files
- (all) (str) – if ‘yes’ do not ignore special directories (like .cm)
- (ignore_names) (list) – list of names to ignore
- (ignore_symb_dirs) (str) – if ‘yes’, ignore symbolically linked dirs (to avoid recursion such as in LLVM)
- (add_path) (str)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
- list (dict): dictionary of all files:
{“file_with_full_path”:{“size”:.., “path”:..}
sizes (dict): sizes of all files (the same order as above “list”)
number (int): (internal) total number of files in a current directory (needed for recursion)
-
ck.kernel.
list_data
(i)[source]¶ - List CK entries
- Target audience: CK kernel and low-level developers
Parameters: - (repo_uoa) (str) – CK repo UOA with wildcards
- (module_uoa) (str) – CK module UOA with wildcards
- (data_uoa) (str) – CK entry (data) UOA with wildcards
- (repo_uoa_list) (list) – list of CK repos to search
- (module_uoa_list) (list) – list of CK modules to search
- (data_uoa_list) (list) – list of CK entries to search
- (filter_func) (str) – name of the filter function to customize search
- (filter_func_addr) (obj) – Python address of the filter function
- (add_if_date_before) (str) – add only entries with date before this date
- (add_if_date_after) (str) – add only entries with date after this date
- (add_if_date) (str) – add only entries with this date
- (ignore_update) (str) – if ‘yes’, do not add info about update (when updating in filter)
- (search_by_name) (str) – search by name
- (search_dict) (dict) – search if this dict is a part of the entry
- (ignore_case) (str) – ignore string case when searching!
- (print_time) (str) – if ‘yes’, print elapsed time at the end
- (do_not_add_to_lst) (str) – if ‘yes’, do not add entries to lst
- (time_out) (float) – in secs, default=30 (if -1, no timeout)
- (limit_size) (int) – if >0, limit the number of returned entries
- (print_full) (str) – if ‘yes’, show CID (repo_uoa:module_uoa:data_uoa) or
- (all) (str) – the same as above
- (print_uid) (str) – if ‘yes’, print UID in brackets
- (print_name) (str) – if ‘yes’, print name (and add info to the list) or
- (name) (str) – the same as above
- (add_info) (str) – if ‘yes’, add info about entry to the list
- (add_meta) (str) – if ‘yes’, add meta about entry to the list
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
- lst (list): [{‘repo_uoa’, ‘repo_uid’,
’module_uoa’, ‘module_uid’, ‘data_uoa’,’data_uid’, ‘path’ (,meta) (,info) …
}]
elapsed_time (float): elapsed time in string
(timed_out) (str): if ‘yes’, timed out or limited by size
}
-
ck.kernel.
list_files
(i)[source]¶ - List files in a given CK entry
- Target audience: end users
Parameters: - (repo_uoa) (str) – CK repo UOA
- (module_uoa) (str) – CK module UOA
- (data_uoa) – CK entry (data) UOA
- See other keys for the “list_all_files” function
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output from the “list_al_files” function
- CK action: list tags in found CK entries (uses search function)
- Target audience: should use via ck.kernel.access
Parameters: The same as in “search” function Returns: (dict) – Unified CK dictionary:- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
tags (list): sorted list of all found tags
The same as from “search” function
}
-
ck.kernel.
load
(i)[source]¶ - CK action: load meta description from the CK entry
- Target audience: should use via ck.kernel.access
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK entry (data) UOA
- (get_lock) (str) – if ‘yes’, lock this entry
- (lock_retries) (int) – number of retries to aquire lock (default=5)
- (lock_retry_delay) (float) – delay in seconds before trying to aquire lock again (default=10)
- (lock_expire_time) (float) – number of seconds before lock expires (default=30)
- (skip_updates) (str) – if ‘yes’, do not load updates
- (skip_desc) (str) – if ‘yes’, do not load descriptions
- (load_extra_json_files) (str) – list of files to load from the entry
- (unlock_uid) (str) – UID of the lock to release it
- (min) (str) – show minimum when output to console (i.e. meta and desc)
- (create_if_not_found) (str) – if ‘yes’, create, if entry is not found - useful to create and lock entries
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
dict (dict): CK entry meta description
(info) (dict): CK entry info
(updates) (dict): CK entry updates
(desc) (dict): CK entry description
path (str): path to the CK entry
path_module (str): path to the CK module entry for this CK entry
path_repo (str): path to the CK repository for this CK entry
repo_uoa (str): CK repo UOA
repo_uid (str): CK repo UID
repo_alias (str): CK repo alias
module_uoa (str): CK module UOA
module_uid (str): CK module UID
module_alias (str): CK module alias
data_uoa (str): CK entry (data) UOA
data_uid (str): CK entry (data) UID
data_alias (str): CK entry (data) alias
data_name (str): CK entry user friendly name
(extra_json_files) (dict): merged dict from JSON files specified by ‘load_extra_json_files’ key
(lock_uid) (str): unlock UID, if locked successfully
-
ck.kernel.
load_json_file
(i)[source]¶ - Load json from file into dict
- Target audience: end users
Parameters: json_file (str) – name of a json file Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
dict (dict or list): dict or list from the json file
-
ck.kernel.
load_meta_from_path
(i)[source]¶ - Load CK meta description from a path
- Target audience: CK kernel and low-level developers
Parameters: - path (str) – path to a data entry
- (skip_updates) (str) – if ‘yes’, do not load updates
- (skip_desc) (str) – if ‘yes’, do not load descriptions to be able to handle many entries (similar to Mediawiki)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
dict (dict): dict with CK meta description
path (str): path to json file with meta description
(info) (dict): dict with CK info (provenance) if exists
(path_info) (str): path to json file with info
(updates) (dict): dict with updates if exists
(path_updates) (str): path to json file with updates
(path_desc) (str): path to json file with API description
-
ck.kernel.
load_module_from_path
(i)[source]¶ - Load (CK) python module
- Target audience: end users
Parameters: - path (str) – path to a Python module
- module_code_name (str) – Python module name
- (cfg) (dict) – CK module configuration if exists
- (skip_init) (str) – if ‘yes’, skip init of the CK module
- (data_uoa) (str) – CK module UOA (useful when printing errors)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
code (obj): Python code object
path (str): full path to the module
cuid (str): automatically generated unique ID for the module in the internal cache of modules
-
ck.kernel.
load_repo_info_from_cache
(i)[source]¶ - Load repo meta description from cache
- Target audience: CK kernel and low-level developers
Parameters: repo_uoa (str) – CK repo UOA Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
repo_uoa (str): CK repo UOA
repo_uid (str): CK repo UID
repo_alias (str): CK repo alias
all other keys from repo dict
-
ck.kernel.
load_text_file
(i)[source]¶ - Load a text file to a string or list
- Target audience: end users
Parameters: - text_file (str) – name of a text file
- (keep_as_bin) (str) – if ‘yes’, return only bin
- (encoding) (str) – by default ‘utf8’, however sometimes we use utf16
- (split_to_list) (str) – if ‘yes’, split to list
- (convert_to_dict) (str) – if ‘yes’, split to list and convert to dict
- (str_split) (str) – if !=’’, use as separator of keys/values when converting to dict
- (remove_quotes) (str) – if ‘yes’, remove quotes from values when converting to dict
- (delete_after_read) (str) – if ‘yes’, delete file after read (useful when reading tmp files)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
bin (byte): loaded text file as byte array
(string) (str): loaded text as string with removed
(lst) (list): if split_to_list==’yes’, split text to list
(dict) (dict): if convert_to_dict==’yes’, return as dict
-
ck.kernel.
load_yaml_file
(i)[source]¶ - Load YAML file to dict
- Target audience: end users
Parameters: yaml_file (str) – name of a YAML file Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
dict (dict): dict from a YAML file
-
ck.kernel.
lower_list
(lst)[source]¶ - Support function to convert all strings into lower case in a list
- Target audience: internal
Parameters: lst (list) – list of strings Returns: (list) – list of lowercased strings
-
ck.kernel.
merge_dicts
(i)[source]¶ - Merge intelligently dict1 with dict2 key by key in contrast with dict1.update(dict2)
Target audience: end users
It can merge sub-dictionaries and lists instead of substituting them
Parameters: - dict1 (dict) – merge this dict with dict2 (will be directly modified!)
- dict2 (dict) – dict to be merged
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
dict1 (dict): dict1 passed through the function
-
ck.kernel.
move
(i)[source]¶ - CK action: move CK entry to another CK repository
- Target audience: should use via ck.kernel.access
Parameters: See “mv” function Returns: See “mv” function
-
ck.kernel.
mv
(i)[source]¶ - CK action: move CK entry to another CK repository
- Target audience: should use via ck.kernel.access
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK entry (data) UOA
- xcids (list) – use original name from xcids[0] and new name from xcids[1] ({‘repo_uoa’, ‘module_uoa’, ‘data_uoa’}) or
- (new_repo_uoa) (str) – new CK repo UOA
- (new_module_uoa) (str) – new CK module UOA
- (new_data_uoa) (str) – new CK data alias
- (new_data_uid) (str) – new CK entry (data) UID (leave empty to generate the new one)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output from the “copy” function
-
ck.kernel.
out
(s)[source]¶ - Universal print of a unicode string in UTF-8 or other format
Target audience: end users
Supports: Python 2.x and 3.x
Parameters: s (str) – unicode string to print Returns: None
-
ck.kernel.
parse_cid
(i)[source]¶ - Convert CID to a dict and add missing parts in CID from the current path
- Target audience: CK kernel and low-level developers
Parameters: - cid (str) – in format (REPO_UOA:)MODULE_UOA:DATA_UOA
- (cur_cid) (str) – output from the “detect_cid_in_current_path” function
- (ignore_error) (str) – if ‘yes’, ignore wrong format
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
data_uoa (str): CK data UOA
module_uoa (str): CK module UOA
(repo_uoa) (str): CK repo UOA
-
ck.kernel.
path
(i)[source]¶ - CK action: get CID from the current path
- Target audience: end users
Parameters: (dict) – empty dict Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
Keys from the “detect_cid_in_current_path” function
-
ck.kernel.
perform_action
(i)[source]¶ - Perform an automation action via CK kernel or from the kernel
- Target audience: CK kernel and low-level developers
Parameters: () – all parameters from the “access” function
(web) (str) – if ‘yes’, called from the web
(common_func) (str) –
- if ‘yes’, ignore search for modules
and call common func from the CK kernel
or
(kernel) (str) – the same as above
(local) (str) – if ‘yes’, run locally even if remote repo …
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
(out) (str): if action changes output, log it
Output from a given action
}
-
ck.kernel.
perform_remote_action
(i)[source]¶ - Perform remote action via CK web service
- Target audience: CK kernel and low-level developers
Parameters: See “perform_action” function Returns: See “perform_action” function
-
ck.kernel.
prepare_special_info_about_entry
(i)[source]¶ - Prepare provenance for a given CK entry (CK used, author, date, etc)
- Target audience: end users
Parameters: i (dict) – empty dict Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
dict (dict): dictionary with provenance information
-
ck.kernel.
print_input
(i)[source]¶ - Print input dictionary to screen for debugging
Target audience: CK kernel and low-level developers
Used in console and web applications
Parameters: (dict) – input Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
html (str): input as JSON string
-
ck.kernel.
pull
(i)[source]¶ - Pull CK entries from the CK server
- Target audience: CK kernel and low-level developers
Parameters: (repo_uoa) (str) – CK repo UOA
module_uoa (str) – must be “module”
data_uoa (str) – UOA of the module for the new action
(filename) (str) –
- filename (with path) (if empty, set archive to ‘yes’).
If empty, create an archive of the entry
or
(cid[0]) (str)
(archive) (str) – if ‘yes’ pull whole entry as zip archive using filename or ck_archive.zip
(all) (str) – if ‘yes’ and archive, add even special directories (.cm, .svn, .git, etc)
(out) (str) – if ‘json’ or ‘json_file’, encode file and return in r
(skip_writing) (str) – if ‘yes’, do not write file (not archive) to current directory
(pattern) (str) – return only files with this pattern
(patterns) (str) – multiple patterns (useful to pack mutiple points in experiments)
(encode_file) (str) – if ‘yes’, encode file
(skip_tmp) (str) – if ‘yes’, skip tmp files and directories
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
actions (dict): dict with actions in the given CK module
(file_content_base64) (str): if i[‘to_json’]==’yes’, encoded file
(filename) (str): filename to record locally
-
ck.kernel.
push
(i)[source]¶ - Push CK entry to the CK server
- Target audience: CK kernel and low-level developers
Parameters: (repo_uoa) (str) – CK repo UOA
module_uoa (str) – must be “module”
data_uoa (str) – UOA of the module for the new action
(filename) (str) –
- filename (with path) (if empty, set archive to ‘yes’).
If empty, create an archive of the entry
or
(cid[0]) (str)
(extra_path) (str) – extra path inside entry (create if doesn’t exist)
(file_content_base64) (str) – if !=’’, take its content and record into filename
(archive) (str) – if ‘yes’ push to entry and unzip …
(overwrite) (str)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
pwiki
(i)[source]¶ - Open web browser with the private discussion wiki page for a given CK entry
Target audience: CK kernel and low-level developers
URL is taken from default kernel configuration cfg[‘private_wiki_data_web’]
Parameters: - (repo_uoa) (str) – CK repo UOA
- (module_uoa) (str) – CK module UOA
- (data_uoa) (str) – CK entry (data) UOA
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
python_version
(i)[source]¶ - CK action: print python version used by CK
- Target audience: end users
Parameters: (dict) – empty dict Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
version (str): sys.version
version_info (str): sys.version_info
-
ck.kernel.
reinit
()[source]¶ - Reinitialize CK
- Target audience: end users
Parameters: None Returns: (dict) – output from the “init” function
-
ck.kernel.
reload_repo_cache
(i)[source]¶ - Reload cache with meta-descriptions of all CK repos
- Target audience: CK kernel and low-level developers
Parameters: (force) (str) – if ‘yes’, force recaching Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
remove
(i)[source]¶ - CK action: delete CK entry or CK entries
- Target audience: should use via ck.kernel.access
Parameters: See “rm” function Returns: See “rm” function
-
ck.kernel.
remove_action
(i)[source]¶ - Remove an action from the given module
- Target audience: should use via ck.kernel.access
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – must be “module”
- data_uoa (str) – UOA of the module for the new action
- func (str) – action name
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output from the ‘update’ function for the given CK module
-
ck.kernel.
ren
(i)[source]¶ - CK action: rename CK entry
- Target audience: should use via ck.kernel.access
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK entry (data) UOA
- new_data_uoa (str) – new CK entry (data) alias or
- new_data_uid (str) – new CK entryt (data) UID (leave empty to keep the old one) or
- xcids (list) – take new CK entry UOA from xcids[0][‘data_uoa’]
- (new_uid) (str) – if ‘yes’, generate new UID
- (remove_alias) (str) – if ‘yes’, remove alias
- (add_uid_to_alias) (str) – if ‘yes’, add UID to alias
- (share) (str) – if ‘yes’, try to remove the old entry via GIT and add the new one
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
rename
(i)[source]¶ - CK action: rename CK entry
- Target audience: should use via ck.kernel.access
Parameters: See “ren” function Returns: See “ren” function
-
ck.kernel.
restore_flattened_dict
(i)[source]¶ - Restore flattened dict
- Target audience: end users
Parameters: dict (dict) – CK flattened dictionary Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
dict (dict): restored dict
-
ck.kernel.
restore_state
(r)[source]¶ - Restore CK state
- Target audience: end users
Parameters: r (dict) – saved CK state Returns: (dict) – output from the “init” function
-
ck.kernel.
rm
(i)[source]¶ - CK action: delete CK entry or CK entries
- Target audience: should use via ck.kernel.access
Parameters: - (repo_uoa) (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK entry (data) UOA
- (force) (str) – if ‘yes’, force deleting without questions or
- (f) (str) – to be compatible with rm -f
- (share) (str) – if ‘yes’, try to remove via GIT
- (tags) (str) – use these tags in format tags=x,y,z to prune rm or
- (search_string) (str)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
run_and_get_stdout
(i)[source]¶ - Run command and log stdout and stdout
- Target audience: end users
Parameters: - cmd (list) – list of command line arguments, starting with the command itself
- (shell) (str) – if ‘yes’, reuse shell environment
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
return_code (int): return code from the os.system call
stdout (str): standard output of the command
stderr (str): standard error of the command
-
ck.kernel.
safe_float
(i, d)[source]¶ - Support function for safe float (useful for sorting function)
- Target audience: end users
Parameters: - i (any) – variable with any type
- d (float) – default value
Returns: (float) – returns i if it can be converted to float or d otherwise
-
ck.kernel.
safe_get_val_from_list
(lst, index, default_value)[source]¶ - Support function to get value from list without error if out of bounds
Target audience: end users
Useful for sorting functions.
Parameters: - lst (list) – list of values
- index (int) – index in a list
- default_value (any) – if index inside list, return lst[index] or default value otherwise
Returns: (int) – returns i if it can be converted to int, or d otherwise
-
ck.kernel.
safe_int
(i, d)[source]¶ - Support function for safe int (useful for sorting function)
- Target audience: end users
Parameters: - i (any) – variable with any type
- d (int) – default value
Returns: (int) – returns i if it can be converted to int, or d otherwise
-
ck.kernel.
save_json_to_file
(i)[source]¶ - Save dict to a json file
- Target audience: end users
Parameters: - json_file (str) – filename to save dictionary
- dict (dict) – dict to save
- (sort_keys) (str) – if ‘yes’, sort keys
- (safe) (str) – if ‘yes’, ignore non-JSON values (only for Debugging - changes original dict!)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
save_repo_cache
(i)[source]¶ - Save cache with meta-descriptions of all CK repos
- Target audience: CK kernel and low-level developers
Parameters: (dict) – empty dict Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
save_state
()[source]¶ - Save CK state
Target audience: end users
FGG: note that in the future we want to implement CK kernel as a Python class where we will not need such save/restore state …
Parameters: None Returns: (dict) – current CK state
-
ck.kernel.
save_text_file
(i)[source]¶ Save string to a text file with all removed
Target audience: end users- Args:
- text_file (str): name of a text file string (str): string to write to a file (all
- will be removed)
- (append) (str): if ‘yes’, append to a file
- Returns:
(dict): Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
save_yaml_to_file
(i)[source]¶ - Save dict to a YAML file
- Target audience: end users
Parameters: - yaml_file (str) – name of a YAML file
- dict (dict) – dict to save
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
search
(i)[source]¶ - CK action: search CK entries
- Target audience: should use via ck.kernel.access
Parameters: - (repo_uoa) (str) – CK repo UOA with wildcards
- (module_uoa) (str) – CK module UOA with wildcards
- (data_uoa) (str) – CK entry (data) UOA with wildcards
- (repo_uoa_list) (list) – list of CK repos to search
- (module_uoa_list) (list) – list of CK modules to search
- (data_uoa_list) (list) – list of CK entries to search
- (filter_func) (str) – name of the filter function to customize search
- (filter_func_addr) (obj) – Python address of the filter function
- (add_if_date_before) (str) – add only entries with date before this date
- (add_if_date_after) (str) – add only entries with date after this date
- (add_if_date) (str) – add only entries with this date
- (ignore_update) (str) – if ‘yes’, do not add info about update (when updating in filter)
- (search_by_name) (str) – search by name
- (search_dict) (dict) – search if this dict is a part of the entry
- (ignore_case) (str) – ignore string case when searching!
- (print_time) (str) – if ‘yes’, print elapsed time at the end
- (do_not_add_to_lst) (str) – if ‘yes’, do not add entries to lst
- (time_out) (float) – in secs, default=30 (if -1, no timeout)
- (print_full) (str) – if ‘yes’, show CID (repo_uoa:module_uoa:data_uoa) or
- (all) (str) – the same as above
- (print_uid) (str) – if ‘yes’, print UID in brackets
- (print_name) (str) – if ‘yes’, print name (and add info to the list) or
- (name) (str) – the same as above
- (add_info) (str) – if ‘yes’, add info about entry to the list
- (add_meta) (str) – if ‘yes’, add meta about entry to the list
- (internal) (str) – if ‘yes’, use internal search even if indexing is on
- (limit_size) (int) – limit the number of returned entries. Use 5000 by default or set to -1 if no limit
- (start_from) (int) – start from a specific entry (only for ElasticSearch)
- (debug) (str) – if ‘yes’, print debug info
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
- lst (list): [{‘repo_uoa’, ‘repo_uid’,
’module_uoa’, ‘module_uid’, ‘data_uoa’,’data_uid’, ‘path’ (,meta) (,info) …
}]
elapsed_time (float): elapsed time in string
(timed_out) (str): if ‘yes’, timed out or limited by size
}
-
ck.kernel.
search_filter
(i)[source]¶ - Search filter
- Target audience: CK kernel and low-level developers
Parameters: - repo_uoa (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK entry (data) UOA
- path (str) – path to the current entry
- (search_dict) (dict) – check if this dict is a part of the entry meta description
- (ignore_case) (str) – if ‘yes’, ignore case of letters
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
skip (str): if ‘yes’, skip this entry from search
-
ck.kernel.
search_string_filter
(i)[source]¶ - Search filter
- Target audience: CK kernel and low-level developers
Parameters: - repo_uoa (str) – CK repo UOA
- module_uoa (str) – CK module UOA
- data_uoa (str) – CK data UOA
- path (str) – path to the current CK entry
- (search_string) - search with expressions *?
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
skip (str): if ‘yes’ then skip this entry from search
-
ck.kernel.
select
(i)[source]¶ - Universal selector of a dictionary key
Target audience: end users
Note: advanced version available in the CK module “choice”
Parameters: - dict (dict) – dict with values being dicts with ‘name’ as string to display and ‘sort’ as int (for ordering)
- (title) (str) – print title
- (error_if_empty) (str) – if ‘yes’ and just Enter, return error
- (skip_sort) (str) – if ‘yes’, do not sort dictionary keys
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
string (str): selected dictionary key
-
ck.kernel.
select_uoa
(i)[source]¶ - Universal CK entry UOA selector
Target audience: end users
Note: advanced version available in the CK module “choice”
Parameters: - choices (list) – list from the search function
- (skip_enter) (str) – if ‘yes’, do not select 0 when a user presses Enter
- (skip_sort) (str) – if ‘yes’, do not sort list
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
choice (str): CK entry UOA
-
ck.kernel.
set_by_flat_key
(i)[source]¶ - Set a value in a dictionary using the CK flat key
- Target audience: end users
Parameters: - dict (dict) – dictionary
- key (str) – CK flat key
- value (any) – value to set
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
dict (dict): modified dict
-
ck.kernel.
set_lock
(i)[source]¶ - Set a lock in a given path (to handle parallel writes to CK entries)
- Target audience: CK kernel and low-level developers
Parameters: - path (str) – path to be locked
- (get_lock) (str) – if ‘yes’, lock this entry
- (lock_retries) (int) – number of retries to aquire lock (default=11)
- (lock_retry_delay) (float) – delay in seconds before trying to aquire lock again (default=3)
- (lock_expire_time) (float) – number of seconds before lock expires (default=30)
- (unlock_uid) (str) – UID of the lock to release it
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
(lock_uid) (str): lock UID, if locked successfully
-
ck.kernel.
short_help
(i)[source]¶ - Print short CK help
- Target audience: end users
Parameters: (dict) – empty dict Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
help (str): string with the help text
-
ck.kernel.
split_name
(name, number)[source]¶ - Support function to split entry name (if needed)
- Target audience: CK kernel and low-level developers
Parameters: - name (str) – CK entry name
- number (int) – Split number (do not split if 0)
Returns: - (
name1 (str): first part of splitted name
name2 (str): second part of splitted name
)
-
ck.kernel.
status
(i)[source]¶ - CK action: check CK server status
- Target audience: CK kernel and low-level developers
Parameters: (dict) – empty dict Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
outdated (str): if ‘yes’, newer version exists
-
ck.kernel.
substitute_str_in_file
(i)[source]¶ - Substitute string in a file
- Target audience: end users
Parameters: - filename (str) – filename
- string1 (str) – string to be replaced
- string2 (str) – replacement string
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
system_with_timeout
(i)[source]¶ - os.system with time out
- Target audience: end users
Parameters: - cmd (str) – command line
- (timeout) (float) – timeout in seconds (granularity 0.01 sec) - may cause some overheads …
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
return_code (int): return code from the os.system call
-
ck.kernel.
system_with_timeout_kill
(proc)[source]¶ - Support function to safely terminate a given process
- Target audience: end users
Parameters: proc (obj) – process object Returns: None
-
ck.kernel.
uid
(i)[source]¶ - CK action: generate CK UID
- Target audience: end users
Parameters: (dict) – empty dict Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
data_uid (str): UID in string format (16 lowercase characters 0..9,a..f)
-
ck.kernel.
unzip_file
(i)[source]¶ - Unizip archive file to a given path
- Target audience: end users
Parameters: - archive_file (str) – full path to a zip file
- (path) (str) – path where to unzip (use current path if empty)
- (overwrite) (str) – if ‘yes’, overwrite existing files
- (delete_after_unzip) (str)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
skipped (list): list of files that were not overwritten
-
ck.kernel.
update
(i)[source]¶ - CK action: update CK entry meta-description
- Target audience: should use via ck.kernel.access
Parameters: (repo_uoa) (str) – CK repo UOA
module_uoa (str) – CK module UOA
data_uoa (str) – CK entry (data) UOA
(data_uid) (str) – CK entry (data) UID (if UOA is an alias)
(data_name) (str) – User-friendly name of this entry
(dict) (dict) – meta description for this entry (will be recorded to meta.json)
(substitute) (str) – if ‘yes’ and update==’yes’ substitute dictionaries, otherwise merge!
(dict_from_cid) (str) – if !=””, merge dict to meta description from this CID (analog of copy)
(dict_from_repo_uoa) (str) – merge dict from this CK repo UOA
(dict_from_module_uoa) (str) – merge dict from this CK module UOA
(dict_from_data_uoa) (str) – merge dict from this CK entry UOA
(desc) (dict) – under development - defining SPECs for meta description in the CK flat format
(extra_json_files) (dict) – dict with extra json files to save to this CK entry (keys in this dictionary are filenames)
(tags) (str) – list or comma separated list of tags to add to entry
(info) (dict) – entry info to record - normally, should not use it!
(extra_info) (dict) –
enforce extra info such as
- author
- author_email
- author_webpage
- license
- copyright
If not specified then take it from the CK kernel (prefix ‘default_’)
(updates) (dict) – entry updates info to record - normally, should not use it!
(ignore_update) (str) – if ‘yes’, do not add info about update
(ask) (str) – if ‘yes’, ask questions, otherwise silent
(unlock_uid) (str) – unlock UID if was previously locked
(sort_keys) (str) – by default, ‘yes’
(share) (str) – if ‘yes’, try to add via GIT
(skip_indexing) (str) – if ‘yes’, skip indexing even if it is globally on
(allow_multiple_aliases) (str) – if ‘yes’, allow multiple aliases for the same UID (needed for cKnowledge.io to publish renamed components with the same UID)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output from the “add” function (the last “add” in case of wildcards)
-
ck.kernel.
version
(i)[source]¶ - CK action: print CK version
- Target audience: end users
Parameters: (dict) – empty dict Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
version (list): list of sub-versions starting from major version number
version_str (str): version string
-
ck.kernel.
webapi
(i)[source]¶ - Open web browser with the API page if exists
- Target audience: CK kernel and low-level developers
Parameters: (dict) – from the “access” function(repo_uoa) (str): CK repo UOA Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
webhelp
(i)[source]¶ - Open web browser with the help page for a given CK entry
- Target audience: CK kernel and low-level developers
Parameters: (dict) – from the “access” function Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
wiki
(i)[source]¶ - Open web browser with the discussion wiki page for a given CK entry
Target audience: CK kernel and low-level developers
URL is taken from default kernel configuration cfg[‘wiki_data_web’]
Parameters: - (repo_uoa) (str) – CK repo UOA
- (module_uoa) (str) – CK module UOA
- (data_uoa) (str) – CK entry (data) UOA
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.kernel.
zip
(i)[source]¶ - Zip CK entries
- Target audience: CK kernel and low-level developers
Parameters: - (repo_uoa) (str) – CK repo UOA with wild cards
- (module_uoa) (str) – CK module UOA with wild cards
- (data_uoa) (str) – CK entry (data) UOA with wild cards
- (archive_path) (str) – if ‘’ create inside repo path
- (archive_name) (str) – if !=’’ use it for zip name
- (auto_name) (str) – if ‘yes’, generate name name from data_uoa: ckr-<repo_uoa>.zip
- (bittorent) (str) – if ‘yes’, generate zip name for BitTorrent: ckr-<repo_uid>-YYYYMMDD.zip
- (overwrite) (str) – if ‘yes’, overwrite zip file
- (store) (str) – if ‘yes’, store files instead of packing
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
ck.files module¶
-
ck.files.
load_json_file
(i)[source]¶ - Load json from file into dict
- Target audience: end users
Parameters: json_file (str) – name of a json file Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
dict (dict or list): dict or list from the json file
-
ck.files.
load_text_file
(i)[source]¶ - Load a text file to a string or list
- Target audience: end users
Parameters: - text_file (str) – name of a text file
- (keep_as_bin) (str) – if ‘yes’, return only bin
- (encoding) (str) – by default ‘utf8’, however sometimes we use utf16
- (split_to_list) (str) – if ‘yes’, split to list
- (convert_to_dict) (str) – if ‘yes’, split to list and convert to dict
- (str_split) (str) – if !=’’, use as separator of keys/values when converting to dict
- (remove_quotes) (str) – if ‘yes’, remove quotes from values when converting to dict
- (delete_after_read) (str) – if ‘yes’, delete file after read (useful when reading tmp files)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
bin (byte): loaded text file as byte array
(string) (str): loaded text as string with removed
(lst) (list): if split_to_list==’yes’, split text to list
(dict) (dict): if convert_to_dict==’yes’, return as dict
-
ck.files.
load_yaml_file
(i)[source]¶ - Load YAML file to dict
- Target audience: end users
Parameters: yaml_file (str) – name of a YAML file Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
dict (dict): dict from a YAML file
-
ck.files.
save_json_to_file
(i)[source]¶ - Save dict to a json file
- Target audience: end users
Parameters: - json_file (str) – filename to save dictionary
- dict (dict) – dict to save
- (sort_keys) (str) – if ‘yes’, sort keys
- (safe) (str) – if ‘yes’, ignore non-JSON values (only for Debugging - changes original dict!)
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
-
ck.files.
save_text_file
(i)[source]¶ Save string to a text file with all removed
Target audience: end users- Args:
- text_file (str): name of a text file string (str): string to write to a file (all
- will be removed)
- (append) (str): if ‘yes’, append to a file
- Returns:
(dict): Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.files.
save_yaml_to_file
(i)[source]¶ - Save dict to a YAML file
- Target audience: end users
Parameters: - yaml_file (str) – name of a YAML file
- dict (dict) – dict to save
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
ck.net module¶
-
ck.net.
access_ck_api
(i)[source]¶ - Universal web request to the CK server (usually cKnowledge.io)
- Target audience: CK kernel and low-level developers
Parameters: - url (str) – URL API
- (dict) (dict) – dict to send to above URL
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
dict (dict): dictionary from the CK server
-
ck.net.
request
(i)[source]¶ - Web request to cKnowledge.org server
- Target audience: CK kernel and low-level developers
Parameters: - get (dict) – GET parameters
- post (dict) – POST parameters
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
string (str): returned string from the server dict (dict): JSON string converted to dict (if possible)
ck.strings module¶
-
ck.strings.
convert_json_str_to_dict
(i)[source]¶ - Convert string in a special format to dict (JSON)
- Target audience: end users
Parameters: str (str) – string (use ‘ instead of “, i.e. {‘a’:’b’} to avoid issues in CMD in Windows and Linux!) Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
dict (dict): dict from json file
-
ck.strings.
copy_to_clipboard
(i)[source]¶ - Copy string to clipboard if supported by OS (requires Tk or pyperclip)
- Target audience: end users
Parameters: string (str) – string to copy Returns: (dict) – Unified CK dictionary:
- return (int): return code = 0, if successful
- > 0, if error
(error) (str): error text if return > 0
-
ck.strings.
dump_json
(i)[source]¶ - Dump dictionary (json) to a string
- Target audience: end users
Parameters: - dict (dict) – dictionary to convert to a string
- (skip_indent) (str) – if ‘yes’, skip indent
- (sort_keys) (str) – if ‘yes’, sort keys
Returns: (dict) –
Unified CK dictionary:
- return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
string (str): JSON string