module.py
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 ini={}
00012 cm_kernel=None
00013
00014
00015 import os
00016 import sys
00017
00018
00019 def init(i):
00020 return {'cm_return':0}
00021
00022
00023 def detect_host_family(i):
00024
00025 """
00026 Detect main OS version using python
00027
00028 Input: {
00029 (cm_repo_uoa) - which repo to use to get info (to support remote ones)
00030 }
00031
00032 Output: {
00033 cm_return - return code = 0, if successful
00034 family - OS family
00035 cm_os_uoa_list - list of OSes from the same family (through search)
00036 cm_host_uoa - most close OS UOA from known
00037 cm_host_alias - alias for cm_host_uoa
00038 }
00039 """
00040
00041
00042
00043 family=''
00044
00045
00046 n=sys.platform
00047
00048 if n.startswith('linux'): family='linux'
00049 elif n.startswith('win'): family='windows'
00050 elif n.startswith('cygwin'): family='windows'
00051 elif n.startswith('darwin'): family='linux'
00052
00053
00054 ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['cm-core'],
00055 'cm_action':'search',
00056 'key_0':'family',
00057 'value_0':family,
00058 'module_selection':[ini['cm_module_uid']],
00059 'use_internal_search':'yes'
00060 }
00061 if 'cm_repo_uoa' in i and i['cm_repo_uoa']!='': ii['repo_selection']=[i['cm_repo_uoa']]
00062 r=cm_kernel.access(ii)
00063 if r['cm_return']>0: return r
00064
00065 all=r['all']
00066
00067
00068 cm_host_uoa=ini['cfg']['cm_os_uoa_list'][family]
00069
00070
00071 ii={'cm_run_module_uoa':ini['cm_module_uid'],
00072 'cm_action':'load',
00073 'cm_data_uoa':cm_host_uoa
00074 }
00075 if 'cm_repo_uoa' in i and i['cm_repo_uoa']!='': ii['cm_repo_uoa']=i['cm_repo_uoa']
00076 r=cm_kernel.access(ii)
00077 if r['cm_return']>0: return r
00078
00079 cm_host_alias=r['cm_alias']
00080
00081 if i.get('cm_console','')=='txt':
00082 cm_kernel.print_for_con('OS family: '+family)
00083 cm_kernel.print_for_con('OS close default alias: '+cm_host_alias)
00084 cm_kernel.print_for_con('OS close default UOA: '+cm_host_uoa)
00085
00086 if len(all)>0:
00087 cm_kernel.print_for_con('')
00088 cm_kernel.print_for_con('OSes from the same family:')
00089 cm_kernel.print_for_con('')
00090 for x in all:
00091 if 'cm_data_uoa' in x: cm_kernel.print_for_con(x['cm_data_uoa'])
00092
00093 return {'cm_return':0, 'family': family, 'cm_os_uoa_list': all, 'cm_host_uoa': cm_host_uoa, 'cm_host_alias': cm_host_alias}