You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2012-2013 Calculate Ltd. http://www.calculate-linux.org
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from itertools import ifilter
  16. from calculate.core.datavars import DataVarsCore
  17. from calculate.core.server.gen_pid import search_worked_process
  18. from calculate.lib.cl_template import SystemIni
  19. from calculate.lib.utils.content import getCfgFiles
  20. from calculate.lib.utils.files import getRunCommands
  21. class UpdateInfo(object):
  22. """
  23. Информационный объект о процессе обновления
  24. """
  25. def __init__(self, dv=None):
  26. if dv is None:
  27. self.dv = DataVarsCore()
  28. self.dv.importCore()
  29. else:
  30. self.dv = dv
  31. def need_update(self):
  32. return self.update_ready() or self.check_for_dispatch()
  33. def update_ready(self):
  34. """
  35. Проверить есть ли обновления по ini.env
  36. """
  37. return SystemIni().getVar('update', 'packages') == u'on'
  38. def check_for_dispatch(self):
  39. """
  40. Есть ли в системе не примененные файлы для dispatch-conf
  41. """
  42. return bool(getCfgFiles(self.dv.Get('cl_config_protect'),
  43. prefix=self.dv.Get('cl_chroot_path')))
  44. def is_console_gui_run(self):
  45. """
  46. Проверить есть ли уже запущенная копия console-gui
  47. """
  48. return any(ifilter(lambda x: "cl-console-gui" in x, getRunCommands()))
  49. def update_already_run(self):
  50. """
  51. В системе уже есть работающий процесс обновления
  52. """
  53. return search_worked_process("update", self.dv)