Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

107 wiersze
3.5 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. update_file = "/var/lib/calculate/calculate-update/updates.available"
  28. def __init__(self, dv=None):
  29. if dv is None:
  30. self.dv = DataVarsCore()
  31. self.dv.importCore()
  32. else:
  33. self.dv = dv
  34. def need_update(self):
  35. return self.update_ready()
  36. @classmethod
  37. def update_ready(cls):
  38. """
  39. Проверить есть ли обновления по ini.env
  40. """
  41. return path.exists(cls.update_file)
  42. @classmethod
  43. def set_update_ready(cls, value):
  44. """
  45. Установить статус обновления
  46. """
  47. try:
  48. if value:
  49. writeFile(cls.update_file).close()
  50. else:
  51. os.unlink(cls.update_file)
  52. except OSError:
  53. pass
  54. def check_for_dispatch(self):
  55. """
  56. Есть ли в системе не примененные файлы для dispatch-conf
  57. """
  58. return bool(getCfgFiles(self.dv.Get('cl_config_protect'),
  59. prefix=self.dv.Get('cl_chroot_path')))
  60. def is_console_gui_run(self):
  61. """
  62. Проверить есть ли уже запущенная копия console-gui
  63. """
  64. return any(ifilter(lambda x: "cl-console-gui" in x, getRunCommands()))
  65. def update_already_run(self):
  66. """
  67. В системе уже есть работающий процесс обновления
  68. """
  69. return search_worked_process("update", self.dv)
  70. @property
  71. def outdated_kernel(self):
  72. flag_path = self.dv.Get('update.cl_update_outdated_kernel_path')
  73. if path.exists(flag_path):
  74. try:
  75. flag_kernel = readFile(flag_path).strip()
  76. current_kernel = self.dv.Get('update.cl_update_kernel_version')
  77. if flag_kernel != current_kernel:
  78. return True
  79. except ValueError:
  80. pass
  81. return False
  82. @outdated_kernel.setter
  83. def outdated_kernel(self, value):
  84. flag_path = self.dv.Get('update.cl_update_outdated_kernel_path')
  85. try:
  86. if value:
  87. with writeFile(flag_path) as f:
  88. f.write(self.dv.Get('update.cl_update_kernel_version'))
  89. else:
  90. if path.exists(flag_path):
  91. os.unlink(flag_path)
  92. except IOError:
  93. pass