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.

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