├── .cm ├── alias-a-module └── alias-u-e9a4bb5e10b91e40 ├── module ├── .cm │ ├── alias-a-code │ ├── alias-a-package │ ├── alias-u-0247b19de472d7d0 │ ├── alias-u-688dee2e7014f1fb │ ├── alias-a-code.source │ └── alias-u-45741e3fbcf4024b ├── code.source │ ├── .cm │ │ ├── meta.json │ │ └── info.json │ └── module.py ├── package │ ├── .cm │ │ ├── info.json │ │ └── meta.json │ └── module.py └── code │ ├── .cm │ ├── info.json │ └── meta.json │ └── module.py ├── README.md └── .ckr.json /.cm/alias-a-module: -------------------------------------------------------------------------------- 1 | e9a4bb5e10b91e40 2 | -------------------------------------------------------------------------------- /.cm/alias-u-e9a4bb5e10b91e40: -------------------------------------------------------------------------------- 1 | module 2 | -------------------------------------------------------------------------------- /module/.cm/alias-a-code: -------------------------------------------------------------------------------- 1 | 688dee2e7014f1fb 2 | -------------------------------------------------------------------------------- /module/.cm/alias-a-package: -------------------------------------------------------------------------------- 1 | 0247b19de472d7d0 2 | -------------------------------------------------------------------------------- /module/.cm/alias-u-0247b19de472d7d0: -------------------------------------------------------------------------------- 1 | package 2 | -------------------------------------------------------------------------------- /module/.cm/alias-u-688dee2e7014f1fb: -------------------------------------------------------------------------------- 1 | code 2 | -------------------------------------------------------------------------------- /module/.cm/alias-a-code.source: -------------------------------------------------------------------------------- 1 | 45741e3fbcf4024b 2 | -------------------------------------------------------------------------------- /module/.cm/alias-u-45741e3fbcf4024b: -------------------------------------------------------------------------------- 1 | code.source 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ctuning-modules 2 | =============== 3 | 4 | cTuning modules 5 | -------------------------------------------------------------------------------- /.ckr.json: -------------------------------------------------------------------------------- 1 | { 2 | "data_uid": "51d5e6084333ae86", 3 | "data_name": "cTuning modules", 4 | "dict": {}, 5 | "data_alias": "ctuning-modules", 6 | "data_uoa": "ctuning-modules" 7 | } -------------------------------------------------------------------------------- /module/code.source/.cm/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "license": "See CK LICENSE.txt for licensing details", 3 | "developer": "Grigori Fursin", 4 | "copyright": "See CK Copyright.txt for copyright details", 5 | "actions": {}, 6 | "desc": "cTuning benchmark" 7 | } -------------------------------------------------------------------------------- /module/code.source/.cm/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "control": { 3 | "engine": "CK", 4 | "version": [ 5 | "0", 6 | "1", 7 | "140810", 8 | "beta" 9 | ], 10 | "iso_datetime": "2014-11-17T15:59:48.532000" 11 | }, 12 | "backup_module_uoa": "module", 13 | "data_name": "code.source", 14 | "backup_module_uid": "e9a4bb5e10b91e40" 15 | } -------------------------------------------------------------------------------- /module/code.source/module.py: -------------------------------------------------------------------------------- 1 | # 2 | # Collective Knowledge (cTuning benchmark) 3 | # 4 | # See CK LICENSE.txt for licensing details 5 | # See CK Copyright.txt for copyright details 6 | # 7 | # Developer: Grigori Fursin 8 | # 9 | 10 | cfg={} # Will be updated by CK (meta description of this module) 11 | work={} # Will be updated by CK (temporal data) 12 | ck=None # Will be updated by CK (initialized CK kernel) 13 | 14 | # Local settings 15 | 16 | ############################################################################## 17 | # Initialize module 18 | 19 | def init(i): 20 | """ 21 | 22 | Input: {} 23 | 24 | Output: { 25 | return - return code = 0, if successful 26 | > 0, if error 27 | (error) - error text if return > 0 28 | } 29 | 30 | """ 31 | return {'return':0} 32 | -------------------------------------------------------------------------------- /module/package/.cm/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "control": { 3 | "engine": "CM", 4 | "copyright": "See CK Copyright.txt for copyright details", 5 | "license": "See CK LICENSE.txt for licensing details", 6 | "author": "Grigori Fursin", 7 | "author_email": "Grigori.Fursin@cTuning.org", 8 | "author_uoa": "0728a400aa1c86fe", 9 | "version": [], 10 | "author_webpage": "http://cTuning.org/lab/people/gfursin", 11 | "iso_datetime": "2012-04-13T17:11:05.931000" 12 | }, 13 | "description": "cM packages", 14 | "backup_module_uid": "e9a4bb5e10b91e40", 15 | "cm_outdated": { 16 | "cm_access_control": { 17 | "read_groups": "all", 18 | "comments_groups": "admin", 19 | "write_groups": "admin" 20 | }, 21 | "powered_by": { 22 | "version": "1.0.1977.beta", 23 | "name": "Collective Mind Engine" 24 | } 25 | }, 26 | "data_name": "package", 27 | "backup_module_uoa": "module" 28 | } -------------------------------------------------------------------------------- /module/code/.cm/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "control": { 3 | "engine": "CM", 4 | "copyright": "See CK Copyright.txt for copyright details", 5 | "license": "See CK LICENSE.txt for licensing details", 6 | "author": "Grigori Fursin", 7 | "author_email": "Grigori.Fursin@cTuning.org", 8 | "author_uoa": "0728a400aa1c86fe", 9 | "version": [], 10 | "author_webpage": "http://cTuning.org/lab/people/gfursin", 11 | "iso_datetime": "2012-04-06T21:42:01.204000" 12 | }, 13 | "description": "any binary code or scripts", 14 | "backup_module_uid": "e9a4bb5e10b91e40", 15 | "cm_outdated": { 16 | "powered_by": { 17 | "version": "1.0.1977.beta", 18 | "name": "Collective Mind Engine" 19 | }, 20 | "cm_access_control": { 21 | "read_groups": "registered", 22 | "comments_groups": "admin", 23 | "write_groups": "admin" 24 | } 25 | }, 26 | "data_name": "code", 27 | "backup_module_uoa": "module" 28 | } -------------------------------------------------------------------------------- /module/code/.cm/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "cm_actions": [ 3 | { 4 | "params_default": "", 5 | "params": "", 6 | "cm_index": "change_work_dir", 7 | "func": "change_work_dir", 8 | "desc": "changing working directory to a given code entry" 9 | }, 10 | { 11 | "params": "", 12 | "cm_index": "get_env", 13 | "func": "get_env", 14 | "desc": "return environment script for code" 15 | }, 16 | { 17 | "params": "", 18 | "cm_index": "install", 19 | "func": "install", 20 | "desc": "install code and prepare environment file" 21 | }, 22 | { 23 | "params": "", 24 | "cm_index": "run", 25 | "func": "run", 26 | "desc": "run code (binary)" 27 | }, 28 | { 29 | "params": "", 30 | "cm_index": "get_validated_dataset", 31 | "func": "get_validated_datatset", 32 | "desc": "get validated dataset" 33 | }, 34 | { 35 | "params": "", 36 | "cm_index": "prepare_env_for_all_codes", 37 | "func": "prepare_env_for_all_codes", 38 | "desc": "prepare environment for all codes" 39 | }, 40 | { 41 | "params_default": "", 42 | "params": "", 43 | "cm_index": "prepare_env_vars", 44 | "func": "prepare_env_vars", 45 | "desc": "changing environment variables" 46 | }, 47 | { 48 | "params_default": "", 49 | "params": "", 50 | "cm_index": "set_env", 51 | "func": "set_env", 52 | "desc": "setting environment in a pipeline" 53 | }, 54 | { 55 | "params": "", 56 | "cm_index": "prepare_cmd", 57 | "func": "prepare_cmd", 58 | "desc": "prepare cmd for the program" 59 | }, 60 | { 61 | "params": "", 62 | "cm_index": "native_run", 63 | "func": "native_run", 64 | "desc": "native run with timing" 65 | } 66 | ], 67 | "license": "cM 1.x license", 68 | "calming_delay": "1", 69 | "cm_module_py_dir": "", 70 | "cm_modules": { 71 | "os.script": "d91afa2830ddcbac", 72 | "class": "58014c9c91d6d101", 73 | "dataset": "8a7141c59cd335f5", 74 | "os": "b9735a270ba455c3", 75 | "processor": "41a0bd4f09be3d16", 76 | "cm-core": "9ac54cef3d7caa8a" 77 | }, 78 | "cm_env_prefix": "cm_code_env_", 79 | "cm_data_description": {}, 80 | "cm_batch_script_ext": "tmp-cm-run-", 81 | "authors": [ 82 | "0728a400aa1c86fe" 83 | ], 84 | "url_module": "", 85 | "cm_module_py_ext": "module", 86 | "cm_common_actions": [] 87 | } -------------------------------------------------------------------------------- /module/package/.cm/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "install_script_py_prefix": "python", 3 | "obj_dir": "obj", 4 | "install_dir": "install", 5 | "install_script": "install", 6 | "minimal_setup_for_download": "yes", 7 | "cm_common_actions": [], 8 | "license": "cM 1.x license", 9 | "cm_module_py_dir": "", 10 | "cm_modules": { 11 | "ctuning.setup": "b8a7418f9c701002", 12 | "code": "688dee2e7014f1fb", 13 | "ctuning.scenario": "aaa8e4766b0351e8", 14 | "system": "c0977f94653a6a1c", 15 | "code.source": "45741e3fbcf4024b", 16 | "cm-core": "9ac54cef3d7caa8a", 17 | "cm-web": "f0d8604c7abf6aee", 18 | "os": "b9735a270ba455c3", 19 | "class": "58014c9c91d6d101", 20 | "processor": "41a0bd4f09be3d16" 21 | }, 22 | "dependencies_file": "cm_code_dependencies.txt", 23 | "cm_classes": { 24 | "compiler": "72f81bd39f84ed89" 25 | }, 26 | "cm_actions": [ 27 | { 28 | "params_default": {}, 29 | "params": "", 30 | "cm_index": "install", 31 | "func": "install", 32 | "desc": "install cM package" 33 | }, 34 | { 35 | "params_default": {}, 36 | "params": "", 37 | "cm_index": "installed", 38 | "func": "installed", 39 | "desc": "view installed packages" 40 | }, 41 | { 42 | "params_default": {}, 43 | "cm_index": "web_install", 44 | "params": "", 45 | "func": "web_install", 46 | "params_desc": { 47 | "##compilation_type": { 48 | "default_value": "static", 49 | "skip_form_refresh": "yes", 50 | "sort_index": "52", 51 | "desc_text": "Compilation type", 52 | "has_choice": "yes", 53 | "choice": [ 54 | "static", 55 | "dynamic" 56 | ], 57 | "type": "text" 58 | }, 59 | "##compiler_code_uoa": { 60 | "title_before": "Additional build parameters", 61 | "cm_classes_uoa": [ 62 | "72f81bd39f84ed89" 63 | ], 64 | "start_new_column": "yes", 65 | "force_select_first": "yes", 66 | "sort_index": "40", 67 | "desc_text": "Compiler", 68 | "cm_class_dependencies_from_data": { 69 | "##run_target_processor_uoa": { 70 | "cm_module_uoa": "41a0bd4f09be3d16", 71 | "cm_key": "target_processor" 72 | }, 73 | "##run_host_os_uoa": { 74 | "cm_module_uoa": "b9735a270ba455c3", 75 | "cm_key": "host_os" 76 | }, 77 | "##build_target_os_uoa": { 78 | "cm_module_uoa": "b9735a270ba455c3", 79 | "cm_key": "target_os" 80 | } 81 | }, 82 | "cm_module_uoa": "688dee2e7014f1fb", 83 | "type": "uoa" 84 | }, 85 | "##number_of_parallel_jobs_for_build": { 86 | "default_value": "1", 87 | "sort_index": "80", 88 | "desc_text": "Number of parallel jobs for build (if supported)", 89 | "has_choice": "yes", 90 | "choice": [ 91 | "1", 92 | "2", 93 | "3", 94 | "4", 95 | "5", 96 | "6", 97 | "7", 98 | "8" 99 | ], 100 | "type": "integer" 101 | }, 102 | "##keep_all_files": { 103 | "default_value": "no", 104 | "sort_index": "83", 105 | "desc_text": "Keep all produced files", 106 | "has_choice": "yes", 107 | "choice": [ 108 | "yes", 109 | "no" 110 | ], 111 | "type": "text" 112 | }, 113 | "##package_host_os_uoa": { 114 | "data_from_other_data": { 115 | "cm_sub_key": "##cm_choices#cm_host_os_uoa", 116 | "cm_module_uoa": "b8a7418f9c701002", 117 | "cm_key": "##ctuning_setup_uoa" 118 | }, 119 | "force_select_first": "yes", 120 | "sort_index": "5", 121 | "desc_text": "Host OS", 122 | "cm_module_uoa": "b9735a270ba455c3", 123 | "type": "uoa" 124 | }, 125 | "##run_target_processor_uoa": { 126 | "data_from_other_data": { 127 | "cm_sub_key": "##cm_choices#run_target_processor_uoa", 128 | "cm_module_uoa": "b8a7418f9c701002", 129 | "cm_key": "##ctuning_setup_uoa" 130 | }, 131 | "force_select_first": "yes", 132 | "sort_index": "15", 133 | "desc_text": "Target processor", 134 | "cm_module_uoa": "41a0bd4f09be3d16", 135 | "type": "uoa" 136 | }, 137 | "##build_target_os_uoa": { 138 | "data_from_other_data": { 139 | "cm_sub_key": "##cm_choices#cm_target_os_uoa", 140 | "cm_module_uoa": "b8a7418f9c701002", 141 | "cm_key": "##ctuning_setup_uoa" 142 | }, 143 | "force_select_first": "yes", 144 | "sort_index": "10", 145 | "desc_text": "Target OS", 146 | "cm_module_uoa": "b9735a270ba455c3", 147 | "type": "uoa" 148 | }, 149 | "##ctuning_setup_uoa": { 150 | "title_before": "Customize", 151 | "cm_module_uoa": "b8a7418f9c701002", 152 | "type": "uoa", 153 | "desc_text": "collective tuning setup", 154 | "sort_index": "1" 155 | }, 156 | "##skip_extract_and_build": { 157 | "default_value": "no", 158 | "title_before": "Misc package parameters", 159 | "sort_index": "70", 160 | "desc_text": "Skip extract and build (refresh mode)", 161 | "has_choice": "yes", 162 | "choice": [ 163 | "no", 164 | "yes" 165 | ], 166 | "type": "text" 167 | }, 168 | "##package_repo_uoa": { 169 | "default_value": "ctuning-setup", 170 | "cm_module_uoa": "b59ada2b6842a6c8", 171 | "type": "uoa", 172 | "desc_text": "Install repository", 173 | "sort_index": "20" 174 | } 175 | }, 176 | "desc": "install/monitor cM packages through web" 177 | } 178 | ], 179 | "cm_class_compiler": "72f81bd39f84ed89", 180 | "install_script_py_ext": ".py", 181 | "cm_data_description": { 182 | "##add_to_code_source": { 183 | "desc_text": "add following parameters to the installation code entry", 184 | "type": "dict", 185 | "dict_type": "free" 186 | }, 187 | "##authors": { 188 | "type_next": "values", 189 | "desc_text": "authors", 190 | "sort_index": "5", 191 | "type": "list", 192 | "skip_next_desc": "yes" 193 | }, 194 | "##title": { 195 | "desc_text": "package title", 196 | "type": "text", 197 | "sort_index": "1" 198 | }, 199 | "##date_released": { 200 | "desc_text": "Date when released (ISO)", 201 | "type": "iso_datetime", 202 | "sort_index": "14" 203 | }, 204 | "##url": { 205 | "desc_text": "package URL", 206 | "type": "url", 207 | "sort_index": "10" 208 | }, 209 | "##license": { 210 | "default_value": "cM 1.x license", 211 | "desc_text": "package license", 212 | "type": "textarea", 213 | "sort_index": "15" 214 | }, 215 | "##date_development_started": { 216 | "desc_text": "Date when development started (ISO)", 217 | "type": "iso_datetime", 218 | "sort_index": "12" 219 | }, 220 | "##build": { 221 | "default_value": "no", 222 | "sort_index": "20", 223 | "desc_text": "build package?", 224 | "has_choice": "yes", 225 | "choice": [ 226 | "no", 227 | "yes" 228 | ], 229 | "type": "text" 230 | }, 231 | "##date_development_finished": { 232 | "desc_text": "Date when development finished (ISO)", 233 | "type": "iso_datetime", 234 | "sort_index": "13" 235 | }, 236 | "##install_script": { 237 | "desc_text": "filename of install script (without extension); leave empty if no script", 238 | "type": "text", 239 | "sort_index": "25" 240 | }, 241 | "##authors@$": { 242 | "cm_module_uoa": "b0743a4044480ead", 243 | "type": "uoa" 244 | } 245 | }, 246 | "authors": [ 247 | "0728a400aa1c86fe" 248 | ], 249 | "url_module": "", 250 | "cm_module_py_ext": "module", 251 | "source_classes_to_install": [ 252 | "914178a17c102fb5", 253 | "7834e958464669af" 254 | ] 255 | } -------------------------------------------------------------------------------- /module/code/module.py: -------------------------------------------------------------------------------- 1 | # 2 | # Collective Mind 3 | # 4 | # See cM LICENSE.txt for licensing details. 5 | # See cM Copyright.txt for copyright details. 6 | # 7 | # Developer(s): (C) Grigori Fursin, started on 2011.09 8 | # 9 | 10 | # Should always be here 11 | ini={} 12 | cm_kernel=None 13 | 14 | # Local settings 15 | import os 16 | import sys 17 | import time 18 | import json 19 | import copy 20 | 21 | # ============================================================================ 22 | def init(i): 23 | return {'cm_return':0} 24 | 25 | # ============================================================================ 26 | def change_work_dir(i): 27 | 28 | """ 29 | Chaning working directory 30 | 31 | Input: { 32 | (work_dir) - change to this working directory before running code 33 | or 34 | (work_dir_repo_uoa) - change to the working directory in the repository (repo UOA) 35 | (work_dir_module_uoa) - change to the working directory in the repository (module UOA) 36 | (work_dir_data_uoa) - change to the working directory in the repository (data UOA) 37 | } 38 | 39 | Output: { 40 | cm_return - if =0, success 41 | work_dir - selected working directory 42 | } 43 | """ 44 | 45 | # Changing to working directory 46 | sys.stdout.flush() 47 | work_dir='' 48 | if 'work_dir' in i: work_dir=i['work_dir'] 49 | elif ('work_dir_module_uoa' in i and 'work_dir_data_uoa' in i): 50 | # Change path to another directory 51 | ii={'cm_run_module_uoa':i['work_dir_module_uoa'], 52 | 'cm_action':'load', 53 | 'cm_data_uoa':i['work_dir_data_uoa']} 54 | if 'work_dir_repo_uoa' in i: ii['cm_repo_uoa']=i['work_dir_repo_uoa'] 55 | r=cm_kernel.access(ii) 56 | if r['cm_return']>0: return r 57 | work_dir=r['cm_path'] 58 | 59 | if work_dir!='': 60 | cm_kernel.print_for_con('') 61 | cm_kernel.print_for_con('Changing path to '+work_dir+' ...') 62 | os.chdir(work_dir) 63 | 64 | return {'cm_return':0, 'work_dir':work_dir} 65 | 66 | # ============================================================================ 67 | def get_env(i): 68 | 69 | """ 70 | cM web index 71 | 72 | Input: { 73 | cm_data_uoa - code UOA to prepare environment script name 74 | os_uoa - OS configuration to prepare extension 75 | } 76 | 77 | Output: { 78 | cm_return - return code >0 if error 79 | } 80 | """ 81 | 82 | if 'os_uoa' not in i or i['os_uoa']=='': 83 | return {'cm_return':1, 'cm_error': '"os_uoa" is not defined for "get_env" in "code" module'} 84 | 85 | # Load OS 86 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 87 | 'cm_action':'load', 88 | 'cm_data_uoa':i['os_uoa']} 89 | r=cm_kernel.access(ii) 90 | if r['cm_return']>0: return r 91 | 92 | os_cfg=r['cm_data_obj']['cfg'] 93 | 94 | # Prepare script 95 | s=ini['cfg']['cm_env_prefix']+i['cm_data_uoa']+os_cfg['script_ext'] 96 | 97 | return {'cm_return':0, 'cm_string':s} 98 | 99 | # ============================================================================ 100 | def run(i): 101 | 102 | """ 103 | Run code (binary or script) 104 | 105 | Input: { 106 | (run_host_os_uoa) - host OS UOA (if not set, use default OS from kernel) 107 | (run_target_os_uoa) - target OS UOA (if not set, use run_host_uoa_os) 108 | 109 | (run_target_processor_uoa) - target processor UOA (not strictly needed - can add some helper parameters before executing code) 110 | 111 | -------------------------------------------------------------------------------------------- 112 | run_cmd_key - if !='', set all further run parameters (including target name) 113 | from the work_dir_data_uoa (must be set) 114 | (dataset_uoa) - use dataset to update cmd params from above 115 | or 116 | run_cmd - command line to run 117 | or 118 | run_script - use the following script (add extension from run_target_os) 119 | run_script_uoa - take script from this entry in os.script (add extension from run_target_os) 120 | or 121 | (run_cmd1) - following format: run_cmd1 run_cmd_name|binary_name run_cmd2 run_cmd_main run_cmd3 > run_cmd_out1 2> run_cmd_out2 122 | (run_cmd_name) 123 | (run_cmd2) 124 | (run_cmd_main) or (binary_name) 125 | (run_cmd3) 126 | (run_cmd_out1) 127 | (run_cmd_out2) 128 | -------------------------------------------------------------------------------------------- 129 | 130 | (work_dir) - change to this working directory before running code 131 | or 132 | (work_dir_repo_uoa) - change to the working directory in the repository (repo UOA) 133 | (work_dir_module_uoa) - change to the working directory in the repository (module UOA) 134 | (work_dir_data_uoa) - change to the working directory in the repository (data UOA) 135 | 136 | (run_input_files) - list of files needed to run code (can be copied to the remote host system) 137 | (run_output_files) - list of files that will be created (for validation, etc) 138 | 139 | (code_deps) - list with code UOA for dependencies [{"index":"uoa"} ...] 140 | (skip_code_deps) - if 'yes', skip code deps 141 | 142 | (run_set_env1) - array with environment variables to be set before code deps 143 | (run_set_env2) - array with environment variables to be set before executable 144 | 145 | (run_commands_before) - run commands before executable 146 | (run_commands_after) - run commands after executable 147 | 148 | (cm_dependencies) - dependencies that set all other dependencies (code/include/lib). 149 | Format [{"class UOA":"code UOA"},{},...] 150 | 151 | (run_timeout) - time out for run (overheads may occur) 152 | 153 | (keep_all_files) - if 'yes', do not remove tmp files and do not clean up remote device 154 | (cm_verbose) - if 'yes', print all info 155 | } 156 | 157 | Output: { 158 | cm_return - return code = 0, if successful 159 | 160 | timed_out - 'yes' if timed out 161 | failed_run - 'yes' if return code !=0 or timed out or binary doesn't exist 162 | run_time_by_module - run time measured by module 163 | exit_code - exit code of the system call 164 | run_cmd - final run cmd 165 | work_dir - work directory 166 | run_output_files - final output files 167 | } 168 | """ 169 | 170 | # Check verbose - yes, by default 171 | vrb=i.get('cm_verbose','yes') 172 | 173 | if vrb=='yes': 174 | # cm_kernel.print_for_con('***********************************************') 175 | cm_kernel.print_for_con('Running code ...') 176 | 177 | # Load OS configuration 178 | host_os_uoa='' 179 | if 'run_host_os_uoa' in i and i['run_host_os_uoa']!='': host_os_uoa=i['run_host_os_uoa'] 180 | elif 'cm_default_os_uoa' in cm_kernel.ini['dcfg'] and cm_kernel.ini['dcfg']['cm_default_os_uoa']!='': 181 | host_os_uoa=cm_kernel.ini['dcfg']['cm_default_os_uoa'] 182 | 183 | if host_os_uoa=='': 184 | return {'cm_return':1, 'cm_error':'"host_os_uoa" is not set and not in kernel'} 185 | 186 | target_os_uoa='' 187 | if 'run_target_os_uoa' in i and i['run_target_os_uoa']!='': target_os_uoa=i['run_target_os_uoa'] 188 | elif host_os_uoa!='': target_os_uoa=host_os_uoa 189 | 190 | if vrb=='yes': 191 | sys.stdout.flush() 192 | cm_kernel.print_for_con('') 193 | cm_kernel.print_for_con('Loading host os '+host_os_uoa+' ...') 194 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 195 | 'cm_action':'load', 196 | 'cm_data_uoa':host_os_uoa} 197 | r=cm_kernel.access(ii) 198 | if r['cm_return']>0: return r 199 | 200 | host_os_cfg=r['cm_data_obj']['cfg'] 201 | host_os_path=r['cm_path'] 202 | host_os_uid=r['cm_uid'] 203 | host_os_alias=r['cm_alias'] 204 | 205 | if vrb=='yes': 206 | cm_kernel.print_for_con('') 207 | cm_kernel.print_for_con('Loading target os '+target_os_uoa+' ...') 208 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 209 | 'cm_action':'load', 210 | 'cm_data_uoa':target_os_uoa} 211 | r=cm_kernel.access(ii) 212 | if r['cm_return']>0: return r 213 | 214 | target_os_cfg=r['cm_data_obj']['cfg'] 215 | target_os_path=r['cm_path'] 216 | target_os_uid=r['cm_uid'] 217 | target_os_alias=r['cm_alias'] 218 | 219 | # Dependencies 220 | code_deps=i.get('code_deps',[]) 221 | 222 | # Check if code_deps set additional parameters 223 | qq=i.get('cm_dependencies',{}) 224 | if len(qq)>0: 225 | if vrb=='yes': 226 | cm_kernel.print_for_con('') 227 | cm_kernel.print_for_con('Updating code dependencies from cm_dependencies ...') 228 | 229 | code_deps1=[] 230 | 231 | for q in i.get('cm_dependencies',{}): 232 | yy=q.keys()[0] 233 | x=q[yy] 234 | 235 | jj={'cm_run_module_uoa':ini['cfg']['cm_modules']['class'], 236 | 'cm_data_uoa':yy, 237 | 'cm_action':'load'} 238 | rj=cm_kernel.access(jj) 239 | if rj['cm_return']>0: return rj 240 | 241 | drj=rj['cm_data_obj']['cfg'] 242 | 243 | vcd=drj.get('build_code_deps_var','') 244 | if vcd!='': code_deps1.append({vcd:x}) 245 | 246 | for q in code_deps: code_deps1.append(q) 247 | 248 | code_deps=code_deps1 249 | 250 | i['code_deps']=code_deps 251 | 252 | processor_params={} 253 | if 'run_target_processor_uoa' in i and i['run_target_processor_uoa']!='': 254 | if vrb=='yes': 255 | cm_kernel.print_for_con('') 256 | cm_kernel.print_for_con('Loading target processor '+i['run_target_processor_uoa']+' ...') 257 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['processor'], 258 | 'cm_action':'load', 259 | 'cm_data_uoa':i['run_target_processor_uoa']} 260 | r=cm_kernel.access(ii) 261 | if r['cm_return']>0: return r 262 | 263 | target_processor_cfg=r['cm_data_obj']['cfg'] 264 | target_processor_path=r['cm_path'] 265 | target_processor_uid=r['cm_uid'] 266 | target_processor_alias=r['cm_alias'] 267 | 268 | if 'family' in target_processor_cfg: 269 | processor_params['CM_PROCESSOR_FAMILY']=target_processor_cfg['family'] 270 | if 'architecture' in target_processor_cfg: 271 | processor_params['CM_PROCESSOR_ARCH']=target_processor_cfg['architecture'] 272 | if 'bits' in target_processor_cfg: 273 | processor_params['CM_PROCESSOR_BITS']=target_processor_cfg['bits'] 274 | 275 | # Changing to working directory 276 | sys.stdout.flush() 277 | work_dir='' 278 | if 'work_dir' in i: work_dir=i['work_dir'] 279 | elif ('work_dir_module_uoa' in i and 'work_dir_data_uoa' in i): 280 | # Change path to another directory 281 | ii={'cm_run_module_uoa':i['work_dir_module_uoa'], 282 | 'cm_action':'load', 283 | 'cm_data_uoa':i['work_dir_data_uoa']} 284 | if 'work_dir_repo_uoa' in i: ii['cm_repo_uoa']=i['work_dir_repo_uoa'] 285 | r=cm_kernel.access(ii) 286 | if r['cm_return']>0: return r 287 | work_dir=r['cm_path'] 288 | 289 | if work_dir!='': 290 | if vrb=='yes': 291 | cm_kernel.print_for_con('') 292 | cm_kernel.print_for_con('Changing path to '+work_dir+' ...') 293 | os.chdir(work_dir) 294 | 295 | e1a={} 296 | 297 | # Check if remote 298 | remote=False 299 | if target_os_cfg.get('remote','')=='yes': 300 | remote=True 301 | files=[] 302 | 303 | # Check vars 304 | run_input_files=i.get('run_input_files',[]) 305 | 306 | run_name='' 307 | run_cmd='' 308 | 309 | if i.get('run_script','')!='': 310 | if vrb=='yes': 311 | cm_kernel.print_for_con('') 312 | cm_kernel.print_for_con('Using script '+i['run_script']) 313 | 314 | r=prepare_sub_script({'run_script':i['run_script'], 315 | 'run_script_uoa':i.get('run_script_uoa',''), 316 | 'target_os_cfg':target_os_cfg, 317 | 'run_cmd':i.get('run_cmd',''), 318 | 'run_cmd_out1':i.get('run_cmd_out1',''), 319 | 'run_cmd_out2':i.get('run_cmd_out2','')}) 320 | if r['cm_return']>0: return r 321 | run_cmd=r['run_cmd'] 322 | elif i.get('run_cmd','')!='': 323 | run_cmd=i['run_cmd'] 324 | 325 | if i.get('run_cmd_out1','')!='': run_cmd+=' 1>'+i['run_cmd_out1'] 326 | if i.get('run_cmd_out2','')!='': run_cmd+=' 2>'+i['run_cmd_out2'] 327 | elif i.get('binary_name','')!='' or i.get('run_cmd_name','')!='' or i.get('run_cmd_key','')!='': 328 | run_time={} 329 | 330 | rcmd='' 331 | if i.get('run_cmd_key','')!='': 332 | r=prepare_cmd({'code_module_uoa':i.get('work_dir_module_uoa',''), 333 | 'code_data_uoa':i.get('work_dir_data_uoa',''), 334 | 'run_cmd_key':i.get('run_cmd_key',''), 335 | 'dataset_uoa':i.get('dataset_uoa',''), 336 | 'os_uoa':target_os_uoa}) 337 | if r['cm_return']>0: return r 338 | run_time=r['run_time'] 339 | for j in run_time.get('run_input_files',[]): 340 | if j not in run_input_files: run_input_files.append(j) 341 | 342 | run_set_env2=i.get('run_set_env2',{}) 343 | if len(run_time.get('run_set_env2',{}))>0: run_set_env2.update(run_time['run_set_env2']) 344 | i['run_set_env2']=run_set_env2 345 | 346 | if run_time.get('run_script','')!='': 347 | if vrb=='yes': 348 | cm_kernel.print_for_con('') 349 | cm_kernel.print_for_con('Using script '+run_time['run_script']) 350 | 351 | ii={'run_script':run_time['run_script'], 352 | 'run_script_uoa':run_time.get('run_script_uoa',''), 353 | 'target_os_cfg':target_os_cfg, 354 | 'run_cmd':i.get('run_cmd',''), 355 | 'run_cmd_out1':i.get('run_cmd_out1',''), 356 | 'run_cmd_out2':i.get('run_cmd_out2','')} 357 | if ii['run_cmd_out1']=='': ii['run_cmd_out1']=run_time.get('run_cmd_out1','') 358 | if ii['run_cmd_out2']=='': ii['run_cmd_out2']=run_time.get('run_cmd_out2','') 359 | r=prepare_sub_script(ii) 360 | if r['cm_return']>0: return r 361 | rcmd=r['run_cmd'] 362 | 363 | if i.get('run_cmd1','')!='': run_time['run_cmd1']=i['run_cmd1'] 364 | if i.get('binary_name','')!='': run_time['binary_name']=i['binary_name'] 365 | elif i.get('run_cmd_name','')!='': run_time['run_cmd_name']=i['run_cmd_name'] 366 | if i.get('run_cmd2','')!='': run_time['run_cmd2']=i['run_cmd2'] 367 | if i.get('run_cmd_main','')!='': run_time['run_cmd_main']=i['run_cmd_main'] 368 | if i.get('run_cmd_out1','')!='': run_time['run_cmd_out1']=i['run_cmd_out1'] 369 | if i.get('run_cmd_out2','')!='': run_time['run_cmd_out2']=i['run_cmd_out2'] 370 | 371 | if len(run_time.get('run_output_files',[]))>0 and ('run_output_files' not in i or len(i['run_output_files'])==0): 372 | i['run_output_files']=run_time['run_output_files'] 373 | 374 | run_cmd='' 375 | run_name='' 376 | if 'run_cmd1' in run_time: run_cmd+=' '+run_time['run_cmd1'] 377 | if 'binary_name' in run_time: run_cmd+=' '+run_time['binary_name']; run_name=run_time['binary_name'] 378 | elif 'run_cmd_name' in run_time: run_cmd+=' '+run_time['run_cmd_name']; run_name=run_time['run_cmd_name'] 379 | if 'run_cmd2' in run_time: run_cmd+=' '+run_time['run_cmd2'] 380 | if 'run_cmd_main' in run_time: run_cmd+=' '+run_time['run_cmd_main'] 381 | if 'run_cmd_out1' in run_time: run_cmd+=' 1>'+run_time['run_cmd_out1']; i['run_cmd_out1']=run_time['run_cmd_out1'] 382 | if 'run_cmd_out2' in run_time: run_cmd+=' 2>'+run_time['run_cmd_out2']; i['run_cmd_out2']=run_time['run_cmd_out2'] 383 | 384 | if rcmd!='': 385 | e1a['CM_RUN_CMD1']=run_time.get('run_cmd1','') 386 | e1a['CM_RUN_CMD2']=run_time.get('run_cmd2','') 387 | e1a['CM_RUN_NAME']=run_name 388 | e1a['CM_RUN_CMD_MAIN']=run_time.get('run_cmd_main','') 389 | run_cmd=rcmd 390 | 391 | else: 392 | return {'cm_return':1, 'cm_error':'not enough parameters to run code in "code run"'} 393 | 394 | if vrb=='yes': 395 | cm_kernel.print_for_con('') 396 | cm_kernel.print_for_con('Prepared command line:') 397 | cm_kernel.print_for_con(' '+run_cmd) 398 | 399 | # Check commands after 400 | run_commands_after=[] 401 | if 'run_commands_after' in i: run_commands_after=i['run_commands_after'] 402 | 403 | # Check that executable exists 404 | if run_name!='' and not os.path.isfile(run_name): 405 | if vrb=='yes': 406 | cm_kernel.print_for_con('Can\'t find executable '+run_name) 407 | return {'cm_return':0, 'failed_run':'yes'} 408 | 409 | # Prepare environment before code deps 410 | # First, set fixed ones 411 | if 'family' in target_os_cfg: e1a['CM_OS_FAMILY']=target_os_cfg['family'] 412 | if 'bits' in target_os_cfg: e1a['CM_OS_BITS']=target_os_cfg['bits'] 413 | if 'version' in target_os_cfg: e1a['CM_OS_VERSION']=target_os_cfg['version'] 414 | if 'lib_dir' in target_os_cfg: e1a['CM_OS_LIB_DIR']=target_os_cfg['lib_dir'] 415 | 416 | if 'run_set_env1' in i: e1a.update(i['run_set_env1']) 417 | e1a.update(processor_params) 418 | 419 | # Prepare script name 420 | script='' 421 | if 'exec_prefix' in target_os_cfg and target_os_cfg['exec_prefix']!='': script+=target_os_cfg['exec_prefix'] 422 | script+=ini['cfg']['cm_batch_script_ext'] 423 | 424 | r=cm_kernel.gen_uid({}) 425 | if r['cm_return']>0: return r 426 | script+=r['cm_uid'] 427 | 428 | # Create script ***************************************************************************************** 429 | ii={'script_name':script, 430 | 'target_os_uoa':target_os_uoa, 431 | 'set_env1':e1a} 432 | if 'code_deps' in i and i.get('skip_code_deps','')!='yes': 433 | ii['code_deps']=i['code_deps'] 434 | if 'run_set_env2' in i and i['run_set_env2']!='': ii['set_env2']=i['run_set_env2'] 435 | if 'run_commands_before' in i: ii['run_commands_before']=i['run_commands_before'] 436 | if run_cmd!='': ii['run_cmd']=run_cmd 437 | if len(run_commands_after)>0: ii['run_commands_after']=run_commands_after 438 | r=prepare_script(ii) 439 | if r['cm_return']>0: return r 440 | script=r['cm_path'] 441 | 442 | # Check if remote 443 | if remote: 444 | fail=False 445 | 446 | if remote and 'remote_init' in target_os_cfg: 447 | sys.stdout.flush() 448 | if vrb=='yes': 449 | cm_kernel.print_for_con('') 450 | cm_kernel.print_for_con('Initializing remote device ...') 451 | p=target_os_cfg['remote_init']; cm_kernel.print_for_con(p); x=os.system(p) 452 | if x!=0: fail=True 453 | 454 | if not fail: 455 | if vrb=='yes': 456 | cm_kernel.print_for_con('') 457 | cm_kernel.print_for_con('Copying files to device ...') 458 | if target_os_cfg.get('no_script_execution','')!='yes': files.append(script) 459 | if run_name!='': files.append(run_name) 460 | if len(run_input_files)>0: 461 | for x in run_input_files: 462 | if x not in files: files.append(x) 463 | 464 | for z in files: 465 | filename=os.path.basename(z) 466 | p=target_os_cfg['remote_push']+' '+host_os_cfg['env_quotes']+z+host_os_cfg['env_quotes']+\ 467 | ' '+target_os_cfg['remote_dir']+target_os_cfg['dir_sep']+filename 468 | if vrb=='yes': 469 | cm_kernel.print_for_con(' '+p) 470 | x=os.system(p) 471 | if x!=0: 472 | fail=True 473 | if vrb=='yes': 474 | cm_kernel.print_for_con('') 475 | cm_kernel.print_for_con('Error: Couldn\'t copy all necessary files for a run!') 476 | 477 | if not fail and run_name!='' and 'set_executable' in target_os_cfg: 478 | if vrb=='yes': 479 | cm_kernel.print_for_con('') 480 | cm_kernel.print_for_con('Setting permissions for binary ...') 481 | 482 | filename=run_name 483 | if remote: filename=os.path.basename(run_name) 484 | 485 | p=target_os_cfg['remote_shell']+' '+target_os_cfg['set_executable']+' '+target_os_cfg['remote_dir']+\ 486 | target_os_cfg['dir_sep']+filename 487 | if vrb=='yes': 488 | cm_kernel.print_for_con(' '+p) 489 | x=os.system(p) 490 | if x!=0: fail=True 491 | 492 | if target_os_cfg.get('no_script_execution', '')!='yes': 493 | p=target_os_cfg['remote_shell']+' '+target_os_cfg['set_executable']+' '+target_os_cfg['remote_dir']+\ 494 | target_os_cfg['dir_sep']+script 495 | if vrb=='yes': 496 | cm_kernel.print_for_con(' '+p) 497 | x=os.system(p) 498 | if x!=0: fail=True 499 | 500 | # Clean output files 501 | if remote: 502 | # if remote and run_cmd_out1/run_cmd_out2 !='', add to run_output_files 503 | # to get them from remote device 504 | if i.get('run_cmd_out1','')!='' or i.get('run_cmd_out2','')!='': 505 | if len(i.get('run_output_files',[]))==0: i['run_output_files']=[] 506 | if i.get('run_cmd_out1','')!='' and i['run_cmd_out1'] not in i['run_output_files']: i['run_output_files'].append(i['run_cmd_out1']) 507 | if i.get('run_cmd_out2','')!='' and i['run_cmd_out2'] not in i['run_output_files']: i['run_output_files'].append(i['run_cmd_out2']) 508 | else: 509 | if i.get('run_cmd_out1','')!='': 510 | try: 511 | os.remove(i['run_cmd_out1']) 512 | except: 513 | pass 514 | if i.get('run_cmd_out2','')!='': 515 | try: 516 | os.remove(i['run_cmd_out2']) 517 | except: 518 | pass 519 | 520 | if 'run_output_files' in i and len(i['run_output_files'])>0: 521 | if vrb=='yes': 522 | sys.stdout.flush() 523 | cm_kernel.print_for_con('') 524 | cm_kernel.print_for_con('Deleting output files ...') 525 | for z in i['run_output_files']: 526 | if vrb=='yes': 527 | cm_kernel.print_for_con(' '+z) 528 | 529 | if remote: 530 | p=target_os_cfg['remote_shell']+' '+target_os_cfg['delete_file']+' '+host_os_cfg['env_quotes']+target_os_cfg['remote_dir']+\ 531 | target_os_cfg['dir_sep']+z+host_os_cfg['env_quotes'] 532 | if vrb=='yes': 533 | cm_kernel.print_for_con(' '+p) 534 | x=os.system(p) 535 | # Ignore errors 536 | # if x!=0: fail=True 537 | 538 | else: 539 | try: 540 | os.remove(z) 541 | except: 542 | pass 543 | 544 | # Run cmd 545 | cmd='' 546 | if target_os_cfg.get('no_script_execution','')=='yes': 547 | r=cm_kernel.load_array_from_file({'cm_filename':script}) 548 | if r['cm_return']>0: return r 549 | a=r['cm_array'] 550 | for x in a: 551 | xx=x.strip() 552 | if xx!='' and not xx.startswith(target_os_cfg['rem']): 553 | if cmd!='': cmd+=target_os_cfg['env_separator']+' ' 554 | cmd+=xx 555 | else: 556 | # FGG: this was originally, (we used . ./script) but Abdul reported many problems 557 | # on UBUNTU and Debian when running scripts with variable substitution (MILEPOST GCC, for example) 558 | # cmd=target_os_cfg['env_call']+' '+script 559 | if target_os_cfg.get('set_executable','')!='': 560 | cmd=target_os_cfg['set_executable']+' '+script+' '+target_os_cfg['env_separator']+' '+script 561 | else: 562 | # for Windows like 563 | cmd=target_os_cfg['env_call']+' '+script 564 | 565 | if remote: 566 | cmd=target_os_cfg['change_dir']+' '+target_os_cfg['remote_dir']+\ 567 | target_os_cfg['env_separator']+' '+cmd 568 | if host_os_cfg.get('env_quotes_if_remote','')!='': 569 | cmdx1=cmd.replace(host_os_cfg['env_quotes_if_remote'], '\\'+host_os_cfg['env_quotes_if_remote']) 570 | cmdx=host_os_cfg['env_quotes_if_remote']+cmdx1+host_os_cfg['env_quotes_if_remote'] 571 | else: 572 | cmdx=cmd 573 | 574 | if host_os_cfg.get('env_dollar_if_remote','')=='yes': 575 | cmdx=cmdx.replace('$','\\$') 576 | 577 | cmd=target_os_cfg['remote_shell']+' '+cmdx 578 | 579 | ii={'cmd':cmd} 580 | if 'run_timeout' in i and i['run_timeout']!='': ii['timeout']=i['run_timeout'] 581 | r=-1 582 | fail=False 583 | 584 | sys.stdout.flush() 585 | if 'calming_delay' in i: 586 | calming_delay=i['calming_delay'] 587 | else: 588 | calming_delay=ini['cfg'].get('calming_delay','') 589 | 590 | if calming_delay!='' and float(calming_delay)!=0: 591 | if vrb=='yes': 592 | cm_kernel.print_for_con('') 593 | cm_kernel.print_for_con('Calming delay: '+calming_delay+' second(s) ...') 594 | time.sleep(float(calming_delay)) 595 | 596 | if vrb=='yes': 597 | cm_kernel.print_for_con('') 598 | cm_kernel.print_for_con('Executing script:') 599 | cm_kernel.print_for_con(' '+cmd) 600 | 601 | start_time=time.time() 602 | rx=cm_kernel.system(ii) 603 | t=time.time()-start_time 604 | 605 | sys.stdout.flush() 606 | 607 | ii={'cm_return':0} 608 | 609 | if rx['cm_return']==1: # timeout 610 | ii.update({'timed_out':'yes', 'failed_run':'yes'}) 611 | elif rx['cm_return']>0: return rx # Module error 612 | else: 613 | ts="%.3f" % t 614 | rc=rx['cm_return_code'] 615 | ii.update({'run_time_by_module':ts, 'exit_code':rc}) 616 | if rc!=0: ii.update({'failed_run':'yes'}) 617 | 618 | ii['run_cmd']=run_cmd 619 | 620 | # Moving back output files if needed 621 | if remote and 'run_output_files' in i and len(i['run_output_files'])>0: 622 | if vrb=='yes': 623 | sys.stdout.flush() 624 | cm_kernel.print_for_con('') 625 | cm_kernel.print_for_con('Copying output files from remote device ...') 626 | for z in i['run_output_files']: 627 | if vrb=='yes': 628 | cm_kernel.print_for_con(' '+z) 629 | 630 | filename=os.path.basename(z) 631 | p=target_os_cfg['remote_pull']+' '+target_os_cfg['remote_dir']+target_os_cfg['dir_sep']+filename+\ 632 | ' '+host_os_cfg['env_quotes']+z+host_os_cfg['env_quotes'] 633 | if vrb=='yes': 634 | cm_kernel.print_for_con(' '+p) 635 | x=os.system(p) 636 | if x!=0: fail=True 637 | 638 | # Cleaning up tmp and other files 639 | if i.get('keep_all_files','')!='yes': 640 | if vrb=='yes': 641 | cm_kernel.print_for_con('') 642 | cm_kernel.print_for_con('Cleaning up local files ...') 643 | # clean up script if not from cM 644 | 645 | try: 646 | os.remove(script) 647 | except: 648 | pass 649 | 650 | if remote: 651 | if vrb=='yes': 652 | cm_kernel.print_for_con('') 653 | cm_kernel.print_for_con('Cleaning up files on remote device ...') 654 | # files already exist - add output files if needed 655 | if 'run_output_files' in i and len(i['run_output_files'])>0: 656 | for x in i['run_output_files']: 657 | if x not in files: files.append(x) 658 | 659 | for z in files: 660 | filename=os.path.basename(z) 661 | p=target_os_cfg['remote_shell']+' '+target_os_cfg['delete_file']+' '+host_os_cfg['env_quotes']+target_os_cfg['remote_dir']+\ 662 | target_os_cfg['dir_sep']+filename+host_os_cfg['env_quotes'] 663 | if vrb=='yes': 664 | cm_kernel.print_for_con(' '+p); x=os.system(p) 665 | 666 | if vrb=='yes': 667 | cm_kernel.print_for_con('') 668 | cm_kernel.print_for_con('Run time (by module): '+ts) 669 | 670 | ii['work_dir']=work_dir 671 | ii['run_output_files']=i.get('run_output_files',[]) 672 | 673 | if vrb=='yes': 674 | cm_kernel.print_for_con('') 675 | cm_kernel.print_for_con('Execution finished!') 676 | 677 | return ii 678 | 679 | # ============================================================================ 680 | def prepare_env_for_all_codes(i): 681 | 682 | """ 683 | Prepare environment for all codes 684 | 685 | Input: { 686 | code_deps - list with code UOA for dependencies [{"index":"uoa"} ...] 687 | os_uoa - OS UOA 688 | no_strict_check - if 'yes', do not check if code dependency was installed properly 689 | } 690 | 691 | Output: { 692 | cm_return - return code = 0, if successful 693 | cm_string - environment string 694 | cm_array - array with environment setting (for scripts) 695 | include_paths1 - list with paths with include directories 696 | lib_paths - list with libraries 697 | env_separator - environment separator (just in case to avoid double loading of OS) 698 | } 699 | """ 700 | 701 | # Check vars 702 | if 'code_deps' not in i: return {'cm_return':1, 'cm_error':'"code_deps" is not defined in "code prepare_env_for_all_codes"'} 703 | 704 | include_paths=[] 705 | lib_paths=[] 706 | 707 | # Load OS 708 | os_uoa='' 709 | if 'os_uoa' in i and i['os_uoa']!='': os_uoa=i['os_uoa'] 710 | elif 'cm_default_os_uoa' in cm_kernel.ini['dcfg'] and cm_kernel.ini['dcfg']['cm_default_os_uoa']!='': 711 | os_uoa=cm_kernel.ini['dcfg']['cm_default_os_uoa'] 712 | 713 | if os_uoa=='' not in i: 714 | return {'cm_return':1, 'cm_error':'"os_uoa" is not defined and not in kernel'} 715 | 716 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 717 | 'cm_action':'load', 718 | 'cm_data_uoa':os_uoa} 719 | r=cm_kernel.access(ii) 720 | if r['cm_return']>0: return r 721 | 722 | os_cfg=r['cm_data_obj']['cfg'] 723 | os_path=r['cm_path'] 724 | os_uid=r['cm_uid'] 725 | os_alias=r['cm_alias'] 726 | 727 | s_code_deps='' 728 | a_code_deps=[] 729 | if 'code_deps' in i: 730 | for xx in i['code_deps']: 731 | yy=xx.keys()[0] 732 | x=xx[yy] 733 | 734 | if x=='': 735 | return {'cm_return':1, 'cm_error':'dependency "'+yy+'" is empty, please check your input'} 736 | 737 | # Check if code was installed 738 | if i.get('no_strict_check','')!='yes': 739 | ii={'cm_run_module_uoa':ini['cm_module_uid'], 740 | 'cm_action':'load', 741 | 'cm_data_uoa':x} 742 | r=cm_kernel.access(ii) 743 | if r['cm_return']==16: 744 | return {'cm_return':1, 'cm_error':'dependency is not resolved - code '+x+' ('+yy+') is not installed'} 745 | elif r['cm_return']>0: return r 746 | code_cfg=r['cm_data_obj']['cfg'] 747 | if code_cfg.get('build_finished_successfully','')!='yes': 748 | return {'cm_return':1, 'cm_error':'dependency is not resolved - code '+x+' ('+yy+') is not installed'} 749 | 750 | code_path=r['cm_path'] 751 | include_paths.append(os.path.join(code_path, 'include')) 752 | 753 | if 'state_input' in code_cfg and \ 754 | 'run_set_env2' in code_cfg['state_input'] and \ 755 | 'CM_TARGET_FILE' in code_cfg['state_input']['run_set_env2']: 756 | lib_paths.append(os.path.join(code_path, os_cfg['lib_dir'], 757 | code_cfg['state_input']['run_set_env2']['CM_TARGET_FILE'])) 758 | 759 | # Environment script 760 | r=get_env({'cm_data_uoa':x, 'os_uoa':os_uoa}) 761 | if r['cm_return']>0: return r 762 | 763 | # z=os_cfg['env_call']+' '+os.path.join(cm_kernel.ini[cm_kernel.env_cm_bin],r['cm_string']) 764 | z1=os_cfg['env_set']+' '+yy+'='+os_cfg['env_quotes']+x+os_cfg['env_quotes'] 765 | z=os_cfg['env_call']+' '+r['cm_string'] 766 | 767 | if s_code_deps!='': s_code_deps+=' '+os_cfg['env_separator']+' ' 768 | s_code_deps+=z1 769 | if s_code_deps!='': s_code_deps+=' '+os_cfg['env_separator']+' ' 770 | s_code_deps+=z 771 | # FGG added again setting environment variable since calling other scripts can change it 772 | # for example, we set CM_CODE_DEP_COMPILER and then call GMP that was compiled with another 773 | # compiler, then it will change this variable to a wrong value and further tools will 774 | # not be working correctly ... 775 | if s_code_deps!='': s_code_deps+=' '+os_cfg['env_separator']+' ' 776 | s_code_deps+=z1 777 | 778 | a_code_deps.append(z1) 779 | a_code_deps.append(z) 780 | a_code_deps.append(z1) 781 | 782 | return {'cm_return':0, 'cm_string':s_code_deps, 'cm_array':a_code_deps, 'env_separator': os_cfg['env_separator'], 783 | 'include_paths':include_paths, 'lib_paths':lib_paths} 784 | 785 | # ============================================================================ 786 | def prepare_env_vars(i): 787 | """ 788 | Prepare environment variables 789 | 790 | Input: { 791 | array - array of environment variables to set 792 | prefix - add prefix to set environment variable 793 | separator - add separator for the command line 794 | (quotes) - use quotes? 795 | } 796 | 797 | Output: { 798 | cm_return - if =0, success 799 | cm_string - cmd with prepared environment (export A=B; export C=D; ...) 800 | cm_string1 - simplified string (CM_ALL_ENV="A=B C=D E=F") 801 | cm_array - array with environment setting (for scripts) 802 | } 803 | """ 804 | 805 | # Check vars 806 | if 'array' not in i: return {'cm_return':1, 'cm_error': '"array" is not set in "os prepare_env_vars"'} 807 | if 'prefix' not in i: return {'cm_return':1, 'cm_error': '"prefix" is not set in "os prepare_env_vars"'} 808 | if 'separator' not in i: return {'cm_return':1, 'cm_error': '"separator" is not set in "os prepare_env_vars"'} 809 | 810 | q='' 811 | if 'quotes' in i: q=i['quotes'] 812 | 813 | a=[] 814 | s='' 815 | s1=i['prefix']+' CM_ALL_ENV='+q 816 | 817 | for k,v in i['array'].iteritems(): 818 | if s!='': 819 | s+=' '+i['separator']+' ' 820 | s1+=' ' 821 | 822 | z=i['prefix']+' '+k+'=' 823 | 824 | # Check quotes (a bit tricky depending on the OS) 825 | x='' 826 | if q!='': 827 | # likely Linux/Android 828 | x=q+v.replace('"', '\"')+q 829 | else: 830 | # likely Windows 831 | x=v 832 | 833 | s+=z+x 834 | a.append(z+x) 835 | 836 | s1+=k+'='+q+v+q 837 | s1+=q 838 | 839 | return {'cm_return':0, 'cm_string':s, 'cm_string1':s1, 'cm_array':a} 840 | 841 | # ============================================================================ 842 | def set_env(i): 843 | 844 | """ 845 | Set environment for a given code 846 | 847 | Input: { 848 | input_key - key with code_uoa 849 | } 850 | 851 | Output: { 852 | cm_return - return code = 0, if successful 853 | os_env - OS environment from the code 854 | } 855 | """ 856 | 857 | # Check vars 858 | if 'input_key' not in i: return {'cm_return':1, 'cm_error':'"input_key" is not defined in "code set_env"'} 859 | if i['input_key'] not in i: return {'cm_return':1, 'cm_error':'i["input_key"] is not defined in "code set_env"'} 860 | 861 | code_uoa=i[i['input_key']] 862 | 863 | # Load code 864 | ii={'cm_run_module_uoa':ini['cm_module_uid'], 865 | 'cm_action':'load', 866 | 'cm_data_uoa':code_uoa} 867 | r=cm_kernel.access(ii) 868 | if r['cm_return']>0: return r 869 | code_cfg=r['cm_data_obj']['cfg'] 870 | 871 | r={'cm_return':0} 872 | 873 | if 'os_env' in code_cfg: r.update({'os_env':code_cfg['os_env']}) 874 | 875 | return r 876 | 877 | # ============================================================================ 878 | def install(i): 879 | 880 | """ 881 | Install code and set environment 882 | 883 | Input: { 884 | (install_data_uid) - create an entry with this UID 885 | (install_data_alias) - create an entry with this alias 886 | (install_data_display_as_alias) - use this display as alias for a generated entry 887 | (install_module_uoa) - use this module to create an entry (if not set, use 'code') 888 | (install_repo_uoa) - use this repo to create an entry 889 | (cm_array) - add this data to the new entry 890 | target_os_uoa - target os to install script 891 | (add_rem_to_script) - add rem to install script 892 | } 893 | 894 | Output: { 895 | cm_return - return code = 0, if successful 896 | 897 | Parameters from entry creation 898 | 899 | script_filename - script filename 900 | script_name - full script name 901 | } 902 | """ 903 | 904 | cm_kernel.print_for_con('***********************************************') 905 | cm_kernel.print_for_con('Installing code ...') 906 | 907 | # Check vars 908 | if 'target_os_uoa' not in i: return {'cm_return':1, 'cm_error':'"target_os_uoa" is not defined in "code install"'} 909 | 910 | # Create entry 911 | ii={'cm_run_module_uoa':ini['cm_module_uid'], 912 | 'cm_action':'update'} 913 | if 'install_data_uid' in i and i['install_data_uid']!='': 914 | ii['cm_data_uid']=i['install_data_uid'] 915 | if 'install_data_alias' in i and i['install_data_alias']!='': 916 | ii['cm_data_uoa']=i['install_data_alias'] 917 | if 'install_data_display_as_alias' in i: 918 | ii['cm_display_as_alias']=i['install_data_display_as_alias'] 919 | if 'install_module_uoa' in i and i['install_module_uoa']!='': 920 | ii['cm_run_module_uoa']=i['install_module_uoa'] 921 | if 'cm_array' in i and len(i['cm_array'])>0: ii['cm_array']=i['cm_array'] 922 | if 'install_repo_uoa' in i and i['install_repo_uoa']!='': 923 | ii['cm_repo_uoa']=i['install_repo_uoa'] 924 | r=cm_kernel.access(ii) 925 | if r['cm_return']>0: return r 926 | 927 | target_path=r['cm_path'] 928 | target_uid=r['cm_uid'] 929 | target_alias=r['cm_alias'] 930 | 931 | # Prepare script 932 | rx=get_env({'cm_data_uoa':target_uid, 933 | 'os_uoa':i['target_os_uoa']}) 934 | if rx['cm_return']>0: return rx 935 | 936 | script=rx['cm_string'] 937 | 938 | ii={'script_name':script, 939 | 'skip_extension':'yes', 940 | 'target_os_uoa':i['target_os_uoa'], 941 | 'cm_path':target_path} 942 | if 'code_deps' in i and i.get('skip_code_deps','')!='yes': 943 | ii['code_deps']=i['code_deps'] 944 | 945 | # Add remark about how code was built 946 | if 'add_rem_to_script' in i: 947 | run_commands_before=[] 948 | run_commands_before.append('') 949 | for x in i['add_rem_to_script']: 950 | run_commands_before.append(x) 951 | ii['run_commands_before']=run_commands_before 952 | 953 | rx=prepare_script(ii) 954 | if rx['cm_return']>0: return rx 955 | 956 | r['script_name']=rx['cm_path'] 957 | r['script_filename']=script 958 | 959 | return r 960 | 961 | # ============================================================================ 962 | def prepare_script(i): 963 | 964 | """ 965 | Prepare script with code deps 966 | 967 | Input: { 968 | script_name - script name (usually without extensions) 969 | target_os_uoa - target os to get script extension and other parameters 970 | (skip_extension) - if 'yes', script already has extension 971 | (cm_path) - path to create script 972 | (set_env1) - add environment vars (1) to script 973 | (code_deps) - add code deps to script 974 | (set_env2) - add environment vars (2) to script 975 | (run_commands_before) - add some commands before main command 976 | (run_cmd) - add main command 977 | (run_commands_after) - add some commands after main command 978 | } 979 | 980 | Output: { 981 | cm_return - return code = 0, if successful 982 | cm_path - full name of the created script with path 983 | } 984 | """ 985 | 986 | # Check vars 987 | if 'script_name' not in i: return {'cm_return':1, 'cm_error':'"script_name" is not defined in "code prepare_script"'} 988 | if 'target_os_uoa' not in i: return {'cm_return':1, 'cm_error':'"target_os_uoa" is not defined in "code prepare_script"'} 989 | 990 | # Prepare path 991 | p='' 992 | if 'cm_path' in i and i['cm_path']!='': 993 | p=os.path.join(i['cm_path'], i['script_name']) 994 | else: 995 | p=i['script_name'] 996 | 997 | # Load OS 998 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 999 | 'cm_action':'load', 1000 | 'cm_data_uoa':i['target_os_uoa']} 1001 | r=cm_kernel.access(ii) 1002 | if r['cm_return']>0: return r 1003 | 1004 | target_os_cfg=r['cm_data_obj']['cfg'] 1005 | target_os_path=r['cm_path'] 1006 | target_os_uid=r['cm_uid'] 1007 | target_os_alias=r['cm_alias'] 1008 | 1009 | if i.get('skip_extension','')!='yes': 1010 | p+=target_os_cfg['script_ext'] 1011 | 1012 | try: 1013 | f=open(p, 'w') 1014 | if 'batch_prefix' in target_os_cfg and target_os_cfg['batch_prefix']!='': f.write(target_os_cfg['batch_prefix']) 1015 | 1016 | if 'rem' in target_os_cfg: f.write('\n'+target_os_cfg['rem']+' target_os_uoa: '+i['target_os_uoa']+'\n') 1017 | 1018 | if 'set_env1' in i and len(i['set_env1'])>0: 1019 | f.write('\n') 1020 | if 'rem' in target_os_cfg: f.write(target_os_cfg['rem']+' Set global parameters\n') 1021 | r=prepare_env_vars({'array':i['set_env1'], 1022 | 'prefix':target_os_cfg['env_set'], 1023 | 'separator':target_os_cfg['env_separator'], 1024 | 'quotes':target_os_cfg['env_quotes']}) 1025 | if r['cm_return']>0: return r 1026 | for x in r['cm_array']: f.write(x+'\n') 1027 | 1028 | if 'code_deps' in i and len(i['code_deps'])>0: 1029 | r=prepare_env_for_all_codes({'code_deps':i['code_deps'], 1030 | 'os_uoa':i['target_os_uoa']}) 1031 | if r['cm_return']>0: return r 1032 | f.write('\n') 1033 | if 'rem' in target_os_cfg: f.write(target_os_cfg['rem']+' Prepare code dependencies\n') 1034 | for x in r['cm_array']: f.write(x+'\n') 1035 | 1036 | if 'set_env2' in i and len(i['set_env2'])>0: 1037 | f.write('\n') 1038 | if 'rem' in target_os_cfg: f.write(target_os_cfg['rem']+' Set execution parameters\n') 1039 | r=prepare_env_vars({'array':i['set_env2'], 1040 | 'prefix':target_os_cfg['env_set'], 1041 | 'separator':target_os_cfg['env_separator'], 1042 | 'quotes':target_os_cfg['env_quotes']}) 1043 | if r['cm_return']>0: return r 1044 | for x in r['cm_array']: f.write(x+'\n') 1045 | 1046 | if 'run_commands_before' in i: 1047 | for x in i['run_commands_before']: f.write(x+'\n') 1048 | 1049 | if 'run_cmd' in i: 1050 | f.write('\n') 1051 | if 'rem' in target_os_cfg: f.write(target_os_cfg['rem']+' Executable\n') 1052 | f.write(i['run_cmd'].strip()+'\n') 1053 | 1054 | if 'run_commands_after' in i: 1055 | for x in i['run_commands_after']: f.write(x+'\n') 1056 | 1057 | f.close() 1058 | except Exception as e: 1059 | return {'cm_return':1, 'cm_error':'error while preparing script in "code prepare_script" ('+format(e)+')'} 1060 | 1061 | return {'cm_return':0, 'cm_path':p} 1062 | 1063 | # ============================================================================ 1064 | def prepare_sub_script(i): 1065 | 1066 | """ 1067 | Prepare sub_script with extension 1068 | 1069 | Input: { 1070 | run_script - script name (usually without extensions) 1071 | (run_script_uoa) - script UOA if any 1072 | target_os_cfg - target os cfg to get script extension and other parameters 1073 | 1074 | } 1075 | 1076 | Output: { 1077 | cm_return - return code = 0, if successful 1078 | cm_path - full name of the created script with path 1079 | } 1080 | """ 1081 | 1082 | run_cmd='' 1083 | 1084 | target_os_cfg=i['target_os_cfg'] 1085 | 1086 | remote=False 1087 | if target_os_cfg.get('remote','')=='yes': 1088 | remote=True 1089 | 1090 | script_name=i['run_script'] 1091 | 1092 | script_path='' 1093 | if 'run_script_uoa' in i and i['run_script_uoa']!='': 1094 | # cm_kernel.print_for_con('') 1095 | # cm_kernel.print_for_con('Preparing path for OS script '+i['run_script_uoa']+' ...') 1096 | 1097 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os.script'], 1098 | 'cm_action':'load', 1099 | 'cm_data_uoa':i['run_script_uoa']} 1100 | r=cm_kernel.access(ii) 1101 | if r['cm_return']>0: return r 1102 | 1103 | script_cfg=r['cm_data_obj']['cfg'] 1104 | script_path=r['cm_path'] 1105 | 1106 | if 'scripts' not in script_cfg or i['run_script'] not in script_cfg['scripts']: 1107 | return {'cm_return':1, 'cm_error':'can\'t find script in os.script configuration'} 1108 | 1109 | script_name=script_cfg['scripts'][script_name] 1110 | 1111 | script_name+=target_os_cfg['script_ext'] 1112 | 1113 | run_name=script_name 1114 | if script_path!='': 1115 | run_name=os.path.join(script_path, run_name) 1116 | elif 'exec_prefix' in target_os_cfg and target_os_cfg['exec_prefix']!='': 1117 | run_name=target_os_cfg['exec_prefix']+run_name 1118 | 1119 | if target_os_cfg.get('set_executable','')!='': 1120 | p=target_os_cfg['set_executable']+' '+run_name 1121 | x=os.system(p) 1122 | 1123 | run_cmd='' 1124 | if remote and target_os_cfg.get('no_script_execution','')=='yes': 1125 | r=cm_kernel.load_array_from_file({'cm_filename':run_name}) 1126 | if r['cm_return']>0: return r 1127 | a=r['cm_array'] 1128 | for x in a: 1129 | xx=x.strip() 1130 | if xx!='' and not xx.startswith(target_os_cfg['rem']): 1131 | if run_cmd!='': run_cmd+=target_os_cfg['env_separator']+' ' 1132 | run_cmd+=xx 1133 | run_name='' 1134 | else: 1135 | run_cmd=run_name 1136 | 1137 | if i.get('run_cmd','')!='': run_cmd+=' '+i['run_cmd'] 1138 | 1139 | if i.get('run_cmd_out1','')!='': run_cmd+=' 1>'+i['run_cmd_out1'] 1140 | if i.get('run_cmd_out2','')!='': run_cmd+=' 2>'+i['run_cmd_out2'] 1141 | 1142 | 1143 | return {'cm_return':0, 'run_cmd':run_cmd} 1144 | 1145 | # ============================================================================ 1146 | def prepare_cmd(i): 1147 | """ 1148 | Prepare command line for the code 1149 | 1150 | Input: { 1151 | (code_module_uoa) - module of the working data 1152 | (code_data_uoa) - working data uoa 1153 | (run_cmd_key) - name if multiple CMDs available for this program 1154 | (dataset_uoa) - UOA of dataset used to prepare this cmd 1155 | (os_uoa) - OS UOA 1156 | (compilation_type) - static or dynamic 1157 | } 1158 | 1159 | Output: { 1160 | cm_return - if =0, success 1161 | (cm_error) - if cm_return>0, error text 1162 | 1163 | run_time={ 1164 | run_env - set environment before command line 1165 | - the following params will be aggregated to 1 line 1166 | run_cmd1 1167 | run_cmd_binary_name 1168 | run_cmd2 1169 | run_cmd_main 1170 | run_cmd3 1171 | run_cmd_out1 1172 | run_cmd_out2 1173 | run_output_files 1174 | run_input_files 1175 | dataset_files 1176 | } 1177 | 1178 | build_compiler_vars - possible compiler variables (often set hardwired dataset) 1179 | } 1180 | """ 1181 | 1182 | # Prepare environment 1183 | rr={'cm_return':0} 1184 | 1185 | # Load OS configuration 1186 | os_uoa='' 1187 | if 'os_uoa' in i and i['os_uoa']!='': os_uoa=i['os_uoa'] 1188 | elif 'cm_default_os_uoa' in cm_kernel.ini['dcfg'] and cm_kernel.ini['dcfg']['cm_default_os_uoa']!='': 1189 | os_uoa=cm_kernel.ini['dcfg']['cm_default_os_uoa'] 1190 | 1191 | if os_uoa=='' not in i: 1192 | return {'cm_return':1, 'cm_error':'"os_uoa" is not defined and not in kernel'} 1193 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 1194 | 'cm_action':'load', 1195 | 'cm_data_uoa':os_uoa} 1196 | r=cm_kernel.access(ii) 1197 | if r['cm_return']>0: return r 1198 | 1199 | os_cfg=r['cm_data_obj']['cfg'] 1200 | os_path=r['cm_path'] 1201 | os_uid=r['cm_uid'] 1202 | os_alias=r['cm_alias'] 1203 | 1204 | run_time={} 1205 | run_input_files=[] 1206 | target_file='' 1207 | 1208 | # Check vars 1209 | if 'code_data_uoa' in i and 'run_cmd_key' in i: 1210 | # Load source code 1211 | m=ini['cm_module_uid'] 1212 | if 'code_module_uoa' in i and i['code_module_uoa']!='': m=i['code_module_uoa'] 1213 | ii={'cm_run_module_uoa':m, 1214 | 'cm_action':'load', 1215 | 'cm_data_uoa':i['code_data_uoa']} 1216 | r=cm_kernel.access(ii) 1217 | if r['cm_return']>0: return r 1218 | 1219 | sc_cfg=r['cm_data_obj']['cfg'] 1220 | sc_path=r['cm_path'] 1221 | sc_uid=r['cm_uid'] 1222 | sc_alias=r['cm_alias'] 1223 | 1224 | # Prepare binary file 1225 | target_file='' 1226 | if 'target_file' in sc_cfg: target_file=os_cfg.get('exec_prefix','')+sc_cfg['target_file'] 1227 | 1228 | add_target_extension1=sc_cfg.get('add_target_extension',{}) 1229 | ct=i.get('compilation_type','') 1230 | if ct=='': ct='static' 1231 | if ct in add_target_extension1: add_target_extension=add_target_extension1.get(ct) 1232 | 1233 | if add_target_extension!='': 1234 | if 'file_extensions' in os_cfg and add_target_extension in os_cfg['file_extensions']: 1235 | target_ext=os_cfg['file_extensions'][add_target_extension] 1236 | target_file+=target_ext 1237 | 1238 | cm_kernel.print_for_con('Prepared target binary name: '+target_file) 1239 | 1240 | # Set vars 1241 | if 'run_cmds' in sc_cfg and i['run_cmd_key'] in sc_cfg['run_cmds']: 1242 | rc=sc_cfg['run_cmds'][i['run_cmd_key']] 1243 | 1244 | run_time=copy.deepcopy(rc.get('run_time',{})) # otherwise change somewhere 1245 | # and it mixes up caching 1246 | 1247 | # Put original input files (useful for mobiles not to mix with dataset files) 1248 | orif=[] 1249 | for q in run_time.get('run_input_files',[]): 1250 | orif.append(q) 1251 | 1252 | # Load dataset 1253 | if i.get('dataset_uoa','')!='': 1254 | cm_kernel.print_for_con('') 1255 | cm_kernel.print_for_con('Loading dataset ...') 1256 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['dataset'], 1257 | 'cm_action':'load', 1258 | 'cm_data_uoa':i['dataset_uoa']} 1259 | r=cm_kernel.access(ii) 1260 | if r['cm_return']>0: return r 1261 | 1262 | ds_cfg=r['cm_data_obj']['cfg'] 1263 | ds_path=r['cm_path'] 1264 | ds_uid=r['cm_uid'] 1265 | ds_alias=r['cm_alias'] 1266 | 1267 | if 'build_compiler_vars' in ds_cfg: 1268 | rr['build_compiler_vars']=ds_cfg['build_compiler_vars'] 1269 | 1270 | if 'run_cmd_main' in run_time: 1271 | ds_path1=ds_path 1272 | os_sep=os_cfg.get('dir_sep','') 1273 | if os_cfg.get('remote','')=='yes': 1274 | ds_path1='' 1275 | os_sep='' 1276 | run_time['run_cmd_main']=run_time['run_cmd_main'].replace(cm_kernel.convert_str_to_special('dataset_path'), ds_path1) 1277 | run_time['run_cmd_main']=run_time['run_cmd_main'].replace(cm_kernel.convert_str_to_special('os_dir_separator'), os_sep) 1278 | 1279 | # Check which path to use for data set 1280 | if 'dataset_files' in ds_cfg and len(ds_cfg['dataset_files'])>0: 1281 | run_time['dataset_files']=ds_cfg['dataset_files'] 1282 | xx=0 1283 | for x in ds_cfg['dataset_files']: 1284 | y='dataset_filename' 1285 | if xx!=0: y+='_'+str(xx) 1286 | run_time['run_cmd_main']=run_time['run_cmd_main'].replace(cm_kernel.convert_str_to_special(y), x) 1287 | xx+=1 1288 | 1289 | # Prepare input files (for remote) 1290 | if 'dataset_files' in ds_cfg and len(ds_cfg['dataset_files'])>0: 1291 | x1=ds_path 1292 | for x2 in ds_cfg['dataset_files']: 1293 | x3=os.path.join(x1,x2) 1294 | if x3 not in run_input_files: run_input_files.append(x3) 1295 | 1296 | # Check cm_properties 1297 | rcm=ds_cfg.get('cm_properties',{}).get('run_time',{}).get('run_cmd_main',{}) 1298 | for x in rcm: 1299 | run_time['run_cmd_main']=run_time['run_cmd_main'].replace(cm_kernel.convert_str_to_special(x), rcm[x]) 1300 | 1301 | run_time['binary_name']=target_file 1302 | rr['run_time']=run_time 1303 | rr['run_time']['original_run_input_files']=orif 1304 | if 'run_input_files' not in rr['run_time']: rr['run_time']['run_input_files']=[] 1305 | for q in run_input_files: 1306 | if q not in rr['run_time']['run_input_files']: rr['run_time']['run_input_files'].append(q) 1307 | 1308 | return rr 1309 | 1310 | # ============================================================================ 1311 | def native_run(i): 1312 | """ 1313 | Native run with timing 1314 | 1315 | Input: { 1316 | cm_unparsed - run 1317 | skip_output - if 'yes', do not print 'Execution time ...' 1318 | } 1319 | 1320 | Output: { 1321 | cm_return - return of the system 1322 | execution_time - execution time of a command 1323 | } 1324 | """ 1325 | 1326 | ucmd=i['cm_unparsed'] 1327 | 1328 | cmd='' 1329 | for q in ucmd: 1330 | cmd+=' '+q 1331 | cmd=cmd.strip() 1332 | 1333 | tstart=time.time() 1334 | 1335 | rc=os.system(cmd) 1336 | 1337 | t=time.time()-tstart 1338 | 1339 | if i.get('skip_output','')!='yes': 1340 | cm_kernel.print_for_con('Execution time: '+"%.3f" % t+' seconds') 1341 | 1342 | return {'cm_return':0, 'execution_time':str(t)} 1343 | -------------------------------------------------------------------------------- /module/package/module.py: -------------------------------------------------------------------------------- 1 | # 2 | # Collective Mind 3 | # 4 | # See cM LICENSE.txt for licensing details. 5 | # See cM Copyright.txt for copyright details. 6 | # 7 | # Developer(s): (C) Grigori Fursin, started on 2011.09 8 | # 9 | 10 | # Should always be here 11 | ini={} 12 | cm_kernel=None 13 | 14 | # Local settings 15 | import shutil 16 | import os 17 | import json 18 | import re 19 | 20 | # ============================================================================ 21 | def init(i): 22 | return {'cm_return':0} 23 | 24 | # ============================================================================ 25 | def install(i): 26 | 27 | """ 28 | Install cM package 29 | 30 | Input: { 31 | package_data_uoa - UOA of package to install 32 | (package_repo_uoa) - repo of the package 33 | package_host_os_uoa - UOA of host OS (to set up script execution) 34 | 35 | (install_data_uid) - UID of the code where package will be installed 36 | if install_data_uid=='' it will be randomly generated 37 | (install_data_alias) - use this alias for a generated entry 38 | (install_data_display_as_alias) - use this display as alias for a generated entry 39 | 40 | If package should be built: 41 | build_target_os_uoa - target OS uoa for building 42 | (code_deps) - list with code UOA for dependencies [{"index":"uoa"} ...] 43 | (run_target_processor_uoa) - target processor UOA (not strictly needed - can add some helper parameters before executing code) 44 | (run_set_env2) - array with environment variables to be set before executable 45 | (add_rem_to_script) - add rem to install script 46 | (add_to_code_entry) - add array to code entry 47 | (skip_extract_and_build) - if 'yes', skip copy, extract and build (by setting CM_SKIP_BUILD=yes) 48 | } 49 | 50 | Output: { 51 | cm_return - return code = 0, if successful 52 | 53 | Output from 'code install' 54 | } 55 | """ 56 | 57 | cm_kernel.print_for_con('***********************************************') 58 | cm_kernel.print_for_con('Installing package ...') 59 | 60 | # Check package UOA 61 | if 'package_data_uoa' not in i: 62 | return {'cm_return':1, 'cm_error':'"package_data_uoa" is not defined'} 63 | package=i['package_data_uoa'] 64 | 65 | # Load package configuration 66 | cm_kernel.print_for_con('') 67 | cm_kernel.print_for_con('Loading info about package '+package+' ...') 68 | 69 | ii={'cm_run_module_uoa':ini['cm_module_uid'], 70 | 'cm_action':'load', 71 | 'cm_data_uoa':package} 72 | if 'package_repo_uoa' in i: ii.update({'cm_repo_uoa':i['package_repo_uoa']}) 73 | r=cm_kernel.access(ii) 74 | if r['cm_return']>0: return r 75 | 76 | package_cfg=r['cm_data_obj']['cfg'] 77 | package_path=r['cm_path'] 78 | package_uid=r['cm_uid'] 79 | package_alias=r['cm_alias'] 80 | 81 | # Set run_set_env2 82 | run_set_env2=package_cfg.get('run_set_env2',{}) 83 | if 'run_set_env2' in i and len(i['run_set_env2'])>0: run_set_env2.update(i['run_set_env2']) 84 | 85 | cm_kernel.print_for_con('') 86 | cm_kernel.print_for_con('Package path: '+package_path) 87 | cm_kernel.print_for_con('Package Alias: '+package_alias) 88 | cm_kernel.print_for_con('Package UID: '+package_uid) 89 | 90 | # Check if need to add something to the code entry 91 | add_to_code_entry=i.get('add_to_code_entry',{}) 92 | if 'add_to_code_entry' in package_cfg: 93 | cm_kernel.merge_arrays({'cm_array':add_to_code_entry, 'cm_array1': package_cfg['add_to_code_entry']}) 94 | 95 | # Load OS configuration 96 | package_host_os_uoa='' 97 | if 'package_host_os_uoa' in i and i['package_host_os_uoa']!='': package_host_os_uoa=i['package_host_os_uoa'] 98 | elif 'cm_default_os_uoa' in cm_kernel.ini['dcfg'] and cm_kernel.ini['dcfg']['cm_default_os_uoa']!='': 99 | package_host_os_uoa=cm_kernel.ini['dcfg']['cm_default_os_uoa'] 100 | 101 | if package_host_os_uoa=='' not in i: 102 | return {'cm_return':1, 'cm_error':'"package_host_os_uoa" is not defined and not in kernel'} 103 | cm_kernel.print_for_con('') 104 | cm_kernel.print_for_con('Loading os '+package_host_os_uoa+' ...') 105 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 106 | 'cm_action':'load', 107 | 'cm_data_uoa':package_host_os_uoa} 108 | r=cm_kernel.access(ii) 109 | if r['cm_return']>0: return r 110 | 111 | target_os_cfg=r['cm_data_obj']['cfg'] 112 | target_os_path=r['cm_path'] 113 | target_os_uid=r['cm_uid'] 114 | target_os_alias=r['cm_alias'] 115 | 116 | # Check if need to build 117 | build=False 118 | if package_cfg.get('build','')=='yes': build=True 119 | 120 | # Check where to copy files before installing: to "code" or to "code.source" 121 | if build: 122 | # Create code source entry 123 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code.source'], 124 | 'cm_action':'update'} 125 | if 'install_data_uid' in i: 126 | ii['cm_data_uoa']=i['install_data_uid'] 127 | else: 128 | ii['cm_data_uoa']=package_uid 129 | if 'add_to_code_source' in package_cfg: 130 | ii['cm_array']=package_cfg['add_to_code_source'] 131 | if 'install_repo_uoa' in i: ii['cm_repo_uoa']=i['install_repo_uoa'] 132 | r=cm_kernel.access(ii) 133 | if r['cm_return']>0: return r 134 | target_path=r['cm_path'] 135 | target_uoa=r['cm_uid'] 136 | else: 137 | # Create code entry 138 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code'], 139 | 'cm_action':'update'} 140 | if 'install_data_uid' in i: ii.update({'cm_data_uid':i['install_data_uid']}) 141 | if 'install_data_alias' in i: ii.update({'cm_data_uoa':i['install_data_alias']}) 142 | if 'install_data_display_as_alias' in i: ii.update({'cm_display_as_alias':i['install_data_display_as_alias']}) 143 | if 'install_repo_uoa' in i: ii['cm_repo_uoa']=i['install_repo_uoa'] 144 | if 'local_src_dir' in package_cfg: 145 | ii['cm_array']={} 146 | ii['cm_array']['local_src_dir']=package_cfg['local_src_dir'] 147 | r=cm_kernel.access(ii) 148 | if r['cm_return']>0: return r 149 | target_path=r['cm_path'] 150 | target_uoa=r['cm_uid'] 151 | 152 | # Install script 153 | install_script_without_ext='' 154 | install_script='' 155 | if 'install_script' in package_cfg: 156 | install_script_without_ext=package_cfg['install_script'] 157 | install_script=install_script_without_ext+target_os_cfg['script_ext'] 158 | 159 | # Copy files 160 | files=[] 161 | if 'cm_files' in package_cfg: files=package_cfg['cm_files'] 162 | if install_script!='': files.append(install_script) 163 | 164 | if len(files)>0: 165 | cm_kernel.print_for_con('') 166 | cm_kernel.print_for_con('Copying files ...') 167 | for f in files: 168 | cm_kernel.print_for_con(' '+f) 169 | f1=os.path.join(package_path, f) 170 | f2=os.path.join(target_path, f) 171 | try: 172 | shutil.copyfile(str(f1),str(f2)) 173 | except IOError as e: 174 | return {'cm_return':1, 'cm_error':'can\'t copy file '+f+' ('+format(e)+')'} 175 | 176 | if i.get('skip_extract_and_build','')!='yes': 177 | 178 | # Extracting 179 | if len(files)>0: 180 | cm_kernel.print_for_con('') 181 | cm_kernel.print_for_con('Check if need to extract files ...') 182 | for f in files: 183 | if f!=install_script: 184 | for ext in target_os_cfg['extract_package']: 185 | if f.endswith(ext): 186 | s=target_os_cfg['change_dir']+' '+target_path+' '+target_os_cfg['env_separator']+\ 187 | target_os_cfg['extract_package'][ext] 188 | s1=s.replace(cm_kernel.convert_str_to_special('cm_file'), f) 189 | s2=s1.replace(cm_kernel.convert_str_to_special('cm_file_without_one_ext'), os.path.splitext(f)[0]) 190 | 191 | cm_kernel.print_for_con('') 192 | cm_kernel.print_for_con(s2) 193 | cm_kernel.print_for_con('') 194 | 195 | r=os.system(str(s2)) 196 | if r!=0: return {'cm_return':1, 'cm_error':'problem while extracting '+f} 197 | 198 | # Set executable 199 | if install_script!='' and 'set_executable' in target_os_cfg: 200 | cm_kernel.print_for_con('') 201 | cm_kernel.print_for_con('Setting permissions for executable ...') 202 | 203 | p1=os.path.join(target_path, install_script) 204 | r=os.system(target_os_cfg['set_executable']+' '+p1) 205 | 206 | # Build 207 | if build: 208 | cm_kernel.print_for_con('') 209 | cm_kernel.print_for_con('Building ...') 210 | else: 211 | cm_kernel.print_for_con('') 212 | cm_kernel.print_for_con('Installing ...') 213 | 214 | if install_script=='': 215 | return {'cm_return':1, 'cm_error':'install script is not defined'} 216 | 217 | # Checking some vars 218 | if 'build_target_os_uoa' not in i: 219 | return {'cm_return':1, 'cm_error':'"build_target_os_uoa" is not defined'} 220 | 221 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code.source'], 222 | 'package_data_uoa':i['package_data_uoa'], 223 | 'cm_action':'build', 224 | 'work_dir_data_uoa':target_uoa, 225 | 'run_script':install_script_without_ext, 226 | 'install':'yes', 227 | 'run_host_os_uoa':i['package_host_os_uoa'], 228 | 'build_target_os_uoa':i['build_target_os_uoa'], 229 | 'run_set_env2':{}} 230 | if build: 231 | ii['work_dir_module_uoa']=ini['cfg']['cm_modules']['code.source'] 232 | else: 233 | ii['work_dir_module_uoa']=ini['cfg']['cm_modules']['code'] 234 | 235 | if 'install_repo_uoa' in i: 236 | ii['work_dir_repo_uoa']=i['install_repo_uoa'] 237 | ii['install_repo_uoa']=i['install_repo_uoa'] 238 | if 'install_data_uid' in i: 239 | ii['install_data_uid']=i['install_data_uid'] 240 | else: ii['install_data_uid']=target_uoa #FGG: need to check that it's correct, i.e. if we install 241 | # something like GCC, that we correctly reuse code & code.source 242 | if 'install_data_alias' in i: ii['install_data_uoa']=i['install_data_alias'] 243 | if 'install_data_display_as_alias' in i: ii['install_data_display_as_alias']=i['install_data_display_as_alias'] 244 | if 'code_deps' in i: ii['code_deps']=i['code_deps'] 245 | if len(run_set_env2)>0: ii['run_set_env2']=run_set_env2 246 | if i.get('skip_extract_and_build','')=='yes': ii['run_set_env2']['CM_SKIP_BUILD']='yes' 247 | if 'run_target_processor_uoa' in i: ii['run_target_processor_uoa']=i['run_target_processor_uoa'] 248 | if 'add_rem_to_script' in i: ii['add_rem_to_script']=i['add_rem_to_script'] 249 | if len(add_to_code_entry)>0: ii['add_to_code_entry']=add_to_code_entry 250 | 251 | rr=cm_kernel.access(ii) 252 | 253 | return rr 254 | 255 | # ============================================================================ 256 | def web_install(i): 257 | 258 | """ 259 | Install cM package/library 260 | 261 | When searching for already installed code, dependencies are checked 262 | * using classes for packages (to allow reuse of packages) 263 | * by exact code_uoa for code.source (to have exact build setup) 264 | 265 | FGG: the checks are a bit ugly and were done in a rush. 266 | Should be simplified, cleaned up and unified one day. 267 | 268 | Input: { 269 | package_data_uoa - UOA of package to install 270 | (package_repo_uoa) - repo of the package 271 | package_host_os_uoa - UOA of host OS (to set up script execution) 272 | 273 | (install_data_uid) - UID of the code where package will be installed 274 | if install_data_uid=='' it will be randomly generated 275 | (install_data_alias) - use this alias for a generated entry 276 | 277 | If package should be built: 278 | build_target_os_uoa - target OS uoa for building 279 | (code_deps) - list with code UOA for dependencies [{"index":"uoa"} ...] 280 | (run_target_processor_uoa) - target processor UOA (not strictly needed - can add some helper parameters before executing code) 281 | (run_set_env2) - array with environment variables to be set before executable 282 | (add_rem_to_script) - add rem to install script 283 | (skip_extract_and_build) - if 'yes', skip copy, extract and build (by setting CM_SKIP_BUILD=yes) 284 | } 285 | 286 | Output: { 287 | cm_return - return code = 0, if successful 288 | 289 | Output from 'code install' 290 | } 291 | """ 292 | 293 | # Get web style 294 | if 'cfg' in cm_kernel.ini['web_style']: web=cm_kernel.ini['web_style']['cfg'] 295 | else: 296 | return {'cm_return':1, 'cm_error':'web style is not defined'} 297 | 298 | cm_kernel.print_for_con('Install / monitor packages
') 299 | 300 | # Detecting/restoring data from forms 301 | a1={} 302 | 303 | r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['cm-web'], 304 | 'cm_action':'detect_form_params', 305 | 'cm_array':i, 306 | 'cm_prefix':'#form1'}) 307 | if r['cm_return']>0: return r 308 | cm_form_array1=r['cm_array'] 309 | cm_form_commands1=r['cm_commands'] 310 | 311 | # Get data description for this action 312 | r=cm_kernel.get_data_description({'cm_module_uoa':ini['cm_module_uoa'], 313 | 'cm_which_action':i['cm_action']}) 314 | if r['cm_return']>0: return r 315 | cm_data_desc1=r['cm_data_desc'] 316 | cm_params_default1=r['cm_params_default'] 317 | 318 | # Check default 319 | if len(cm_form_array1)==0: 320 | a1=cm_params_default1 321 | else: 322 | r=cm_kernel.restore_flattened_array({'cm_array':cm_form_array1, 323 | 'cm_replace_in_keys':{'^35^':'#', '^64^':'@'}}) 324 | if r['cm_return']>0: return r 325 | a1=r['cm_array'] 326 | 327 | # If there is data in form, means that refresh 328 | forms_exists='yes' 329 | if len(cm_form_array1)==0: forms_exists='no' 330 | 331 | if 'skip_extract_and_build' in i: a1['skip_extract_and_build']=i['skip_extract_and_build'] 332 | 333 | # Check if setup is selected and prune choices ********************************************************************* 334 | cm_scen_c='' 335 | cm_scen_p='' 336 | 337 | cm_setup_uoa=a1.get('ctuning_setup_uoa','') 338 | if cm_setup_uoa!='': 339 | # Load setup 340 | ii={} 341 | ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['ctuning.setup'] 342 | ii['cm_action']='load' 343 | ii['cm_data_uoa']=cm_setup_uoa 344 | r=cm_kernel.access(ii) 345 | if r['cm_return']>0: return r 346 | 347 | ds=r['cm_data_obj']['cfg'] 348 | 349 | # Check class 350 | ctuning_scenario_uoa=ds.get('ctuning_scenario_uoa','') 351 | if ctuning_scenario_uoa!='': 352 | ii={} 353 | ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['ctuning.scenario'] 354 | ii['cm_action']='load' 355 | ii['cm_data_uoa']=ctuning_scenario_uoa 356 | r=cm_kernel.access(ii) 357 | if r['cm_return']>0: return r 358 | ds1=r['cm_data_obj']['cfg'] 359 | 360 | cm_scen_c=ds1.get('cm_classes_uoa',[]) 361 | cm_scen_p=ds1.get('cm_properties',{}) 362 | 363 | cm_kernel.print_for_web('
' ) 364 | 365 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['cm-web'], 366 | 'cm_action':'visualize_data', 367 | 'cm_array':a1, 368 | 'cm_data_desc':cm_data_desc1, 369 | 'cm_form_commands':cm_form_commands1, 370 | 'cm_separator':'#', 371 | 'cm_separator_form':'#form1#', 372 | 'cm_forms_exists':forms_exists, 373 | 'cm_support_raw_edit':'no', 374 | 'hide_add_new_object':'yes', 375 | 'cm_mode':'add'} 376 | if 'cm_raw_edit' in i: ii['cm_raw_edit']=i['cm_raw_edit'] 377 | if 'cm_back_json' in i: ii['cm_back_json']=i['cm_back_json'] 378 | r=cm_kernel.access(ii) 379 | if r['cm_return']>0: return r 380 | cm_kernel.print_for_web(r['cm_string']) 381 | 382 | # Pruning vars 383 | cm_t_os_uoa=a1.get('build_target_os_uoa','') 384 | cm_h_os_uoa=a1.get('package_host_os_uoa','') 385 | cm_p_uoa=a1.get('run_target_processor_uoa','') 386 | cm_repo_uoa=a1.get('package_repo_uoa','') 387 | 388 | # Check target OS classes and properties 389 | cm_t_os_c='' 390 | cm_t_os_p='' 391 | if cm_t_os_uoa!='': 392 | ii={} 393 | ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['os'] 394 | ii['cm_action']='load' 395 | ii['cm_data_uoa']=cm_t_os_uoa 396 | r=cm_kernel.access(ii) 397 | if r['cm_return']>0: return r 398 | 399 | cm_t_os_uid=r['cm_uid'] 400 | cm_t_os_uoa=r['cm_uoa'] 401 | 402 | d=r['cm_data_obj']['cfg'] 403 | 404 | cm_t_os_c=d.get('cm_classes_uoa',[]) 405 | cm_t_os_p=d.get('cm_properties',{}) 406 | 407 | cm_h_os_c='' 408 | cm_h_os_p='' 409 | cm_h_os_cfg={} 410 | if cm_h_os_uoa!='': 411 | ii={} 412 | ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['os'] 413 | ii['cm_action']='load' 414 | ii['cm_data_uoa']=cm_h_os_uoa 415 | r=cm_kernel.access(ii) 416 | if r['cm_return']>0: return r 417 | 418 | cm_h_os_uid=r['cm_uid'] 419 | cm_h_os_uoa=r['cm_uoa'] 420 | cm_h_os_cfg=r['cm_data_obj']['cfg'] 421 | 422 | d=cm_h_os_cfg 423 | cm_h_os_c=d.get('cm_classes_uoa',[]) 424 | cm_h_os_p=d.get('cm_properties',{}) 425 | 426 | cm_p_c='' 427 | cm_p_p='' 428 | if cm_p_uoa!='': 429 | ii={} 430 | ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['processor'] 431 | ii['cm_action']='load' 432 | ii['cm_data_uoa']=cm_p_uoa 433 | r=cm_kernel.access(ii) 434 | if r['cm_return']>0: return r 435 | 436 | cm_p_uid=r['cm_uid'] 437 | cm_p_uoa=r['cm_uoa'] 438 | 439 | d=r['cm_data_obj']['cfg'] 440 | 441 | cm_p_c=d.get('cm_classes_uoa',[]) 442 | cm_p_p=d.get('cm_properties',{}) 443 | 444 | 445 | # Get list of packages and libraries *************************************************************************************** 446 | r={} 447 | r['cm_mixed']=[] 448 | 449 | r1=cm_kernel.access({'cm_run_module_uoa':ini['cm_module_uid'], 'cm_action':'list'}) 450 | if r1['cm_return']>0: cm_kernel.print_for_web('cM error: '+r['cm_error']+'
') 451 | for q in r1['cm_mixed']: r['cm_mixed'].append(q) 452 | 453 | for j in ini['cfg']['source_classes_to_install']: 454 | r1=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['code.source'], 'cm_action':'list', \ 455 | 'cm_classes_uoa':[j]}) 456 | if r1['cm_return']>0: cm_kernel.print_for_web('cM error: '+r['cm_error']+'
') 457 | for q in r1['cm_mixed']: 458 | if q not in r['cm_mixed']: r['cm_mixed'].append(q) 459 | 460 | if len(r['cm_mixed'])>0: 461 | pg1=[] 462 | 463 | # List 464 | for xx in sorted(r['cm_mixed'], key=lambda k: tuple(s.lower() if isinstance(s,str) else s for s in k['cm_display_html'])): 465 | x=xx['cm_uoa']; xu=xx['cm_uid']; xa=xx['cm_alias']; xd=xx['cm_display_html'] 466 | # Load data 467 | ii={} 468 | ii['cm_run_module_uoa']=xx['cm_module_uid'] 469 | ii['cm_action']='load' 470 | ii['cm_data_uoa']=xu 471 | r=cm_kernel.access(ii) 472 | if r['cm_return']==0: 473 | d=r['cm_data_obj']['cfg'] 474 | 475 | add=True 476 | 477 | # Check classes 478 | dc=d.get('cm_classes_uoa',{}) 479 | if len(dc)>0: xx['cm_classes_uoa']=dc 480 | 481 | # Check overlaping properties from target OS 482 | dp=d.get('cm_properties',{}) 483 | if len(dp)>0: 484 | xx['cm_properties']=dp 485 | 486 | for q in cm_t_os_p: 487 | if q in dp and cm_t_os_p[q]!=dp[q]: 488 | add=False 489 | break 490 | 491 | # Check dependencies 492 | if add: 493 | dd=d.get('cm_dependencies', {}) 494 | if len(dd)>0: 495 | xx['cm_dependencies']=dd 496 | 497 | if 'scenario' in dd and len(dd['scenario'])>0: 498 | if len(cm_scen_c)>0: 499 | # Class 500 | found=False 501 | for q in cm_scen_c: 502 | if q in dd['scenario']: found=True; break 503 | if not found: add=False 504 | 505 | if 'host_os' in dd and len(dd['host_os'])>0: 506 | if len(cm_h_os_c)>0: 507 | # Class 508 | found=False 509 | for q in cm_h_os_c: 510 | if q in dd['host_os']: found=True; break 511 | if not found: add=False 512 | 513 | if 'target_os' in dd and len(dd['target_os'])>0: 514 | if len(cm_t_os_c)>0: 515 | # Class 516 | found=False 517 | for q in cm_t_os_c: 518 | if q in dd['target_os']: found=True; break 519 | if not found: add=False 520 | 521 | if 'target_processor' in dd and len(dd['target_processor'])>0: 522 | if len(cm_p_c)>0: 523 | # Class 524 | found=False 525 | for q in cm_p_c: 526 | if q in dd['target_processor']: found=True; break 527 | 528 | if not found: add=False 529 | 530 | if add: pg1.append(xx) 531 | 532 | # Sort by deps ******************************************************************************************* 533 | deps=[] 534 | pg=[] 535 | finish=False 536 | prefinish=False 537 | 538 | while not finish: 539 | processed=False 540 | for o in range(0, len(pg1)): 541 | x=pg1[o] 542 | if x!={}: 543 | to_add=False 544 | if 'cm_dependencies' not in x or 'classes' not in x['cm_dependencies']: to_add=True 545 | else: 546 | if 'classes' in x['cm_dependencies']: 547 | found_all=True 548 | for qq in x['cm_dependencies']['classes']: 549 | if qq not in deps: 550 | found_all=False; break 551 | if found_all: to_add=True 552 | 553 | # Check remaining deps 554 | if not prefinish: 555 | if to_add: 556 | for oo1 in range(0, len(pg1)): 557 | if oo1!=o: 558 | oo=pg1[oo1] 559 | if oo!={} and 'cm_classes_uoa' in oo: 560 | deps1=oo['cm_classes_uoa'] 561 | failed=False 562 | for qq in x['cm_dependencies']['classes']: 563 | if qq in deps1: 564 | failed=True; break 565 | if failed: to_add=False 566 | 567 | if to_add: 568 | if 'cm_classes_uoa' in x: 569 | for q in x['cm_classes_uoa']: 570 | if q not in deps: deps.append(q) 571 | pg.append(x) 572 | pg1[o]={} 573 | processed=True 574 | 575 | if not processed: 576 | if prefinish: finish=True 577 | else: prefinish=True 578 | else: 579 | pg.append({}) 580 | 581 | # Cache all code to check status 582 | codes={} 583 | codes_repo={} 584 | if cm_t_os_uoa!='' and cm_p_uoa!='': 585 | ii={} 586 | ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['code'] 587 | ii['cm_action']='list' 588 | r=cm_kernel.access(ii) 589 | if r['cm_return']==0: 590 | for q in r['cm_mixed']: 591 | # Load data 592 | ii={} 593 | ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['code'] 594 | ii['cm_action']='load' 595 | ii['cm_data_uoa']=q['cm_uid'] 596 | rx=cm_kernel.access(ii) 597 | if rx['cm_return']==0: 598 | codes[rx['cm_uid']]=rx['cm_data_obj']['cfg'] 599 | codes_repo[rx['cm_uid']]=rx['cm_repo_uid'] 600 | 601 | # Load all classes 602 | classes={} 603 | classes_install={} 604 | classes_install_static={} 605 | 606 | # View ************************************************************************************************* 607 | line=True; 608 | x1='' 609 | if 'table_bgcolor_line1' in web: x1=' bgcolor="'+web['table_bgcolor_line1']+'" ' 610 | x2='' 611 | if 'table_bgcolor_line2' in web: x2=' bgcolor="'+web['table_bgcolor_line2']+'" ' 612 | x3='' 613 | if 'table_bgcolor_line3' in web: x3=' bgcolor="'+web['table_bgcolor_line3']+'" ' 614 | x4='' 615 | if 'table_bgcolor_line4' in web: x4=' bgcolor="'+web['table_bgcolor_line4']+'" ' 616 | 617 | all_installed_uids=[] 618 | 619 | cm_kernel.print_for_web(web['table_init']) 620 | 621 | cm_kernel.print_for_con('') 622 | cm_kernel.print_for_con('Package name:') 623 | cm_kernel.print_for_con('Classes:') 624 | cm_kernel.print_for_con('Dependencies:') 625 | cm_kernel.print_for_con('Install/code UID:') 626 | cm_kernel.print_for_con('Install Status:') 627 | cm_kernel.print_for_con('Install:') 628 | cm_kernel.print_for_con('') 629 | 630 | for xx in pg: 631 | cm_kernel.print_for_con('') 632 | 633 | if xx!={}: 634 | x=xx['cm_uoa']; xu=xx['cm_uid']; xa=xx['cm_alias']; xd=xx['cm_display_html']; xda=xx['cm_display_as_alias'] 635 | 636 | # If compiler is selected, remove itself from the list of packages! 637 | # otherwise had problem with LLVM depending on OpenME 638 | ign=False 639 | if xu==a1['compiler_code_uoa']: ign=True 640 | 641 | if True: 642 | cc=xx.get('cm_classes_uoa',[]) 643 | cd=xx.get('cm_dependencies',{}).get('classes',[]) 644 | 645 | cx=[] 646 | for c in cc: cx.append(c) 647 | for c in cd: cx.append(c) 648 | for c in cx: 649 | if c not in classes: 650 | #Load class to get name 651 | ii={} 652 | ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['class'] 653 | ii['cm_action']='load' 654 | ii['cm_data_uoa']=c 655 | rx=cm_kernel.access(ii) 656 | if rx['cm_return']>0: return rx 657 | else: classes[c]=rx 658 | if line: 659 | line=False; 660 | if xx['cm_module_uid']==ini['cm_module_uid']: x=x1 661 | else: x=x3 662 | else: 663 | line=True 664 | if xx['cm_module_uid']==ini['cm_module_uid']: x=x2 665 | else: x=x4 666 | cm_kernel.print_for_con('') 667 | 668 | # sou=web['http_prefix']+'cm_menu='+web['cm_menu_browse']+'&cm_subaction_view&browse_cid='+xx['cm_module_uid']+':'+xu 669 | sou=web['http_prefix']+'view_cid='+xx['cm_module_uid']+':'+xu 670 | y=''+xd+'' 671 | 672 | cm_kernel.print_for_web(''+y+'') 673 | cm_kernel.print_for_web('') 674 | first=True; y='' 675 | for c in cc: 676 | if first: first=False 677 | else: y+='
' 678 | y+=classes[c]['cm_display_html'] 679 | cm_kernel.print_for_con(y) 680 | cm_kernel.print_for_web('
') 681 | 682 | 683 | cm_kernel.print_for_web('') 684 | 685 | # If not self-reference, print dependences, otherwise show self-reference 686 | if ign: 687 | cm_kernel.print_for_web('Self-reference, dependencies will not be shown') 688 | else: 689 | failed_deps=False 690 | code_deps=[] 691 | code_deps1=[] 692 | code_deps2=[] 693 | compiler_name='' 694 | 695 | if len(cd)>0: 696 | y='' 697 | iz=0 698 | for c in cd: 699 | iz+=1 700 | z1='';z2='' 701 | 702 | if c not in classes_install and c: 703 | z1='';z2='' 704 | failed_deps=True 705 | y+='' 706 | 707 | if c in classes_install: 708 | yy='' 709 | name='package_web_install_'+xu+'_'+c 710 | value=i.get(name,'') 711 | jq='' 712 | 713 | yz={} 714 | if c in classes_install_static: yz=classes_install_static[c] 715 | elif c in classes_install: yz=classes_install[c] 716 | 717 | if c==ini['cfg']['cm_class_compiler']: 718 | # found_compiler=False 719 | # for j in classes_install[c]: 720 | # if a1['compiler_code_uoa']==j['code_uid']: 721 | # jq={'code_uid':a1['compiler_code_uoa']} 722 | # compiler_name=j['name'] 723 | # yy=''+compiler_name+'' 724 | # found_compiler=True 725 | # break 726 | # if not found_compiler: failed_deps=True 727 | 728 | # FGG removed check for deps here otherwise problem with LLVM 3.2 with OpenME 729 | jq={'code_uid':a1['compiler_code_uoa']} 730 | 731 | compiler_name=a1['compiler_code_uoa'] 732 | 733 | # Load compiler code to get package_uoa 734 | rx=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['code'], 735 | 'cm_action':'load', 736 | 'cm_data_uoa':a1['compiler_code_uoa']}) 737 | if rx['cm_return']==0: 738 | compiler_package_uoa=rx['cm_data_obj']['cfg'].get('state_input',{}).get('package_data_uoa','') 739 | 740 | if compiler_package_uoa!='': 741 | # Load package 742 | rx=cm_kernel.access({'cm_run_module_uoa':ini['cm_module_uid'], 743 | 'cm_action':'load', 744 | 'cm_data_uoa':compiler_package_uoa}) 745 | if rx['cm_return']==0: 746 | compiler_name=rx['cm_data_obj']['cfg'].get('cm_display_as_alias','') 747 | if compiler_name=='': compiler_name=rx['cm_uoa'] 748 | 749 | yy=''+compiler_name+'' 750 | else: 751 | yy='' 762 | y+='' 763 | 764 | if jq=='' and len(yz)>0: jq=yz[0] 765 | 766 | if jq!='': 767 | code_deps_var=classes[c]['cm_data_obj']['cfg'].get('code_deps_var','') 768 | if code_deps_var!='': 769 | code_deps.append({code_deps_var:jq['code_uid']}) 770 | code_deps1.append({c:jq['code_uid']}) 771 | if c!=ini['cfg']['cm_class_compiler']: 772 | code_deps2.append({c:jq['code_uid']}) 773 | y+='
'+z1+str(iz)+') '+classes[c]['cm_display_as_alias']+z2+''+yy+'
' 774 | cm_kernel.print_for_con(y) 775 | 776 | cm_kernel.print_for_web('
') 777 | 778 | # Check status and deps ************************************************************************ 779 | found=False 780 | y='' 781 | z='' 782 | if not failed_deps and cm_t_os_uoa!='' and cm_p_uoa!='': 783 | qr='' 784 | for q in codes: 785 | qq=codes[q] 786 | 787 | qqd=qq.get('cm_source_data_uoa','') 788 | qqm=qq.get('cm_source_module_uoa','') 789 | 790 | success=False 791 | if qq.get('build_finished_successfully','')=='yes': success=True 792 | 793 | # Check package/source code 794 | if (qqd!=xu or qqm!=xx['cm_module_uid']): 795 | continue 796 | 797 | add=True 798 | if xx['cm_module_uid']==ini['cm_module_uid']: 799 | 800 | si=qq.get('state_input',{}) 801 | qqp=si.get('run_target_processor_uoa','') 802 | qqbtos=si.get('build_target_os_uoa','') 803 | qqwd=si.get('package_data_uoa','') 804 | if qqwd=='': qqwd=si.get('work_dir_data_uoa','') 805 | 806 | # for packages, we use comparison by class (less restrictive) to reuse packages for different setups 807 | dd=qq 808 | if 'host_os' in dd: 809 | # Prune by target OS 810 | if len(cm_h_os_c)>0: 811 | # Class 812 | found=False 813 | for q in cm_h_os_c: 814 | if q in dd['host_os']: found=True; break 815 | if not found: add=False 816 | if not add: continue 817 | 818 | if 'target_os' in dd: 819 | # Prune by target OS 820 | if len(cm_t_os_c)>0: 821 | # Class 822 | found=False 823 | for q in cm_t_os_c: 824 | if q in dd['target_os']: found=True; break 825 | if not found: add=False 826 | if not add: continue 827 | 828 | if 'target_processor' in dd: 829 | # Prune by target OS 830 | if len(cm_p_c)>0: 831 | # Class 832 | found=False 833 | for q in cm_p_c: 834 | if q in dd['target_processor']: found=True; break 835 | if not found: add=False 836 | if not add: continue 837 | else: 838 | # Check deps ************************************************************************************** 839 | # for libraries, we use exact comparison by UID for a given setup 840 | add=False 841 | 842 | rdep=qq.get('cm_dependencies_real',{}) 843 | 844 | if rdep.get('host_os','')!='' and rdep['host_os']!=cm_h_os_uid: continue 845 | if rdep.get('target_os','')!='' and rdep['target_os']!=cm_t_os_uid: continue 846 | if rdep.get('target_processor','')!='' and rdep['target_processor']!=cm_p_uid: continue 847 | 848 | add=True 849 | j=rdep.get('classes',{}) 850 | for t in j: 851 | t1=t.keys()[0] 852 | t2=t[t1] 853 | found=False 854 | for e in code_deps1: 855 | e1=e.keys()[0] 856 | e2=e[e1] 857 | if e1==t1 and e2==t2: found=True; break 858 | if not found: 859 | add=False 860 | break 861 | 862 | if not add: continue 863 | 864 | if rdep.get('compilation_type','')!='' and a1.get('compilation_type','')!=rdep['compilation_type']: 865 | add=False 866 | found=False 867 | continue 868 | 869 | if rdep.get('compilation_type','')=='static': 870 | qxd=qq.get('cm_display_as_alias','') 871 | if qxd=='': qxd=xd 872 | for j in cc: 873 | if j not in classes_install_static: 874 | classes_install_static[j]=[{'code_uid':q, 'name':qxd}] 875 | else: 876 | if q not in classes_install_static[j]: 877 | classes_install_static[j].append({'code_uid':q, 'name':qxd}) 878 | 879 | if add: qr=q 880 | 881 | if qr!='': 882 | sou=web['http_prefix']+'cm_menu='+web['cm_menu_browse']+'&cm_subaction_view&browse_cid='+ini['cfg']['cm_modules']['code']+':'+qr 883 | y=''+qr+'' 884 | qq=codes[qr] 885 | all_installed_uids.append(qr) 886 | 887 | success=False 888 | if qq.get('build_finished_successfully','')=='yes': success=True 889 | 890 | if success: 891 | z='Success' 892 | qxd=qq.get('cm_display_as_alias','') 893 | if qxd=='': qxd=xd 894 | for j in cc: 895 | if j not in classes_install: 896 | classes_install[j]=[{'code_uid':qr, 'name':qxd}] 897 | else: 898 | if qr not in classes_install[j]: classes_install[j].append({'code_uid':qr, 'name':qxd}) 899 | 900 | else: 901 | z='Not finished
(either in progress or error)
' 902 | 903 | found=True 904 | 905 | cm_kernel.print_for_web(''+y+'') 906 | cm_kernel.print_for_web(''+z+'') 907 | 908 | z='' 909 | y='' 910 | if not failed_deps and cm_t_os_uoa!='' and cm_p_uoa!='' and not ign: 911 | # Check if enough params for an install button 912 | cm_json={} 913 | rem=[] 914 | rm=cm_h_os_cfg.get('rem','') 915 | 916 | # Load package or source-code to check default build script 917 | ii={} 918 | ii['cm_run_module_uoa']=xx['cm_module_uid'] 919 | ii['cm_action']='load' 920 | ii['cm_data_uoa']=xx['cm_uid'] 921 | rx=cm_kernel.access(ii) 922 | if rx['cm_return']>0: return rx 923 | d1=rx['cm_data_obj']['cfg'] 924 | 925 | if xx['cm_module_uid']==ini['cm_module_uid']: 926 | rem.append(rm+' package: '+str(xd)) 927 | cm_json['install_data_display_as_alias']=str(xd) 928 | y1='Install' 929 | if not failed_deps and cm_t_os_uoa!='' and cm_h_os_uoa!='' and cm_p_uoa!='': 930 | z=web['http_prefix']+'cm_web_module_uoa=package&cm_web_action=install&package_data_uoa='+xu+\ 931 | '&package_host_os_uoa='+cm_h_os_uoa+'&build_target_os_uoa='+cm_t_os_uoa+\ 932 | '&run_target_processor_uoa='+cm_p_uoa+'&cm_detach_console=yes' 933 | if found: 934 | z+='&install_data_uid='+qr+'&install_repo_uoa='+codes_repo[qr] 935 | y1='Re-install' 936 | elif cm_repo_uoa!='': 937 | z+='&install_repo_uoa='+cm_repo_uoa 938 | else: 939 | rem.append(rm+' package: '+str(xd)+' - '+compiler_name+' - '+a1.get('compilation_type','')) 940 | cm_json['install_data_display_as_alias']=str(xd)+' - '+compiler_name+' - '+a1.get('compilation_type','') 941 | y1='Build' 942 | if not failed_deps and cm_t_os_uoa!='' and cm_h_os_uoa!='' and cm_p_uoa!='': 943 | z=web['http_prefix']+'cm_menu=scenarios&cm_submenu=ctuning_code_source_build' 944 | 945 | cm_json['#form1##run_host_os_uoa']=cm_h_os_uoa 946 | cm_json['#form1##build_target_os_uoa']=cm_t_os_uoa 947 | cm_json['#form1##run_target_processor_uoa']=cm_p_uoa 948 | cm_json['#form1##work_dir_data_uoa']=xu 949 | cm_json['#form1##work_dir_repo_uoa']='' 950 | cm_json['#form1##install']='yes' 951 | if 'ctuning_setup_uoa' in a1: cm_json['#form1##ctuning_setup_uoa']=a1['ctuning_setup_uoa'] 952 | if 'package_repo_uoa' in a1: cm_json['#form1##install_repo_uoa']=a1['package_repo_uoa'] 953 | cross_build_static_lib=False 954 | if 'compiler_code_uoa' in a1: 955 | cm_json['#form1##compiler_code_uoa']=a1['compiler_code_uoa'] 956 | 957 | # Load compiler code to check if cross-compile 958 | rx=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['code'], 959 | 'cm_action':'load', 960 | 'cm_data_uoa':a1['compiler_code_uoa']}) 961 | if rx['cm_return']==0: 962 | drx=rx['cm_data_obj']['cfg'] 963 | if drx.get('build_params',{}).get('cross_build_static_lib','')=='yes': 964 | cross_build_static_lib=True 965 | 966 | if 'compilation_type' in a1: cm_json['#form1##compilation_type']=a1['compilation_type'] 967 | 968 | # Always force dependencies even if empty 969 | cm_json['#form1##cm_dependencies']=code_deps2 970 | 971 | if found: 972 | y1='Re-build' 973 | cm_json['#form1##install_data_uid']=qr 974 | 975 | if 'build_scripts_uoa' in d1: 976 | cm_json['#form1##build_run_script_uoa']=d1['build_scripts_uoa'][0] 977 | 978 | if cross_build_static_lib and 'build_scripts_names' in d1: 979 | for j in d1['build_scripts_names']: 980 | for jj in d1['build_scripts_names'][j]: 981 | if 'cross_build_static_lib' in jj: 982 | cm_json['#form1##build_run_script']=jj 983 | break 984 | 985 | cm_json['add_rem_to_script']=rem 986 | 987 | cm_json['code_deps']=code_deps 988 | 989 | if 'keep_all_files' in a1 and a1['keep_all_files']!='': cm_json['keep_all_files']=a1['keep_all_files'] 990 | 991 | if 'skip_extract_and_build' in a1: cm_json['skip_extract_and_build']=a1['skip_extract_and_build'] 992 | if 'number_of_parallel_jobs_for_build' in a1: 993 | cm_json['run_set_env2']={} 994 | cm_json['run_set_env2']['CM_PARALLEL_JOB_NUMBER']=a1['number_of_parallel_jobs_for_build'] 995 | 996 | package_info={} 997 | if 'cm_classes_uoa' in xx: package_info['cm_classes_uoa']=xx['cm_classes_uoa'] 998 | if 'cm_properties' in xx: package_info['cm_properties']=xx['cm_properties'] 999 | if 'cm_dependencies' in xx: package_info['cm_dependencies']=xx['cm_dependencies'] 1000 | 1001 | package_info['cm_source_data_uoa']=xu 1002 | package_info['cm_source_module_uoa']=xx['cm_module_uid'] 1003 | 1004 | # Prepare real dependencies 1005 | 1006 | package_info['cm_dependencies_real']={} 1007 | 1008 | package_info['cm_dependencies_real']['classes']=code_deps1 1009 | 1010 | dd=d1.get('cm_dependencies',{}) 1011 | if 'host_os' in dd: package_info['cm_dependencies_real']['host_os']=cm_h_os_uid 1012 | if 'target_os' in dd: package_info['cm_dependencies_real']['target_os']=cm_t_os_uid 1013 | if 'target_processor' in dd: package_info['cm_dependencies_real']['target_processor']=cm_p_uid 1014 | 1015 | # Check if package requires compilation, and then record compiler and compilation type 1016 | if 'classes' in dd and ini['cfg']['cm_classes']['compiler'] in dd['classes']: 1017 | if 'compiler_code_uoa' in a1: 1018 | package_info['cm_dependencies_real']['compiler_code_uoa']=a1['compiler_code_uoa'] 1019 | if 'compilation_type' in a1: 1020 | package_info['cm_dependencies_real']['compilation_type']=a1['compilation_type'] 1021 | 1022 | cm_json['add_to_code_entry']=package_info 1023 | 1024 | rx=cm_kernel.convert_cm_array_to_uri({'cm_array':cm_json}) 1025 | if rx['cm_return']>0: return rx 1026 | 1027 | z+='&cm_json='+rx['cm_string'] 1028 | 1029 | y=''+y1+'' 1030 | 1031 | cm_kernel.print_for_web(''+y+'') 1032 | 1033 | else: 1034 | cm_kernel.print_for_con('
') 1035 | 1036 | cm_kernel.print_for_con('') 1037 | 1038 | cm_kernel.print_for_con('') 1039 | 1040 | cm_kernel.print_for_con('All installed UIDs:
') 1041 | for q in all_installed_uids: 1042 | cm_kernel.print_for_con(' '+q) 1043 | cm_kernel.print_for_con('

') 1044 | 1045 | 1046 | cm_kernel.print_for_con('') 1047 | 1048 | cm_kernel.print_for_con('') 1049 | 1050 | return {'cm_return':0} 1051 | 1052 | # ============================================================================ 1053 | def installed(i): 1054 | 1055 | """ 1056 | List installed packages 1057 | 1058 | Input: { 1059 | (code_repo_uoa) - repo UOA to list code 1060 | (prune_by_class_uoa) - prune by 1 class UOA 1061 | (prune_by_name) - prune by name (checks for inclusion; case insensitive) 1062 | (fuzzy_match) - if 'yes', check inclusion of 'prune_by_name' in name, otherwise exact match 1063 | (prune_by_name_uoa) - prune by name UOA 1064 | (prune_by_type) - prune by "library_or_plugin" or "package" 1065 | (prune_by_host_os) - prune by host os 1066 | (prune_by_target_os) - prune by target os 1067 | (prune_by_target_processor) - prune by target processor 1068 | (prune_by_compiler) - if library or plugin, prune by compiler 1069 | (prune_by_os_from_kernel) - if 'yes', take OS from kernel 1070 | (only_uoa) - return only UOA 1071 | } 1072 | 1073 | Output: { 1074 | cm_return - return code = 0, if successful 1075 | final - list with code entries in cM 'list' format 1076 | } 1077 | """ 1078 | 1079 | # Checking some pruning parameters 1080 | pbcu=i.get('prune_by_class_uoa','') 1081 | pbn=i.get('prune_by_name','').lower() 1082 | fm=i.get('fuzzy_match','') 1083 | pbnu=i.get('prune_by_name_uoa','') 1084 | pbt=i.get('prune_by_type','').lower() 1085 | pbho=i.get('prune_by_host_os','').lower() 1086 | pbto=i.get('prune_by_target_os','').lower() 1087 | pbtp=i.get('prune_by_target_processor','').lower() 1088 | pbc=i.get('prune_by_compiler','').lower() 1089 | 1090 | ou=i.get('only_uoa','') 1091 | 1092 | pik=i.get('prune_by_os_from_kernel','') 1093 | if pik!='': 1094 | dos=cm_kernel.ini['dcfg'].get('cm_default_os_uoa','') 1095 | r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 'cm_action':'load', 'cm_data_uoa':dos}) 1096 | if r['cm_return']>0: return r 1097 | if r['cm_alias']!='': dos=r['cm_alias'] 1098 | 1099 | pbho=dos 1100 | pbto=dos 1101 | 1102 | ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code'], 1103 | 'cm_action':'list', 1104 | } 1105 | if i.get('code_repo_uoa','')!='': ii['cm_repo_uoa']=i['code_repo_uoa'] 1106 | r=cm_kernel.access(ii) 1107 | if r['cm_return']>0: return r 1108 | 1109 | m=r['cm_mixed'] 1110 | ms=sorted(m, key=lambda k: k['cm_display_as_alias']) 1111 | 1112 | final=[] 1113 | for q in ms: 1114 | d=q['cm_data_obj_cfg'] 1115 | bfs=d.get('build_finished_successfully','') 1116 | cl=d.get('cm_classes_uoa',[]) 1117 | 1118 | show=True 1119 | if pbcu!='' and pbcu not in cl: 1120 | show=False 1121 | 1122 | if show: 1123 | if bfs=='' or bfs=='yes': 1124 | si=d.get('state_input',{}) 1125 | pack=si.get('package_data_uoa','') 1126 | source=si.get('work_dir_data_uoa','') 1127 | 1128 | show=True 1129 | if pbnu!='' and not (pbnu==pack or pbnu==source): 1130 | show=False 1131 | 1132 | if show: 1133 | if pack!='' or source!='': 1134 | xcompiler='' 1135 | if pack=='': 1136 | # If library/plugin ************** 1137 | lib=True 1138 | t='library/plugin' 1139 | t1='library_or_plugin' 1140 | 1141 | r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['code.source'], 'cm_action':'load', 'cm_data_uoa':source}) 1142 | if r['cm_return']==0: 1143 | name=r.get('cm_display_as_alias',source) 1144 | 1145 | cc_uoa=d.get('cm_dependencies_real',{}).get('compiler_code_uoa','') 1146 | r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['code'], 'cm_action':'load', 'cm_data_uoa':cc_uoa}) 1147 | if r['cm_return']==0: 1148 | cp_uoa=r['cm_data_obj']['cfg'].get('state_input',{}).get('package_data_uoa','') 1149 | 1150 | if cp_uoa!='': 1151 | r=cm_kernel.access({'cm_run_module_uoa':ini['cm_module_uid'], 'cm_action':'load', 'cm_data_uoa':cp_uoa}) 1152 | if r['cm_return']==0: 1153 | xcompiler='"'+r.get('cm_display_as_alias',cp_uoa)+'"' 1154 | else: 1155 | # If package ************** 1156 | lib=False 1157 | t='package' 1158 | t1=t 1159 | r=cm_kernel.access({'cm_run_module_uoa':ini['cm_module_uid'], 'cm_action':'load', 'cm_data_uoa':pack}) 1160 | if r['cm_return']==0: 1161 | name=r.get('cm_display_as_alias',pack) 1162 | 1163 | show=True 1164 | 1165 | if pbt!='' and pbt!=t1: 1166 | show=False 1167 | elif pbn!='': 1168 | if fm=='yes' and not pbn in name.lower(): #re.match(pbn,name.lower())): 1169 | show=False 1170 | elif pbn!='' and fm!='yes' and pbn!=name.lower(): #re.match(pbn,name.lower())): 1171 | show=False 1172 | elif t=='library/plugin' and pbc!='': 1173 | if fm=='yes' and not pbc in xcompiler.lower(): 1174 | show=False 1175 | elif fm!='yes' and pbc!=xcompiler.lower(): 1176 | show=False 1177 | 1178 | if show: 1179 | st='%14s' % t 1180 | 1181 | cm_uoa=q['cm_uoa'] 1182 | cm_uid=q['cm_uid'] 1183 | daa=q.get('cm_display_as_alias','') 1184 | 1185 | # Get host OS 1186 | ho=si.get('run_host_os_uoa','') 1187 | xho=ho 1188 | xho1=ho 1189 | r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 'cm_action':'load', 'cm_data_uoa':ho}) 1190 | if r['cm_return']>0: return r 1191 | if r['cm_alias']!='': 1192 | xho=r['cm_alias'] 1193 | xho1=r['cm_uid'] 1194 | 1195 | # Get target OS 1196 | to=si.get('build_target_os_uoa','') 1197 | xto=to 1198 | xto1=to 1199 | r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 'cm_action':'load', 'cm_data_uoa':to}) 1200 | if r['cm_return']>0: return r 1201 | if r['cm_alias']!='': 1202 | xto=r['cm_alias'] 1203 | xto1=r['cm_uid'] 1204 | 1205 | # Get target processor 1206 | tp=si.get('run_target_processor_uoa','') 1207 | xtp=tp 1208 | xtp1=tp 1209 | r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['processor'], 'cm_action':'load', 'cm_data_uoa':tp}) 1210 | if r['cm_return']>0: return r 1211 | if r['cm_alias']!='': 1212 | xtp=r['cm_alias'] 1213 | xtp1=r['cm_uid'] 1214 | 1215 | sto='%25s' % xto 1216 | stp='%16s' % xtp 1217 | sho='%25s' % xho 1218 | 1219 | show=True 1220 | 1221 | if pbho!='' and pbho!=xho and pbho!=xho1: 1222 | show=False 1223 | elif pbto!='' and pbto!=xto and pbto!=xto1: 1224 | show=False 1225 | elif pbtp!='' and pbtp!=xtp and pbtp!=xtp1: 1226 | show=False 1227 | 1228 | if show: 1229 | final.append(q) 1230 | if i.get('cm_console','')=='txt': 1231 | if ou=='': 1232 | cm_kernel.print_for_con(cm_uoa+' '+st+' '+sho+' '+sto+' '+stp+' "'+name+'"'+' '+xcompiler) 1233 | cm_kernel.print_for_con('') 1234 | else: 1235 | cm_kernel.print_for_con(cm_uoa) 1236 | 1237 | return {'cm_return':0, 'final':final} 1238 | --------------------------------------------------------------------------------