
| def cm::access | ( | i | ) |
Single entry point to access all cM functions.
Input: {
Set of global cM variables:
cm_run_module_uoa - UOA of the module to run
cm_action - module action (function)
(cm_console) - by default, do not output anything except errors
if 'txt' then output as plain text
if 'web' then output for web (html, image, etc)
if 'json' then output as json
cm_web - if 'yes', function was called from web environment
cm_web_preprocess - if 'yes', we in the preprocessing stage in the web environment,
where we can still change the http headers, etc ...
If cM Web access or fully remote access:
cm_user_uoa - user UOA
If requires user authentication in web environment!
After authentication, passwords will be removed from the array
cm_user_password - user password in plain text
(not secure, usually used for web form authentication)
cm_user_password1 - user password in SHA1
(more secure, can be stored in environment, session or cookies)
cM authenicates by taking SHA1(cm_user_password1)...
If access to remote repository or fully remote access:
cm_remote_user_uoa - remote user UOA
cm_remote_user_password - remote user password
Set of parameters depending on the called module and action (function)
}
Output: {
cm_return - return code = 0 if successful
> 0 if error
< 0 if warning (rarely used at this moment)
(cm_error) - error text, if cm_return > 0
Set of output parameters depending on the called module and action (function)
}
| def cm::access_control | ( | i | ) |
Control access
Input: {
dcfg - cfg of the current entry
module_uoa - module UOA of the entry
module_uid - module UID of the entry
data_uoa - data UOA of the entry
key - 'read' or 'write'
}
Output: {
cm_return - 0, if Ok; ==32 if access denied
cm_error - if access is denied
}
| def cm::access_fe | ( | i | ) |
| def cm::access_fe_as_string | ( | s | ) |
| def cm::access_fe_from_cmd | ( | a | ) |
Front-end to single entry 'access' function from command line (bash, windows shell, etc) If cm_console=='', it will be set to 'txt' If cm_user_uoa and cm_user_password1 are not in input but in environment, they will be also used Input: cmd list that will be converted to array (See "access" function) Output: See "access" function
| def cm::access_fe_through_cmd | ( | i | ) |
FGG TBD: Currently used only in cM web server.
Should be cleaned and updated!
Should check that tmp files are deleted!
Main function to access cM through a command line (useful for web server, etc).
Input: {
... - see "access" function from this module
(cm_detach_console) - if 'yes', detach console (for installations or experiments)
}
Output: {
cm_return - return code = 0 if successful
cm_stdout - stdout
cm_stderr - stderr
}
| def cm::array2cm | ( | a | ) |
Convert list to cm array
cm_module_uoa cm_action A=B C=D ... @file1.json E=F ... -- <unparsed arguments>
if extension of @file is .tmp, it will be deleted after read!
Input: input array
Output: {
cm_return - return code = 0 if successful
cm_array - array
cm_console - if 'cm_console' in array, set it to the value of 'cm_console' parameter
}
| def cm::array2str | ( | i | ) |
| def cm::auth_user | ( | i | ) |
Authenticate user
Input: {
cm_user_uoa - user UOA
cm_user_password - user password in plain text
(not secure, usually used for web form authentication)
cm_user_password1 - user password in SHA1
(more secure, can be stored in environment, session or cookies)
cM authenicates by taking SHA1(cm_user_password1)...
cm_user_password2 - only should be set here by web environment!
}
Output: {
cm_return - return code = 0 if authenticated
(cm_error) - error text, if cm_return > 0
cm_user_cfg - user config if authenticated (to check groups, etc)
cm_user_password2 - user password in SHA1(SHA1)
cm_user_uid - user UID
cm_user_uoa - user UOA
cm_user_alias - user alias
cm_user_path - user path
}
| def cm::auth_user_and_ini_cm | ( | i | ) |
Check if need to auth user, try to auth and set cM vars
Input: {
cm_user_uoa - user UOA
cm_user_password - user password in plain text
(not secure, usually used for web form authentication)
cm_user_password1 - user password in SHA1
(more secure, can be stored in environment, session or cookies)
cM authenicates by taking SHA1(cm_user_password1)...
cm_user_password2 - only should be set here by web environment!
}
Output: {
cm_return - return code = 0 if authenticated
(cm_error) - error text, if cm_return > 0
If needed to auth or default user:
cm_user_cfg - user config if authenticated (to check groups, etc)
cm_user_password1 - user password in SHA1
cm_user_uid - user UID
cm_user_uoa - user UOA
cm_user_alias - user alias
cm_user_path - user path
cm_user_status - 'no_user', 'default', 'logged_in' or 'failed'
}
| def cm::check_cm_json | ( | i | ) |
| def cm::check_global_writing | ( | i | ) |
| def cm::cid2array | ( | i | ) |
| def cm::convert_cm_array_to_uri | ( | i | ) |
Convert cM array to uri (convert various special parameters)
Input: {
cm_array - array to convert to uri
}
Output: {
cm_return - return code (check "access" function for full description)
(cm_error) - error text (check "access" function for full description)
cm_string - converted string
cm_string1 - converted string (for urlopen)
}
| def cm::convert_file_to_upload_string | ( | i | ) |
| def cm::convert_iso_time_to_str | ( | i | ) |
| def cm::convert_str_to_sha1 | ( | i | ) |
Convert string to sha1
Input: {
cm_string - string
}
Output: {
cm_return - return code >0 if not authentificated
cm_string_sha1 - password in SHA1 (digest)
cm_string_sha1_hex - password in SHA1 (digest in hex)
cm_string_sha1_base64 - BASE64 (SHA1 digest) - compatible with htpasswd format
}
| def cm::convert_str_to_special | ( | s | ) |
| def cm::convert_string_to_html | ( | i | ) |
| def cm::convert_text_to_value | ( | i | ) |
| def cm::copy_vars | ( | i | ) |
| def cm::create_data_entry | ( | i | ) |
Create data entry
Input: {
cm_path - path to the repository
cm_module_uoa - module UOA
cm_data_uoa - data UOA
(cm_data_uid) - if cm_data_uoa==alias, we can force a given UID through this variable
(cm_array) - array to add to the entry
If not set, the whole array will be added
including all working variables - we do not suggest to do that
(cm_add_default) - if 'yes', add default params from descriptions (module/kernel)
(cm_update) - if 'yes', update entry
(cm_description) - description of the data entry
(cm_display_as_alias) - user readable alias to display instead of module:data
(cm_skip_update_info) - if == 'yes', do not write 'cm_updated'
(cm_note) - note about this data entry
(cm_like) - if 'yes' add +1 for this user to the entry
(cm_file_upload_tmp_uid) - normally generated automatically by web server
when uploading files
(cm_file_upload_name) - preffered uploaded file name
(cm_file_upload_type) - type of file (if .zip, it will be automatically unziped)
(cm_archive) - if file should be kept as archive
... - if 'cm_array' not present, add everything else from this array
to the entry
(lock_uid) - unlock data
}
Output: {
cm_return - return code >0 if error
-1 if entry exists
cm_path - path to created data entry
cm_uid - uid (from UOA)
cm_alias - alias (from UOA)
}
| def cm::create_default_array_from_description | ( | i | ) |
| def cm::create_entry | ( | i | ) |
Create an UOA entry directory structure.
Input: {
cm_path - path to a repository
(cm_data_uoa) - data UOA
(cm_data_uid) - if cm_data_uoa==alias, we can force a given UID through this variable
(lock_uid) - UID of the aquired lock
}
Output: {
cm_return - return code = 0 if created entry
= -1 if already exist
> 0 if error
cm_path - path to data entry
cm_uid - uid (from UOA)
cm_alias - alias (from UOA)
cm_uoa - alias or uid if alias==''
}
| def cm::delete_alias | ( | i | ) |
| def cm::delete_directory | ( | i | ) |
| def cm::delete_entry | ( | i | ) |
Delete entry
Input: {
cm_path - path to the entry
cm_path_module - part of the path with module
cm_uid - uid (from UOA), needed to delete alias disambiguator if exists
cm_alias - alias (from UOA), needed to delete alias disambiguator if exists
}
Output: {
cm_return - return code >0 if error
}
| def cm::find_index_in_array | ( | i | ) |
Find index in array of formart [{cm_index:'a', ...}, {cm_index='b', ...}, ...]
We use such array instead of simple associative array
when we need to keep an order such as for actions ...
Input: {
cm_array - array of format
cm_index - index
}
Output: {
cm_return - return code = 0 if successful
-1 if not found
cm_array - sub-array with given index
}
| def cm::find_keys_by_prefix | ( | i | ) |
| def cm::find_path_to_current_repository | ( | i | ) |
Finds local repository (recursively checks
all upper directories until it finds the repository)
Input: {
cm_get_uid - if 'yes' load data to get UID besides UOA
}
Output: {
cm_return - return code >0 if error
-1 if doesn't exist
cm_path - path to the local repository
(cm_module_uoa) - module UOA of the current path
(cm_module_uid) - module UID of the current path
(cm_data_uoa) - data UOA of the current path
(cm_data_uid) - data UID of the current path
}
| def cm::find_path_to_entry | ( | i | ) |
Find path to an UOA entry (check UID or alias).
Input: {
cm_path - path to a repository
cm_data_uoa - data UOA
}
Output: {
cm_return - return code = 0 if found path to entry
= -1 if not found path to entry
> 0 if error
cm_path_orig - i['cm_path']
cm_path - path to data entry
cm_uid - uid (from UOA)
cm_alias - alias (from UOA)
cm_uoa - alias or uid, if alias==''
}
| def cm::find_path_to_work_repositories | ( | i | ) |
| def cm::flatten_array | ( | i | ) |
Flatten array
Any list item is converted to @number=value
Any dict item is converted to #key=value
# is always added at the beginning
Input: {
cm_array - full array
prefix - prefix (for recursion)
}
Output: {
cm_return - if =0, success
cm_array - flattened array
}
| def cm::flatten_classification | ( | i | ) |
| def cm::gen_cm_tmp_file | ( | i | ) |
| def cm::gen_uid | ( | i | ) |
| def cm::get_all_uoa | ( | i | ) |
Get a list of all entries in the repository
Input: {
cm_path - path to repository
(cm_module_uoa) - module UOA. If =='', return available modules in the repository
(or use cm_only_available_modules explicitly)
cm_only_uid - 'yes' to show only UIDs
(cm_classes_uoa) - prune by classes UOA
(prune_data_uoa) - prune by data UOA
(cm_only_available_modules) - if 'yes', return only available modules in a given repository
(skip_data_cfg) - if 'yes', do not add data cfg
(cm_admin) - if 'yes', override access control - only internal use,
can not be used during web access (explicitly removed)
}
Output: {
cm_return - return code = 0 if successful
cm_array - list of UOA or only UID
cm_mixed - list of {cm_uid, cm_alias, cm_uoa, cm_display_as_alias, cm_display_html, cm_data_obj_cfg}
}
| def cm::get_cm_version | ( | i | ) |
| def cm::get_current_date_time | ( | i | ) |
| def cm::get_data_description | ( | i | ) |
Get data entry description
Input: {
cm_run_module_uoa | cm_module_uoa - module UOA
(cm_desc_key) - if this key is specified, take description from this key
(cm_flat_desc_key) - if this flat key is specified, take description from this flat key
(cm_action_key) - action key
cm_which_action - action
(cm_key) - if action is specified, use this key instead of default one
}
Output: {
cm_return - return code >0 if error
cm_data_desc - data description
cm_params_default - data description
... - other parameters from load_data
}
| def cm::get_list_of_all_files | ( | i | ) |
Get a list of all files in a given directory recursively
Input: {
cm_path - path
cm_path_ext - path extension
limit - limit number of files (if huge directories)
number - cur. number of files
cm_all_files - if 'yes' do not ignore special files (like .cm)
}
Output: {
cm_return - return code = 0 if successful
cm_array - list of files
}
| def cm::get_value_by_flattened_key | ( | i | ) |
| def cm::get_var | ( | a, | ||
| p | ||||
| ) |
| def cm::init | ( | i | ) |
| def cm::is_uid | ( | str | ) |
| def cm::is_windows | ( | ) |
| def cm::load_array_from_file | ( | i | ) |
| def cm::load_code | ( | i | ) |
| def cm::load_data | ( | i | ) |
Load and cache cM data
Input: {
cm_module_uoa - UOA of the module
cm_data_uoa - UOA of the data
(cm_path) - path to repository
(cm_path_array) - array of paths to search
(lock_acquire) - if 'yes', acquire lock
(lock_retry_num) - number of retries to acquire lock (default=6)
(lock_retry_delay) - delay in sec before retrying to acquire lock (default=11)
(lock_expire) - for how long to acquire lock (secs)
(unlock_uid) - unlock data (FGG note: I changed lock_uid to unlock_uid
not to interfere with update locking)
(cm_admin) - if 'yes', override access control - only internal use,
can not be used during web access (explicitly removed)
}
Output: {
cm_return - return code = 0, if successful
(cm_error) - error text if return code > 0
cm_data_obj - cM data object
cm_path - path to data entry
cm_path_module - path to module entry with this entry
cm_path_repo - path to the repository of this entry
cm_uid - uid (from UOA)
cm_alias - alias (from UOA)
cm_uoa - cm_data_uoa (alias or uid if alias=='')
cm_module_uoa - module UOA
cm_module_uid - module UID
cm_display_as_alias - taken from the data
cm_display_html - prepare display: "display as alias" or <I>alias</I> or UID
(lock_uid) - UID of the aquired lock
}
| def cm::load_json_file | ( | i | ) |
| def cm::load_module | ( | i | ) |
Load and cache cM module
Input: {
cm_module_uoa - UOA of the module
(cm_path)
}
Output: {
cm_return - return code = 0, if successful
cm_code - python code object
external_module - if 'yes', module is external
cm_path - path to data entry
cm_uid - uid (from UOA)
cm_alias - alias (from UOA)
}
| def cm::merge_arrays | ( | i | ) |
| def cm::merge_arrays_ll | ( | a, | ||
| b | ||||
| ) |
| def cm::prepare_cid | ( | i | ) |
Prepare cid
Input: {
(cm_repo_uoa) - repository UOA
cm_run_module_uoa | cm_module_uoa - module UOA
cm_data_uoa - data UOA
}
Output: {
cm_return - 0
cm_string_uid - cid with only uid
cm_string_with_repo_uid - cid with only uid
cm_string_uoa - cid with alias or uid
cm_string_with_repo_uoa - cid with alias or uid
cm_repo_uid - cm_repo_uid
cm_repo_uoa - cm_repo_uoa
cm_module_uid - cm_module_uid
cm_module_uoa - cm_module_uoa
cm_data_uid - cm_data_uid
cm_data_uoa - cm_data_uoa
}
| def cm::prepare_final_out | ( | i, | ||
| j | ||||
| ) |
Prepare final output of cM access function depending on cm_console
Input: i= {
cm_return - return code (check "access" function for full description)
(cm_error) - error text (check "access" function for full description)
...
}
j= {
(cm_console) - cm_console (check "access" function for full description)
(cm_output) - if !='', save output to file
...
}
Output: {}
| def cm::print_for_con | ( | s | ) |
| def cm::print_for_web | ( | s | ) |
| def cm::remote_access | ( | i | ) |
Remote access to cM
Input: {
cm_remote_url - remote URL
(cm_user_uoa) -
(cm_user_password) -
(cm_user_password1) -
(remote_repo_uoa)
(remote_pre_auth) - if 'yes', need standard http login/password pre-authentication
(cm_remote_user_name) - remote username
(cm_remote_user_password) - remote password
(cm_web_module_uoa) - module to run
(cm_web_action) - action to perform
if =='download', prepare entry/file download through Internet
(cm_save_to_file) - if cm_web_action==download,
save output to this file
... - all other request parameters
}
Output: {
cm_return - return code = 0 if successful
> 0 if error
< 0 if warning (rarely used at this moment)
(cm_error) - error text, if cm_return > 0
}
| def cm::replace_from_dict | ( | s, | ||
| rep | ||||
| ) |
| def cm::restore_flattened_array | ( | i | ) |
| def cm::save_array_to_file_as_json | ( | i | ) |
| def cm::save_flat_array_to_file | ( | i | ) |
| def cm::set_print_mode | ( | i | ) |
| def cm::set_value_by_flattened_key | ( | i | ) |
Set value in array using flattened key
Input: {
cm_array - array (it will be directly changed!)
cm_key - flattened key (or not if doesn't start with #)
cm_value - value to set
cm_replace_in_keys - array with strings to replace in keys
(used in forms to process # and @ through ^35^ and ^64^ for example)
}
Output: {
cm_return - if =0, success
cm_array - modified array
}
| def cm::str2cm | ( | i | ) |
| def cm::substitute_str_in_file | ( | i | ) |
| def cm::system | ( | i | ) |
System call with timeout (careful, may cause overheads)
Input: {
cmd - command line
(timeout) - timeout in seconds (granularity 0.01 sec) - may cause overheads ...
}
Output: {
cm_return - return code =0 if success
=1 if timedout and killed
(cm_error) - error text if return code > 0
cm_return_code - return code of a program
}
Definition at line 2271 of file cm.py.
Referenced by cm_action().
| def cm::web_print_array_for_debug | ( | i | ) |
| string cm::cm_action_default = 'default' |
| string cm::cm_json_with_text_sep = '*** ### --- CM JSON SEPARATOR --- ### ***' |
| cm::cm_kernel = None |
| string cm::cm_module_default = 'core' |
| string cm::cm_module_default_access = 'access' |
| string cm::cm_unparsed_sep = '--' |
| string cm::env_cm_bin = 'CM_BIN' |
| string cm::env_cm_cfg = 'CM_DEFAULT_CFG' |
| string cm::env_cm_cfg_path = 'CM_DEFAULT_CFG_PATH' |
| string cm::env_cm_default_repo = 'CM_DEFAULT_REPO' |
| string cm::env_cm_local_repo = 'CM_LOCAL_REPO' |
| string cm::env_cm_remote_repo_proxy_http = 'CM_REMOTE_REPO_PROXY_HTTP' |
| string cm::env_cm_remote_repo_proxy_https = 'CM_REMOTE_REPO_PROXY_HTTPS' |
| string cm::env_cm_root = 'CM_ROOT' |
| string cm::env_cm_tmp = 'CM_TMP' |
| string cm::env_cm_user_password = 'CM_USER_PASSWORD' |
| string cm::env_cm_user_password1 = 'CM_USER_PASSWORD1' |
| string cm::env_cm_user_uoa = 'CM_USER_UOA' |
| dictionary cm::ini |
{
# This variable describes initialization of cM framework
# -1 - not initalized
# 0 - initialized
# 1 - error during initialization
'init':-1,
'loaded_module_by_path':{},
'loaded_module_by_path_last_modification':{},
'loaded_data_by_path':{},
'loaded_data_by_path_last_modification':{},
'pcfg':'',
'cfg':{},
'dcfg':{},
'path':'',
'web':'no',
'web_auth':{},
'web_style':{},
'remote_repo':{}
}
| cm::print_on = True |
| string cm::var_cm_cfg_default = 'default' |
| string cm::var_cm_cfg_local = 'local' |
| string cm::var_cm_data = 'data.json' |
| string cm::var_cm_info = '.cm' |