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.

103 lines
3.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2012-2016 Mir Calculate. 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. import os
  16. from os import path
  17. from itertools import ifilter
  18. from calculate.core.datavars import DataVarsCore
  19. from calculate.core.server.gen_pid import search_worked_process
  20. from calculate.lib.cl_template import SystemIni
  21. from calculate.lib.utils.content import getCfgFiles
  22. from calculate.lib.utils.files import getRunCommands, readFile, writeFile
  23. class UpdateInfo(object):
  24. """
  25. Информационный объект о процессе обновления
  26. """
  27. section = "update"
  28. varname = "updates"
  29. def __init__(self, dv=None):
  30. if dv is None:
  31. self.dv = DataVarsCore()
  32. self.dv.importCore()
  33. else:
  34. self.dv = dv
  35. def need_update(self):
  36. return self.update_ready()
  37. @classmethod
  38. def update_ready(cls):
  39. """
  40. Проверить есть ли обновления по ini.env
  41. """
  42. return SystemIni().getVar(cls.section, cls.varname) == u'on'
  43. @classmethod
  44. def set_update_ready(cls, value):
  45. """
  46. Установить статус обновления
  47. """
  48. SystemIni().setVar(cls.section,
  49. {cls.varname:"on" if value else "off"})
  50. def check_for_dispatch(self):
  51. """
  52. Есть ли в системе не примененные файлы для dispatch-conf
  53. """
  54. return bool(getCfgFiles(self.dv.Get('cl_config_protect'),
  55. prefix=self.dv.Get('cl_chroot_path')))
  56. def is_console_gui_run(self):
  57. """
  58. Проверить есть ли уже запущенная копия console-gui
  59. """
  60. return any(ifilter(lambda x: "cl-console-gui" in x, getRunCommands()))
  61. def update_already_run(self):
  62. """
  63. В системе уже есть работающий процесс обновления
  64. """
  65. return search_worked_process("update", self.dv)
  66. @property
  67. def outdated_kernel(self):
  68. flag_path = self.dv.Get('update.cl_update_outdated_kernel_path')
  69. if path.exists(flag_path):
  70. try:
  71. flag_kernel = readFile(flag_path).strip()
  72. current_kernel = self.dv.Get('update.cl_update_kernel_version')
  73. if flag_kernel != current_kernel:
  74. return True
  75. except ValueError:
  76. pass
  77. return False
  78. @outdated_kernel.setter
  79. def outdated_kernel(self, value):
  80. flag_path = self.dv.Get('update.cl_update_outdated_kernel_path')
  81. try:
  82. if value:
  83. with writeFile(flag_path) as f:
  84. f.write(self.dv.Get('update.cl_update_kernel_version'))
  85. else:
  86. if path.exists(flag_path):
  87. os.unlink(flag_path)
  88. except IOError:
  89. pass