def install(self, feat_type=None):
"""Process the installation.
None is used to install all feature types.
:param feat_type: (str or None) Install features of the given type.
:return: (list) Error messages.
"""
errors = list()
self.__pvalue = 1
self.__nb_steps = len(self._features.get_ids(feat_type))
for step, fid in enumerate(self._features.get_ids(feat_type)):
self.__pheader(self.__message('beginning_feature', fid))
if self._features.available(fid) is False:
pmesg = 'available_false'
elif self._features.enable(fid) is False:
if self._features.feature_type(fid) == 'deps':
if cfg.feature_installed(fid) is False:
cfg.set_feature(fid, False)
pmesg = 'enable_false'
else:
try:
fid_output = self.__install_feature(fid)
if len(fid_output) > 0:
msg = 'Installation of feature {} returned information message(s): '.format(fid)
errors.append(fid_output)
logging.warning(msg + fid_output)
except sppasInstallationError as e:
self._features.enable(fid, False)
pmesg = 'install_failed'
if self._features.feature_type(fid) == 'deps':
cfg.set_feature(fid, False)
errors.append(str(e))
logging.error(str(e))
except NotImplementedError:
self._features.available(fid, False)
self._features.enable(fid, False)
pmesg = 'install_failed'
msg = 'Installation of feature {} is not implemented yet for this os.'.format(fid)
errors.append(msg)
logging.error(msg)
except Exception as e:
logging.debug(traceback.format_exc())
self._features.enable(fid, False)
pmesg = 'install_failed'
msg = 'An un-expected error occurred: {:s}'.format(str(e))
errors.append(msg)
logging.error(msg)
else:
self._features.enable(fid, True)
cfg.set_feature(fid, True)
pmesg = 'install_success'
self.__pvalue = int(100.0 * float(step + 1) / self.__nb_steps)
self.__pupdate(pmesg, fid)
cfg.save()
return errors