Welcome    Usage    Browse    Find CID    Search     Log in

cM API Documentation

module.py

Go to the documentation of this file.
00001 #
00002 # Collective Mind
00003 #
00004 # See cM LICENSE.txt for licensing details.
00005 # See cM Copyright.txt for copyright details.
00006 #
00007 # Developer(s): (C) Grigori Fursin, started on 2011.09
00008 #
00009 
00010 # Should always be here
00011 ini={}
00012 cm_kernel=None
00013 
00014 # Local settings
00015 import shutil
00016 import os
00017 import json
00018 import re
00019 
00020 # ============================================================================
00021 def init(i):
00022     return {'cm_return':0}
00023 
00024 # ============================================================================
00025 def install(i):
00026 
00027     """
00028     Install cM package
00029 
00030     Input:  {
00031               package_data_uoa                - UOA of package to install
00032               (package_repo_uoa)              - repo of the package
00033               package_host_os_uoa             - UOA of host OS (to set up script execution)
00034 
00035               (install_data_uid)              - UID of the code where package will be installed
00036                                                 if install_data_uid=='' it will be randomly generated
00037               (install_data_alias)            - use this alias for a generated entry
00038               (install_data_display_as_alias) - use this display as alias for a generated entry
00039 
00040                 If package should be built:
00041               build_target_os_uoa             - target OS uoa for building
00042               (code_deps)                     - list with code UOA for dependencies [{"index":"uoa"} ...]
00043               (run_target_processor_uoa)      - target processor UOA (not strictly needed - can add some helper parameters before executing code)
00044               (run_set_env2)                  - array with environment variables to be set before executable
00045               (add_rem_to_script)             - add rem to install script
00046               (add_to_code_entry)             - add array to code entry
00047               (skip_extract_and_build)        - if 'yes', skip copy, extract and build (by setting CM_SKIP_BUILD=yes)
00048             }
00049 
00050     Output: {
00051               cm_return - return code = 0, if successful
00052 
00053               Output from 'code install'
00054             }
00055     """
00056 
00057     cm_kernel.print_for_con('***********************************************')
00058     cm_kernel.print_for_con('Installing package ...')
00059 
00060     # Check package UOA
00061     if 'package_data_uoa' not in i:
00062        return {'cm_return':1, 'cm_error':'"package_data_uoa" is not defined'}
00063     package=i['package_data_uoa']
00064 
00065     # Load package configuration
00066     cm_kernel.print_for_con('')
00067     cm_kernel.print_for_con('Loading info about package '+package+' ...')
00068 
00069     ii={'cm_run_module_uoa':ini['cm_module_uid'],
00070         'cm_action':'load',
00071         'cm_data_uoa':package}
00072     if 'package_repo_uoa' in i: ii.update({'cm_repo_uoa':i['package_repo_uoa']})
00073     r=cm_kernel.access(ii)
00074     if r['cm_return']>0: return r
00075 
00076     package_cfg=r['cm_data_obj']['cfg']
00077     package_path=r['cm_path']
00078     package_uid=r['cm_uid']
00079     package_alias=r['cm_alias']
00080 
00081     # Set run_set_env2
00082     run_set_env2=package_cfg.get('run_set_env2',{})
00083     if 'run_set_env2' in i and len(i['run_set_env2'])>0: run_set_env2.update(i['run_set_env2'])
00084 
00085     cm_kernel.print_for_con('')
00086     cm_kernel.print_for_con('Package path:  '+package_path)
00087     cm_kernel.print_for_con('Package Alias: '+package_alias)
00088     cm_kernel.print_for_con('Package UID:   '+package_uid)
00089 
00090     # Check if need to add something to the code entry
00091     add_to_code_entry=i.get('add_to_code_entry',{})
00092     if 'add_to_code_entry' in package_cfg: 
00093        cm_kernel.merge_arrays({'cm_array':add_to_code_entry, 'cm_array1': package_cfg['add_to_code_entry']})
00094 
00095     # Load OS configuration
00096     package_host_os_uoa=''
00097     if 'package_host_os_uoa' in i and i['package_host_os_uoa']!='': package_host_os_uoa=i['package_host_os_uoa']
00098     elif 'cm_default_os_uoa' in cm_kernel.ini['dcfg'] and cm_kernel.ini['dcfg']['cm_default_os_uoa']!='':
00099        package_host_os_uoa=cm_kernel.ini['dcfg']['cm_default_os_uoa']
00100 
00101     if package_host_os_uoa=='' not in i:
00102        return {'cm_return':1, 'cm_error':'"package_host_os_uoa" is not defined and not in kernel'}
00103     cm_kernel.print_for_con('')
00104     cm_kernel.print_for_con('Loading os '+package_host_os_uoa+' ...')
00105     ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['os'],
00106         'cm_action':'load',
00107         'cm_data_uoa':package_host_os_uoa}
00108     r=cm_kernel.access(ii)
00109     if r['cm_return']>0: return r
00110 
00111     target_os_cfg=r['cm_data_obj']['cfg']
00112     target_os_path=r['cm_path']
00113     target_os_uid=r['cm_uid']
00114     target_os_alias=r['cm_alias']
00115 
00116     # Check if need to build
00117     build=False
00118     if package_cfg.get('build','')=='yes': build=True
00119 
00120     # Check where to copy files before installing: to "code" or to "code.source"
00121     if build:
00122        # Create code source entry
00123        ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code.source'],
00124            'cm_action':'update'}
00125        if 'install_data_uid' in i: 
00126           ii['cm_data_uoa']=i['install_data_uid']
00127        else:
00128           ii['cm_data_uoa']=package_uid
00129        if 'add_to_code_source' in package_cfg:
00130           ii['cm_array']=package_cfg['add_to_code_source']
00131        if 'install_repo_uoa' in i: ii['cm_repo_uoa']=i['install_repo_uoa']
00132        r=cm_kernel.access(ii)
00133        if r['cm_return']>0: return r
00134        target_path=r['cm_path']
00135        target_uoa=r['cm_uid']
00136     else:
00137        # Create code entry
00138        ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code'],
00139            'cm_action':'update'}
00140        if 'install_data_uid' in i: ii.update({'cm_data_uid':i['install_data_uid']})
00141        if 'install_data_alias' in i: ii.update({'cm_data_uoa':i['install_data_alias']})
00142        if 'install_data_display_as_alias' in i: ii.update({'cm_display_as_alias':i['install_data_display_as_alias']})
00143        if 'install_repo_uoa' in i: ii['cm_repo_uoa']=i['install_repo_uoa']
00144        if 'local_src_dir' in package_cfg:
00145           ii['cm_array']={}
00146           ii['cm_array']['local_src_dir']=package_cfg['local_src_dir']
00147        r=cm_kernel.access(ii)
00148        if r['cm_return']>0: return r
00149        target_path=r['cm_path']
00150        target_uoa=r['cm_uid']
00151 
00152     # Install script
00153     install_script_without_ext=''
00154     install_script=''
00155     if 'install_script' in package_cfg:
00156        install_script_without_ext=package_cfg['install_script']
00157        install_script=install_script_without_ext+target_os_cfg['script_ext']
00158 
00159     # Copy files
00160     files=[]
00161     if 'cm_files' in package_cfg: files=package_cfg['cm_files']
00162     if install_script!='': files.append(install_script)
00163 
00164     if len(files)>0:
00165        cm_kernel.print_for_con('')
00166        cm_kernel.print_for_con('Copying files ...')
00167        for f in files:
00168            cm_kernel.print_for_con('  '+f)
00169            f1=os.path.join(package_path, f)
00170            f2=os.path.join(target_path, f)
00171            try:
00172              shutil.copyfile(str(f1),str(f2))
00173            except IOError as e:
00174              return {'cm_return':1, 'cm_error':'can\'t copy file '+f+' ('+format(e)+')'}
00175 
00176     if i.get('skip_extract_and_build','')!='yes':
00177 
00178        # Extracting 
00179        if len(files)>0:
00180           cm_kernel.print_for_con('')
00181           cm_kernel.print_for_con('Check if need to extract files ...')
00182           for f in files:
00183               if f!=install_script:
00184                  for ext in target_os_cfg['extract_package']:
00185                      if f.endswith(ext):
00186                         s=target_os_cfg['change_dir']+' '+target_path+' '+target_os_cfg['env_separator']+\
00187                         target_os_cfg['extract_package'][ext]
00188                         s1=s.replace(cm_kernel.convert_str_to_special('cm_file'), f)
00189                         s2=s1.replace(cm_kernel.convert_str_to_special('cm_file_without_one_ext'), os.path.splitext(f)[0])
00190 
00191                         cm_kernel.print_for_con('')
00192                         cm_kernel.print_for_con(s2)
00193                         cm_kernel.print_for_con('')
00194 
00195                         r=os.system(str(s2))
00196                         if r!=0: return {'cm_return':1, 'cm_error':'problem while extracting '+f}
00197 
00198     # Set executable
00199     if install_script!='' and 'set_executable' in target_os_cfg:
00200        cm_kernel.print_for_con('')
00201        cm_kernel.print_for_con('Setting permissions for executable ...')
00202 
00203        p1=os.path.join(target_path, install_script)
00204        r=os.system(target_os_cfg['set_executable']+' '+p1)
00205 
00206     # Build
00207     if build:
00208        cm_kernel.print_for_con('')
00209        cm_kernel.print_for_con('Building ...')
00210     else:
00211        cm_kernel.print_for_con('')
00212        cm_kernel.print_for_con('Installing ...')
00213 
00214     if install_script=='':
00215        return {'cm_return':1, 'cm_error':'install script is not defined'}
00216 
00217     # Checking some vars
00218     if 'build_target_os_uoa' not in i:
00219        return {'cm_return':1, 'cm_error':'"build_target_os_uoa" is not defined'}
00220 
00221     ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code.source'],
00222         'package_data_uoa':i['package_data_uoa'],
00223         'cm_action':'build',
00224         'work_dir_data_uoa':target_uoa,
00225         'run_script':install_script_without_ext,
00226         'install':'yes',
00227         'run_host_os_uoa':i['package_host_os_uoa'],
00228         'build_target_os_uoa':i['build_target_os_uoa'],
00229         'run_set_env2':{}}
00230     if build:
00231        ii['work_dir_module_uoa']=ini['cfg']['cm_modules']['code.source']
00232     else:
00233        ii['work_dir_module_uoa']=ini['cfg']['cm_modules']['code']
00234 
00235     if 'install_repo_uoa' in i: 
00236        ii['work_dir_repo_uoa']=i['install_repo_uoa']
00237        ii['install_repo_uoa']=i['install_repo_uoa']
00238     if 'install_data_uid' in i: 
00239        ii['install_data_uid']=i['install_data_uid']
00240     else: ii['install_data_uid']=target_uoa #FGG: need to check that it's correct, i.e. if we install 
00241                                             #     something like GCC, that we correctly reuse code & code.source
00242     if 'install_data_alias' in i: ii['install_data_uoa']=i['install_data_alias']
00243     if 'install_data_display_as_alias' in i: ii['install_data_display_as_alias']=i['install_data_display_as_alias']
00244     if 'code_deps' in i: ii['code_deps']=i['code_deps']
00245     if len(run_set_env2)>0: ii['run_set_env2']=run_set_env2
00246     if i.get('skip_extract_and_build','')=='yes': ii['run_set_env2']['CM_SKIP_BUILD']='yes'
00247     if 'run_target_processor_uoa' in i: ii['run_target_processor_uoa']=i['run_target_processor_uoa']
00248     if 'add_rem_to_script' in i: ii['add_rem_to_script']=i['add_rem_to_script']
00249     if len(add_to_code_entry)>0: ii['add_to_code_entry']=add_to_code_entry
00250 
00251     rr=cm_kernel.access(ii)
00252 
00253     return rr
00254 
00255 # ============================================================================
00256 def web_install(i):
00257 
00258     """
00259     Install cM package/library
00260 
00261     When searching for already installed code, dependencies are checked
00262      * using classes for packages (to allow reuse of packages)
00263      * by exact code_uoa for code.source (to have exact build setup)
00264 
00265     FGG: the checks are a bit ugly and were done in a rush. 
00266          Should be simplified, cleaned up and unified one day.
00267 
00268     Input:  {
00269               package_data_uoa              - UOA of package to install
00270               (package_repo_uoa)            - repo of the package
00271               package_host_os_uoa           - UOA of host OS (to set up script execution)
00272 
00273               (install_data_uid)            - UID of the code where package will be installed
00274                                               if install_data_uid=='' it will be randomly generated
00275               (install_data_alias)          - use this alias for a generated entry
00276 
00277                 If package should be built:
00278               build_target_os_uoa           - target OS uoa for building
00279               (code_deps)                   - list with code UOA for dependencies [{"index":"uoa"} ...]
00280               (run_target_processor_uoa)    - target processor UOA (not strictly needed - can add some helper parameters before executing code)
00281               (run_set_env2)                - array with environment variables to be set before executable
00282               (add_rem_to_script)           - add rem to install script
00283               (skip_extract_and_build)      - if 'yes', skip copy, extract and build (by setting CM_SKIP_BUILD=yes)
00284             }
00285 
00286     Output: {
00287               cm_return - return code = 0, if successful
00288 
00289               Output from 'code install'
00290             }
00291     """
00292 
00293     # Get web style
00294     if 'cfg' in cm_kernel.ini['web_style']: web=cm_kernel.ini['web_style']['cfg']
00295     else:
00296        return {'cm_return':1, 'cm_error':'web style is not defined'}
00297 
00298     cm_kernel.print_for_con('<span class="cm-title">Install / monitor packages</span><br>')
00299 
00300     # Detecting/restoring data from forms
00301     a1={}
00302 
00303     r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['cm-web'],
00304                         'cm_action':'detect_form_params',
00305                         'cm_array':i, 
00306                         'cm_prefix':'#form1'})
00307     if r['cm_return']>0: return r
00308     cm_form_array1=r['cm_array']
00309     cm_form_commands1=r['cm_commands']
00310 
00311     # Get data description for this action
00312     r=cm_kernel.get_data_description({'cm_module_uoa':ini['cm_module_uoa'], 
00313                                       'cm_which_action':i['cm_action']})
00314     if r['cm_return']>0: return r
00315     cm_data_desc1=r['cm_data_desc']
00316     cm_params_default1=r['cm_params_default']
00317 
00318     # Check default
00319     if len(cm_form_array1)==0:
00320        a1=cm_params_default1
00321     else:
00322        r=cm_kernel.restore_flattened_array({'cm_array':cm_form_array1, 
00323                                             'cm_replace_in_keys':{'^35^':'#', '^64^':'@'}})
00324        if r['cm_return']>0: return r
00325        a1=r['cm_array']
00326 
00327     # If there is data in form, means that refresh
00328     forms_exists='yes'
00329     if len(cm_form_array1)==0: forms_exists='no'
00330 
00331     if 'skip_extract_and_build' in i: a1['skip_extract_and_build']=i['skip_extract_and_build']
00332 
00333     # Check if setup is selected and prune choices *********************************************************************
00334     cm_scen_c=''
00335     cm_scen_p=''
00336 
00337     cm_setup_uoa=a1.get('ctuning_setup_uoa','')
00338     if cm_setup_uoa!='':
00339        # Load setup
00340        ii={}
00341        ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['ctuning.setup']
00342        ii['cm_action']='load'
00343        ii['cm_data_uoa']=cm_setup_uoa
00344        r=cm_kernel.access(ii)
00345        if r['cm_return']>0: return r
00346 
00347        ds=r['cm_data_obj']['cfg']
00348 
00349        # Check class
00350        ctuning_scenario_uoa=ds.get('ctuning_scenario_uoa','')
00351        if ctuning_scenario_uoa!='':
00352           ii={}
00353           ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['ctuning.scenario']
00354           ii['cm_action']='load'
00355           ii['cm_data_uoa']=ctuning_scenario_uoa
00356           r=cm_kernel.access(ii)
00357           if r['cm_return']>0: return r
00358           ds1=r['cm_data_obj']['cfg']
00359 
00360           cm_scen_c=ds1.get('cm_classes_uoa',[])
00361           cm_scen_p=ds1.get('cm_properties',{})
00362 
00363     cm_kernel.print_for_web('<FORM ACTION="" name="add_edit" METHOD="POST" enctype="multipart/form-data" accept-charset="utf-8">' )
00364 
00365     ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['cm-web'],
00366         'cm_action':'visualize_data',
00367         'cm_array':a1,
00368         'cm_data_desc':cm_data_desc1,
00369         'cm_form_commands':cm_form_commands1,
00370         'cm_separator':'#',
00371         'cm_separator_form':'#form1#',
00372         'cm_forms_exists':forms_exists,
00373         'cm_support_raw_edit':'no',
00374         'hide_add_new_object':'yes',
00375         'cm_mode':'add'}
00376     if 'cm_raw_edit' in i: ii['cm_raw_edit']=i['cm_raw_edit']
00377     if 'cm_back_json' in i: ii['cm_back_json']=i['cm_back_json']
00378     r=cm_kernel.access(ii)
00379     if r['cm_return']>0: return r
00380     cm_kernel.print_for_web(r['cm_string'])
00381 
00382     # Pruning vars
00383     cm_t_os_uoa=a1.get('build_target_os_uoa','')
00384     cm_h_os_uoa=a1.get('package_host_os_uoa','')
00385     cm_p_uoa=a1.get('run_target_processor_uoa','')
00386     cm_repo_uoa=a1.get('package_repo_uoa','')
00387 
00388     # Check target OS classes and properties
00389     cm_t_os_c=''
00390     cm_t_os_p=''
00391     if cm_t_os_uoa!='':
00392        ii={}
00393        ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['os']
00394        ii['cm_action']='load'
00395        ii['cm_data_uoa']=cm_t_os_uoa
00396        r=cm_kernel.access(ii)
00397        if r['cm_return']>0: return r
00398 
00399        cm_t_os_uid=r['cm_uid']
00400        cm_t_os_uoa=r['cm_uoa']
00401 
00402        d=r['cm_data_obj']['cfg']
00403 
00404        cm_t_os_c=d.get('cm_classes_uoa',[])
00405        cm_t_os_p=d.get('cm_properties',{})
00406 
00407     cm_h_os_c=''
00408     cm_h_os_p=''
00409     cm_h_os_cfg={}
00410     if cm_h_os_uoa!='':
00411        ii={}
00412        ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['os']
00413        ii['cm_action']='load'
00414        ii['cm_data_uoa']=cm_h_os_uoa
00415        r=cm_kernel.access(ii)
00416        if r['cm_return']>0: return r
00417 
00418        cm_h_os_uid=r['cm_uid']
00419        cm_h_os_uoa=r['cm_uoa']
00420        cm_h_os_cfg=r['cm_data_obj']['cfg']
00421 
00422        d=cm_h_os_cfg
00423        cm_h_os_c=d.get('cm_classes_uoa',[])
00424        cm_h_os_p=d.get('cm_properties',{})
00425 
00426     cm_p_c=''
00427     cm_p_p=''
00428     if cm_p_uoa!='':
00429        ii={}
00430        ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['processor']
00431        ii['cm_action']='load'
00432        ii['cm_data_uoa']=cm_p_uoa
00433        r=cm_kernel.access(ii)
00434        if r['cm_return']>0: return r
00435 
00436        cm_p_uid=r['cm_uid']
00437        cm_p_uoa=r['cm_uoa']
00438 
00439        d=r['cm_data_obj']['cfg']
00440 
00441        cm_p_c=d.get('cm_classes_uoa',[])
00442        cm_p_p=d.get('cm_properties',{})
00443 
00444 
00445     # Get list of packages and libraries ***************************************************************************************
00446     r={}
00447     r['cm_mixed']=[]
00448 
00449     r1=cm_kernel.access({'cm_run_module_uoa':ini['cm_module_uid'], 'cm_action':'list'})
00450     if r1['cm_return']>0: cm_kernel.print_for_web('</select><B>cM error:</b> '+r['cm_error']+'<br>')
00451     for q in r1['cm_mixed']: r['cm_mixed'].append(q)
00452 
00453     for j in ini['cfg']['source_classes_to_install']:
00454         r1=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['code.source'], 'cm_action':'list', \
00455                              'cm_classes_uoa':[j]})
00456         if r1['cm_return']>0: cm_kernel.print_for_web('</select><B>cM error:</b> '+r['cm_error']+'<br>')
00457         for q in r1['cm_mixed']: 
00458             if q not in r['cm_mixed']: r['cm_mixed'].append(q)
00459 
00460     if len(r['cm_mixed'])>0:
00461        pg1=[]
00462 
00463        # List
00464        for xx in sorted(r['cm_mixed'], key=lambda k: tuple(s.lower() if isinstance(s,basestring) else s for s in k['cm_display_html'])):
00465            x=xx['cm_uoa'];  xu=xx['cm_uid'];  xa=xx['cm_alias'];  xd=xx['cm_display_html']
00466            # Load data
00467            ii={}
00468            ii['cm_run_module_uoa']=xx['cm_module_uid']
00469            ii['cm_action']='load'
00470            ii['cm_data_uoa']=xu
00471            r=cm_kernel.access(ii)
00472            if r['cm_return']==0:
00473               d=r['cm_data_obj']['cfg']
00474 
00475               add=True
00476 
00477               # Check classes
00478               dc=d.get('cm_classes_uoa',{})
00479               if len(dc)>0: xx['cm_classes_uoa']=dc
00480 
00481               # Check overlaping properties from target OS
00482               dp=d.get('cm_properties',{})
00483               if len(dp)>0:
00484                  xx['cm_properties']=dp
00485 
00486                  for q in cm_t_os_p:
00487                      if q in dp and cm_t_os_p[q]!=dp[q]:
00488                         add=False
00489                         break
00490 
00491               # Check dependencies
00492               if add:
00493                  dd=d.get('cm_dependencies', {})
00494                  if len(dd)>0: 
00495                     xx['cm_dependencies']=dd
00496 
00497                     if 'scenario' in dd and len(dd['scenario'])>0:
00498                        if len(cm_scen_c)>0:
00499                           # Class
00500                           found=False
00501                           for q in cm_scen_c:
00502                               if q in dd['scenario']: found=True; break
00503                           if not found: add=False
00504 
00505                     if 'host_os' in dd and len(dd['host_os'])>0:
00506                        if len(cm_h_os_c)>0:
00507                           # Class
00508                           found=False
00509                           for q in cm_h_os_c:
00510                               if q in dd['host_os']: found=True; break
00511                           if not found: add=False
00512 
00513                     if 'target_os' in dd and len(dd['target_os'])>0:
00514                        if len(cm_t_os_c)>0:
00515                           # Class
00516                           found=False
00517                           for q in cm_t_os_c:
00518                               if q in dd['target_os']: found=True; break
00519                           if not found: add=False
00520 
00521                     if 'target_processor' in dd and len(dd['target_processor'])>0:
00522                        if len(cm_p_c)>0:
00523                           # Class
00524                           found=False
00525                           for q in cm_p_c:
00526                               if q in dd['target_processor']: found=True; break
00527 
00528                           if not found: add=False
00529 
00530               if add: pg1.append(xx)
00531 
00532        # Sort by deps *******************************************************************************************
00533        deps=[]
00534        pg=[]
00535        finish=False
00536        prefinish=False
00537 
00538        while not finish:
00539           processed=False
00540           for o in range(0, len(pg1)):
00541               x=pg1[o]
00542               if x!={}:
00543                  to_add=False
00544                  if 'cm_dependencies' not in x or 'classes' not in x['cm_dependencies']: to_add=True
00545                  else:
00546                     if 'classes' in x['cm_dependencies']:
00547                        found_all=True
00548                        for qq in x['cm_dependencies']['classes']:
00549                            if qq not in deps:
00550                               found_all=False; break
00551                        if found_all: to_add=True
00552 
00553                        # Check remaining deps
00554                        if not prefinish:
00555                           if to_add:
00556                              for oo1 in range(0, len(pg1)):
00557                                  if oo1!=o:
00558                                     oo=pg1[oo1]
00559                                     if oo!={} and 'cm_classes_uoa' in oo:
00560                                        deps1=oo['cm_classes_uoa']
00561                                        failed=False
00562                                        for qq in x['cm_dependencies']['classes']:
00563                                            if qq in deps1: 
00564                                               failed=True; break
00565                                        if failed: to_add=False
00566 
00567                  if to_add:
00568                     if 'cm_classes_uoa' in x:
00569                        for q in x['cm_classes_uoa']: 
00570                            if q not in deps: deps.append(q)
00571                     pg.append(x)
00572                     pg1[o]={}
00573                     processed=True 
00574 
00575           if not processed: 
00576              if prefinish: finish=True
00577              else: prefinish=True
00578           else:
00579              pg.append({})
00580 
00581        # Cache all code to check status
00582        codes={}
00583        codes_repo={}
00584        if cm_t_os_uoa!='' and cm_p_uoa!='':
00585           ii={}
00586           ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['code']
00587           ii['cm_action']='list'
00588           r=cm_kernel.access(ii)
00589           if r['cm_return']==0:
00590              for q in r['cm_mixed']:
00591                  # Load data
00592                  ii={}
00593                  ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['code']
00594                  ii['cm_action']='load'
00595                  ii['cm_data_uoa']=q['cm_uid']
00596                  rx=cm_kernel.access(ii)
00597                  if rx['cm_return']==0:
00598                     codes[rx['cm_uid']]=rx['cm_data_obj']['cfg']
00599                     codes_repo[rx['cm_uid']]=rx['cm_repo_uid']
00600 
00601        # Load all classes
00602        classes={}
00603        classes_install={}
00604        classes_install_static={}
00605 
00606        # View  *************************************************************************************************
00607        line=True; 
00608        x1=''
00609        if 'table_bgcolor_line1' in web: x1=' bgcolor="'+web['table_bgcolor_line1']+'" ' 
00610        x2=''
00611        if 'table_bgcolor_line2' in web: x2=' bgcolor="'+web['table_bgcolor_line2']+'" '
00612        x3=''
00613        if 'table_bgcolor_line3' in web: x3=' bgcolor="'+web['table_bgcolor_line3']+'" ' 
00614        x4=''
00615        if 'table_bgcolor_line4' in web: x4=' bgcolor="'+web['table_bgcolor_line4']+'" '
00616 
00617        all_installed_uids=[]
00618 
00619        cm_kernel.print_for_web(web['table_init'])
00620 
00621        cm_kernel.print_for_con('<tr style="background-color:#7F7FFF">')
00622        cm_kernel.print_for_con('<td><b>Package name:</b></td>')
00623        cm_kernel.print_for_con('<td><b>Classes:</b></td>')
00624        cm_kernel.print_for_con('<td><b>Dependencies:</b></td>')
00625        cm_kernel.print_for_con('<td><b>Install/code UID:</b></td>')
00626        cm_kernel.print_for_con('<td><b>Install Status:</b></td>')
00627        cm_kernel.print_for_con('<td><b>Install:</b></td>')
00628        cm_kernel.print_for_con('</tr>')
00629 
00630        for xx in pg:
00631            cm_kernel.print_for_con('<tr>')
00632 
00633            if xx!={}:
00634               x=xx['cm_uoa'];  xu=xx['cm_uid'];  xa=xx['cm_alias'];  xd=xx['cm_display_html'];  xda=xx['cm_display_as_alias']
00635 
00636               # If compiler is selected, remove itself from the list of packages!
00637               # otherwise had problem with LLVM depending on OpenME
00638               ign=False
00639               if xu==a1['compiler_code_uoa']: ign=True
00640 
00641               if True:
00642                  cc=xx.get('cm_classes_uoa',[])
00643                  cd=xx.get('cm_dependencies',{}).get('classes',[])
00644 
00645                  cx=[]
00646                  for c in cc: cx.append(c)
00647                  for c in cd: cx.append(c)
00648                  for c in cx:
00649                      if c not in classes: 
00650                         #Load class to get name
00651                         ii={}
00652                         ii['cm_run_module_uoa']=ini['cfg']['cm_modules']['class']
00653                         ii['cm_action']='load'
00654                         ii['cm_data_uoa']=c
00655                         rx=cm_kernel.access(ii)
00656                         if rx['cm_return']>0: return rx
00657                         else: classes[c]=rx
00658                  if line: 
00659                     line=False; 
00660                     if xx['cm_module_uid']==ini['cm_module_uid']: x=x1
00661                     else: x=x3
00662                  else: 
00663                     line=True
00664                     if xx['cm_module_uid']==ini['cm_module_uid']: x=x2
00665                     else: x=x4
00666                  cm_kernel.print_for_con('<tr'+x+'>')
00667 
00668 #                 sou=web['http_prefix']+'cm_menu='+web['cm_menu_browse']+'&cm_subaction_view&browse_cid='+xx['cm_module_uid']+':'+xu
00669                  sou=web['http_prefix']+'view_cid='+xx['cm_module_uid']+':'+xu
00670                  y='<a href="'+sou+'" target="_blank">'+xd+'</a>'
00671 
00672                  cm_kernel.print_for_web('<td>'+y+'</td>')
00673                  cm_kernel.print_for_web('<td><small>')
00674                  first=True; y=''
00675                  for c in cc:
00676                      if first: first=False
00677                      else: y+='<br>'
00678                      y+=classes[c]['cm_display_html']
00679                  cm_kernel.print_for_con(y)
00680                  cm_kernel.print_for_web('</small></td>')
00681 
00682 
00683                  cm_kernel.print_for_web('<td><small>')
00684 
00685                  # If not self-reference, print dependences, otherwise show self-reference
00686                  if ign: 
00687                     cm_kernel.print_for_web('<B><I>Self-reference, dependencies will not be shown</I></B>')
00688                  else:
00689                     failed_deps=False
00690                     code_deps=[]
00691                     code_deps1=[]
00692                     code_deps2=[]
00693                     compiler_name=''
00694 
00695                     if len(cd)>0:
00696                        y='<table border="0">'
00697                        iz=0
00698                        for c in cd:
00699                            iz+=1
00700                            z1='';z2=''
00701 
00702                            if c not in classes_install and c: 
00703                               z1='<strike>';z2='</strike>'
00704                               failed_deps=True
00705                            y+='<tr><td align="left">'+z1+str(iz)+')&nbsp;'+classes[c]['cm_display_as_alias']+z2+'</td>'
00706 
00707                            if c in classes_install: 
00708                               yy=''
00709                               name='package_web_install_'+xu+'_'+c
00710                               value=i.get(name,'')
00711                               jq=''
00712 
00713                               yz={}
00714                               if c in classes_install_static: yz=classes_install_static[c]
00715                               elif c in classes_install: yz=classes_install[c]
00716 
00717                               if c==ini['cfg']['cm_class_compiler']:
00718 #                                 found_compiler=False
00719 #                                 for j in classes_install[c]:
00720 #                                     if a1['compiler_code_uoa']==j['code_uid']:
00721 #                                        jq={'code_uid':a1['compiler_code_uoa']}
00722 #                                        compiler_name=j['name']
00723 #                                        yy='<i>'+compiler_name+'</i>'
00724 #                                        found_compiler=True
00725 #                                        break
00726 #                                 if not found_compiler: failed_deps=True
00727 
00728                                   # FGG removed check for deps here otherwise problem with LLVM 3.2 with OpenME
00729                                   jq={'code_uid':a1['compiler_code_uoa']}
00730 
00731                                   compiler_name=a1['compiler_code_uoa']
00732 
00733                                   # Load compiler code to get package_uoa
00734                                   rx=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['code'],
00735                                                        'cm_action':'load',
00736                                                        'cm_data_uoa':a1['compiler_code_uoa']})
00737                                   if rx['cm_return']==0:
00738                                      compiler_package_uoa=rx['cm_data_obj']['cfg'].get('state_input',{}).get('package_data_uoa','')
00739 
00740                                      if compiler_package_uoa!='':
00741                                         # Load package
00742                                         rx=cm_kernel.access({'cm_run_module_uoa':ini['cm_module_uid'],
00743                                                              'cm_action':'load',
00744                                                              'cm_data_uoa':compiler_package_uoa})
00745                                         if rx['cm_return']==0:
00746                                            compiler_name=rx['cm_data_obj']['cfg'].get('cm_display_as_alias','')
00747                                            if compiler_name=='': compiler_name=rx['cm_uoa']
00748 
00749                                   yy='<i>'+compiler_name+'</i>'
00750                               else:
00751                                  yy='<select name="'+name+'" width="300" style="width: 300px" onchange="document.add_edit.submit();">'
00752 
00753                                  for j in yz:
00754                                      yyy=''
00755                                      if value==j['code_uid']: 
00756                                         jq=j
00757                                         yyy=' SELECTED '
00758                                      if yy!='': yy+=','
00759 
00760                                      yy+='<option value="'+j['code_uid']+'"'+yyy+'>'+j['name']+'</option>'
00761                                  yy+='</select>'
00762                               y+='<td>'+yy+'</td></tr>'
00763 
00764                               if jq=='' and len(yz)>0: jq=yz[0]
00765 
00766                               if jq!='':
00767                                  code_deps_var=classes[c]['cm_data_obj']['cfg'].get('code_deps_var','')
00768                                  if code_deps_var!='': 
00769                                     code_deps.append({code_deps_var:jq['code_uid']})
00770                                     code_deps1.append({c:jq['code_uid']})
00771                                     if c!=ini['cfg']['cm_class_compiler']:
00772                                        code_deps2.append({c:jq['code_uid']})
00773                        y+='</table>'
00774                        cm_kernel.print_for_con(y)
00775 
00776                     cm_kernel.print_for_web('</small></td>')
00777 
00778                  # Check status and deps ************************************************************************
00779                  found=False
00780                  y=''
00781                  z=''
00782                  if not failed_deps and cm_t_os_uoa!='' and cm_p_uoa!='':
00783                     qr=''
00784                     for q in codes:
00785                         qq=codes[q]
00786 
00787                         qqd=qq.get('cm_source_data_uoa','')
00788                         qqm=qq.get('cm_source_module_uoa','')
00789 
00790                         success=False
00791                         if qq.get('build_finished_successfully','')=='yes': success=True
00792 
00793                         # Check package/source code
00794                         if (qqd!=xu or qqm!=xx['cm_module_uid']):
00795                            continue
00796 
00797                         add=True
00798                         if xx['cm_module_uid']==ini['cm_module_uid']:
00799 
00800                            si=qq.get('state_input',{})
00801                            qqp=si.get('run_target_processor_uoa','')
00802                            qqbtos=si.get('build_target_os_uoa','')
00803                            qqwd=si.get('package_data_uoa','')
00804                            if qqwd=='': qqwd=si.get('work_dir_data_uoa','')
00805 
00806                            # for packages, we use comparison by class (less restrictive) to reuse packages for different setups
00807                            dd=qq
00808                            if 'host_os' in dd:
00809                               # Prune by target OS
00810                               if len(cm_h_os_c)>0:
00811                                  # Class
00812                                  found=False
00813                                  for q in cm_h_os_c:
00814                                      if q in dd['host_os']: found=True; break
00815                                  if not found: add=False
00816                            if not add: continue
00817 
00818                            if 'target_os' in dd:
00819                               # Prune by target OS
00820                               if len(cm_t_os_c)>0:
00821                                  # Class
00822                                  found=False
00823                                  for q in cm_t_os_c:
00824                                      if q in dd['target_os']: found=True; break
00825                                  if not found: add=False
00826                            if not add: continue
00827 
00828                            if 'target_processor' in dd:
00829                               # Prune by target OS
00830                               if len(cm_p_c)>0:
00831                                  # Class
00832                                  found=False
00833                                  for q in cm_p_c:
00834                                      if q in dd['target_processor']: found=True; break
00835                                  if not found: add=False
00836                            if not add: continue
00837                         else:
00838                            # Check deps **************************************************************************************
00839                            # for libraries, we use exact comparison by UID for a given setup
00840                            add=False
00841 
00842                            rdep=qq.get('cm_dependencies_real',{})
00843 
00844                            if rdep.get('host_os','')!='' and rdep['host_os']!=cm_h_os_uid: continue
00845                            if rdep.get('target_os','')!='' and rdep['target_os']!=cm_t_os_uid: continue
00846                            if rdep.get('target_processor','')!='' and rdep['target_processor']!=cm_p_uid: continue
00847 
00848                            add=True
00849                            j=rdep.get('classes',{})
00850                            for t in j:
00851                                t1=t.keys()[0]
00852                                t2=t[t1]
00853                                found=False
00854                                for e in code_deps1:
00855                                    e1=e.keys()[0]
00856                                    e2=e[e1]
00857                                    if e1==t1 and e2==t2: found=True; break
00858                                if not found:
00859                                   add=False
00860                                   break
00861 
00862                            if not add: continue
00863 
00864                            if rdep.get('compilation_type','')!='' and a1.get('compilation_type','')!=rdep['compilation_type']:
00865                               add=False
00866                               found=False
00867                               continue
00868 
00869                            if rdep.get('compilation_type','')=='static':
00870                               qxd=qq.get('cm_display_as_alias','')
00871                               if qxd=='': qxd=xd
00872                               for j in cc:
00873                                   if j not in classes_install_static: 
00874                                         classes_install_static[j]=[{'code_uid':q, 'name':qxd}]
00875                                   else:
00876                                      if q not in classes_install_static[j]: 
00877                                         classes_install_static[j].append({'code_uid':q, 'name':qxd})
00878 
00879                         if add: qr=q
00880 
00881                     if qr!='':
00882                        sou=web['http_prefix']+'cm_menu='+web['cm_menu_browse']+'&cm_subaction_view&browse_cid='+ini['cfg']['cm_modules']['code']+':'+qr
00883                        y='<a href="'+sou+'" target="_blank">'+qr+'</a>'
00884                        qq=codes[qr]
00885                        all_installed_uids.append(qr)
00886 
00887                        success=False
00888                        if qq.get('build_finished_successfully','')=='yes': success=True
00889 
00890                        if success:
00891                           z='<span style="color:#00009F"><b>Success</b></span>'
00892                           qxd=qq.get('cm_display_as_alias','')
00893                           if qxd=='': qxd=xd
00894                           for j in cc:
00895                               if j not in classes_install: 
00896                                  classes_install[j]=[{'code_uid':qr, 'name':qxd}]
00897                               else:
00898                                  if qr not in classes_install[j]: classes_install[j].append({'code_uid':qr, 'name':qxd})
00899 
00900                        else: 
00901                           z='<span style="color:#9F0000"><b>Not finished<BR>(either in progress or error)</b></span>'
00902 
00903                        found=True
00904 
00905                  cm_kernel.print_for_web('<td><small>'+y+'</small></td>')
00906                  cm_kernel.print_for_web('<td align="center"><small>'+z+'</small></td>')
00907 
00908                  z=''
00909                  y=''
00910                  if not failed_deps and cm_t_os_uoa!='' and cm_p_uoa!='' and not ign:
00911                     # Check if enough params for an install button
00912                     cm_json={}
00913                     rem=[]
00914                     rm=cm_h_os_cfg.get('rem','')
00915 
00916                     # Load package or source-code to check default build script
00917                     ii={}
00918                     ii['cm_run_module_uoa']=xx['cm_module_uid']
00919                     ii['cm_action']='load'
00920                     ii['cm_data_uoa']=xx['cm_uid']
00921                     rx=cm_kernel.access(ii)
00922                     if rx['cm_return']>0: return rx
00923                     d1=rx['cm_data_obj']['cfg']
00924 
00925                     if xx['cm_module_uid']==ini['cm_module_uid']:
00926                        rem.append(rm+' package: '+str(xd))
00927                        cm_json['install_data_display_as_alias']=str(xd)
00928                        y1='Install'
00929                        if not failed_deps and cm_t_os_uoa!='' and cm_h_os_uoa!='' and cm_p_uoa!='':
00930                           z=web['http_prefix']+'cm_web_module_uoa=package&cm_web_action=install&package_data_uoa='+xu+\
00931                             '&package_host_os_uoa='+cm_h_os_uoa+'&build_target_os_uoa='+cm_t_os_uoa+\
00932                             '&run_target_processor_uoa='+cm_p_uoa+'&cm_detach_console=yes'
00933                           if found:
00934                             z+='&install_data_uid='+qr+'&install_repo_uoa='+codes_repo[qr]
00935                             y1='Re-install'
00936                           elif cm_repo_uoa!='': 
00937                             z+='&install_repo_uoa='+cm_repo_uoa
00938                     else:
00939                        rem.append(rm+' package: '+str(xd)+' - '+compiler_name+' - '+a1.get('compilation_type',''))
00940                        cm_json['install_data_display_as_alias']=str(xd)+' - '+compiler_name+' - '+a1.get('compilation_type','')
00941                        y1='Build'
00942                        if not failed_deps and cm_t_os_uoa!='' and cm_h_os_uoa!='' and cm_p_uoa!='':
00943                           z=web['http_prefix']+'cm_menu=scenarios&cm_submenu=ctuning_code_source_build'
00944 
00945                           cm_json['#form1##run_host_os_uoa']=cm_h_os_uoa
00946                           cm_json['#form1##build_target_os_uoa']=cm_t_os_uoa
00947                           cm_json['#form1##run_target_processor_uoa']=cm_p_uoa
00948                           cm_json['#form1##work_dir_data_uoa']=xu
00949                           cm_json['#form1##work_dir_repo_uoa']=''
00950                           cm_json['#form1##install']='yes'
00951                           if 'ctuning_setup_uoa' in a1: cm_json['#form1##ctuning_setup_uoa']=a1['ctuning_setup_uoa']
00952                           if 'package_repo_uoa' in a1: cm_json['#form1##install_repo_uoa']=a1['package_repo_uoa']
00953                           cross_build_static_lib=False
00954                           if 'compiler_code_uoa' in a1: 
00955                              cm_json['#form1##compiler_code_uoa']=a1['compiler_code_uoa']
00956 
00957                              # Load compiler code to check if cross-compile
00958                              rx=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['code'],
00959                                                   'cm_action':'load',
00960                                                   'cm_data_uoa':a1['compiler_code_uoa']})
00961                              if rx['cm_return']==0: 
00962                                 drx=rx['cm_data_obj']['cfg']
00963                                 if drx.get('build_params',{}).get('cross_build_static_lib','')=='yes': 
00964                                    cross_build_static_lib=True
00965 
00966                           if 'compilation_type' in a1: cm_json['#form1##compilation_type']=a1['compilation_type']
00967 
00968                           # Always force dependencies even if empty
00969                           cm_json['#form1##cm_dependencies']=code_deps2
00970 
00971                           if found:
00972                             y1='Re-build'
00973                             cm_json['#form1##install_data_uid']=qr
00974 
00975                           if 'build_scripts_uoa' in d1:
00976                              cm_json['#form1##build_run_script_uoa']=d1['build_scripts_uoa'][0]
00977 
00978                           if cross_build_static_lib and 'build_scripts_names' in d1:
00979                              for j in d1['build_scripts_names']:
00980                                  for jj in d1['build_scripts_names'][j]:
00981                                      if 'cross_build_static_lib' in jj:
00982                                         cm_json['#form1##build_run_script']=jj
00983                                         break
00984 
00985                     cm_json['add_rem_to_script']=rem
00986 
00987                     cm_json['code_deps']=code_deps
00988 
00989                     if 'keep_all_files' in a1 and a1['keep_all_files']!='': cm_json['keep_all_files']=a1['keep_all_files']
00990 
00991                     if 'skip_extract_and_build' in a1: cm_json['skip_extract_and_build']=a1['skip_extract_and_build']
00992                     if 'number_of_parallel_jobs_for_build' in a1: 
00993                        cm_json['run_set_env2']={}
00994                        cm_json['run_set_env2']['CM_PARALLEL_JOB_NUMBER']=a1['number_of_parallel_jobs_for_build']
00995 
00996                     package_info={}
00997                     if 'cm_classes_uoa' in xx: package_info['cm_classes_uoa']=xx['cm_classes_uoa']
00998                     if 'cm_properties' in xx: package_info['cm_properties']=xx['cm_properties']
00999                     if 'cm_dependencies' in xx: package_info['cm_dependencies']=xx['cm_dependencies']
01000 
01001                     package_info['cm_source_data_uoa']=xu
01002                     package_info['cm_source_module_uoa']=xx['cm_module_uid']
01003 
01004                     # Prepare real dependencies
01005 
01006                     package_info['cm_dependencies_real']={}
01007 
01008                     package_info['cm_dependencies_real']['classes']=code_deps1
01009 
01010                     dd=d1.get('cm_dependencies',{})
01011                     if 'host_os' in dd:          package_info['cm_dependencies_real']['host_os']=cm_h_os_uid
01012                     if 'target_os' in dd:        package_info['cm_dependencies_real']['target_os']=cm_t_os_uid
01013                     if 'target_processor' in dd: package_info['cm_dependencies_real']['target_processor']=cm_p_uid
01014 
01015                     # Check if package requires compilation, and then record compiler and compilation type
01016                     if 'classes' in dd and ini['cfg']['cm_classes']['compiler'] in dd['classes']:
01017                        if 'compiler_code_uoa' in a1:
01018                           package_info['cm_dependencies_real']['compiler_code_uoa']=a1['compiler_code_uoa']
01019                        if 'compilation_type' in a1:
01020                           package_info['cm_dependencies_real']['compilation_type']=a1['compilation_type']
01021 
01022                     cm_json['add_to_code_entry']=package_info
01023 
01024                     rx=cm_kernel.convert_cm_array_to_uri({'cm_array':cm_json})
01025                     if rx['cm_return']>0: return rx
01026 
01027                     z+='&cm_json='+rx['cm_string']
01028 
01029                     y='<a href="'+z+'" target="_blank">'+y1+'</a>'
01030 
01031                  cm_kernel.print_for_web('<td align="center"><small>'+y+'</small></td>')
01032 
01033            else:
01034               cm_kernel.print_for_con('<td colspan=6><HR class="cm-hr"></td>')
01035 
01036            cm_kernel.print_for_con('</tr>')
01037 
01038        cm_kernel.print_for_con('</table>')
01039 
01040        cm_kernel.print_for_con('<small><B>All installed UIDs:</B><BR><i>')
01041        for q in all_installed_uids:
01042            cm_kernel.print_for_con(' '+q)
01043        cm_kernel.print_for_con('</i></small><BR>')
01044 
01045 
01046     cm_kernel.print_for_con('<input type="submit" class="cm-button" value="Refresh">')
01047 
01048     cm_kernel.print_for_con('</FORM>')
01049 
01050     return {'cm_return':0}
01051 
01052 # ============================================================================
01053 def installed(i):
01054 
01055     """
01056     List installed packages
01057 
01058     Input:  {
01059               (code_repo_uoa)             - repo UOA to list code
01060               (prune_by_class_uoa)        - prune by 1 class UOA
01061               (prune_by_name)             - prune by name (checks for inclusion; case insensitive)
01062               (fuzzy_match)               - if 'yes', check inclusion of 'prune_by_name' in name, otherwise exact match
01063               (prune_by_name_uoa)         - prune by name UOA
01064               (prune_by_type)             - prune by "library_or_plugin" or "package"
01065               (prune_by_host_os)          - prune by host os
01066               (prune_by_target_os)        - prune by target os
01067               (prune_by_target_processor) - prune by target processor
01068               (prune_by_compiler)         - if library or plugin, prune by compiler
01069               (prune_by_os_from_kernel)   - if 'yes', take OS from kernel
01070               (only_uoa)                  - return only UOA
01071             }
01072 
01073     Output: {
01074               cm_return - return code = 0, if successful
01075               final     - list with code entries in cM 'list' format
01076             }
01077     """
01078 
01079     # Checking some pruning parameters
01080     pbcu=i.get('prune_by_class_uoa','')
01081     pbn=i.get('prune_by_name','').lower()
01082     fm=i.get('fuzzy_match','')
01083     pbnu=i.get('prune_by_name_uoa','')
01084     pbt=i.get('prune_by_type','').lower()
01085     pbho=i.get('prune_by_host_os','').lower()
01086     pbto=i.get('prune_by_target_os','').lower()
01087     pbtp=i.get('prune_by_target_processor','').lower()
01088     pbc=i.get('prune_by_compiler','').lower()
01089 
01090     ou=i.get('only_uoa','')
01091 
01092     pik=i.get('prune_by_os_from_kernel','')
01093     if pik!='':
01094        dos=cm_kernel.ini['dcfg'].get('cm_default_os_uoa','')
01095        r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 'cm_action':'load', 'cm_data_uoa':dos})
01096        if r['cm_return']>0: return r
01097        if r['cm_alias']!='': dos=r['cm_alias']
01098 
01099        pbho=dos
01100        pbto=dos
01101 
01102     ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code'],
01103         'cm_action':'list',
01104        }
01105     if i.get('code_repo_uoa','')!='': ii['cm_repo_uoa']=i['code_repo_uoa']
01106     r=cm_kernel.access(ii)
01107     if r['cm_return']>0: return r
01108 
01109     m=r['cm_mixed']
01110     ms=sorted(m, key=lambda k: k['cm_display_as_alias'])
01111 
01112     final=[]
01113     for q in ms:
01114         d=q['cm_data_obj_cfg']
01115         bfs=d.get('build_finished_successfully','')
01116         cl=d.get('cm_classes_uoa',[])
01117 
01118         show=True
01119         if pbcu!='' and pbcu not in cl:
01120            show=False
01121 
01122         if show:
01123            if bfs=='' or bfs=='yes':
01124               si=d.get('state_input',{})
01125               pack=si.get('package_data_uoa','')
01126               source=si.get('work_dir_data_uoa','')
01127 
01128               show=True
01129               if pbnu!='' and not (pbnu==pack or pbnu==source):
01130                  show=False
01131 
01132               if show:
01133                  if pack!='' or source!='':
01134                     xcompiler=''
01135                     if pack=='':
01136                        # If library/plugin **************
01137                        lib=True
01138                        t='library/plugin'
01139                        t1='library_or_plugin'
01140 
01141                        r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['code.source'], 'cm_action':'load', 'cm_data_uoa':source})
01142                        if r['cm_return']==0:
01143                           name=r.get('cm_display_as_alias',source) 
01144 
01145                           cc_uoa=d.get('cm_dependencies_real',{}).get('compiler_code_uoa','')
01146                           r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['code'], 'cm_action':'load', 'cm_data_uoa':cc_uoa})
01147                           if r['cm_return']==0: 
01148                              cp_uoa=r['cm_data_obj']['cfg'].get('state_input',{}).get('package_data_uoa','')
01149 
01150                              if cp_uoa!='':
01151                                 r=cm_kernel.access({'cm_run_module_uoa':ini['cm_module_uid'], 'cm_action':'load', 'cm_data_uoa':cp_uoa})
01152                                 if r['cm_return']==0: 
01153                                    xcompiler='"'+r.get('cm_display_as_alias',cp_uoa)+'"'
01154                     else:
01155                        # If package **************
01156                        lib=False
01157                        t='package'
01158                        t1=t
01159                        r=cm_kernel.access({'cm_run_module_uoa':ini['cm_module_uid'], 'cm_action':'load', 'cm_data_uoa':pack})
01160                        if r['cm_return']==0: 
01161                           name=r.get('cm_display_as_alias',pack) 
01162 
01163                     show=True
01164 
01165                     if pbt!='' and pbt!=t1:
01166                        show=False
01167                     elif pbn!='':
01168                          if fm=='yes' and not pbn in name.lower(): #re.match(pbn,name.lower())):
01169                              show=False
01170                          elif pbn!='' and fm!='yes' and pbn!=name.lower(): #re.match(pbn,name.lower())):
01171                              show=False
01172                     elif t=='library/plugin' and pbc!='':
01173                          if fm=='yes' and not pbc in xcompiler.lower():
01174                             show=False
01175                          elif fm!='yes' and pbc!=xcompiler.lower():
01176                             show=False
01177 
01178                     if show:
01179                        st='%14s' % t
01180 
01181                        cm_uoa=q['cm_uoa']
01182                        cm_uid=q['cm_uid']
01183                        daa=q.get('cm_display_as_alias','')
01184 
01185                        # Get host OS
01186                        ho=si.get('run_host_os_uoa','')
01187                        xho=ho
01188                        xho1=ho
01189                        r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 'cm_action':'load', 'cm_data_uoa':ho})
01190                        if r['cm_return']>0: return r
01191                        if r['cm_alias']!='': 
01192                           xho=r['cm_alias']
01193                           xho1=r['cm_uid']
01194 
01195                        # Get target OS
01196                        to=si.get('build_target_os_uoa','')
01197                        xto=to
01198                        xto1=to
01199                        r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['os'], 'cm_action':'load', 'cm_data_uoa':to})
01200                        if r['cm_return']>0: return r
01201                        if r['cm_alias']!='': 
01202                           xto=r['cm_alias']
01203                           xto1=r['cm_uid']
01204 
01205                        # Get target processor
01206                        tp=si.get('run_target_processor_uoa','')
01207                        xtp=tp
01208                        xtp1=tp
01209                        r=cm_kernel.access({'cm_run_module_uoa':ini['cfg']['cm_modules']['processor'], 'cm_action':'load', 'cm_data_uoa':tp})
01210                        if r['cm_return']>0: return r
01211                        if r['cm_alias']!='': 
01212                           xtp=r['cm_alias']
01213                           xtp1=r['cm_uid']
01214 
01215                        sto='%25s' % xto
01216                        stp='%16s' % xtp
01217                        sho='%25s' % xho
01218 
01219                        show=True
01220 
01221                        if pbho!='' and pbho!=xho and pbho!=xho1:
01222                           show=False
01223                        elif pbto!='' and pbto!=xto and pbto!=xto1:
01224                           show=False
01225                        elif pbtp!='' and pbtp!=xtp and pbtp!=xtp1:
01226                           show=False
01227 
01228                        if show:
01229                           final.append(q)
01230                           if i.get('cm_console','')=='txt':
01231                              if ou=='':
01232                                 cm_kernel.print_for_con(cm_uoa+' '+st+' '+sho+' '+sto+' '+stp+'  "'+name+'"'+'   '+xcompiler)
01233                                 cm_kernel.print_for_con('')
01234                              else:
01235                                 cm_kernel.print_for_con(cm_uoa)
01236 
01237     return {'cm_return':0, 'final':final}

Generated on Wed May 28 02:49:02 2014 for Collective Mind Framework by DoxyGen 1.6.1
Concept, design and coordination: Grigori Fursin (C) 1993-2013