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.

142 lines
6.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2010-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 sys
  16. from calculate.core.server.func import Action, Tasks
  17. from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate
  18. from calculate.lib.cl_template import TemplatesError
  19. from calculate.lib.utils.files import FilesError
  20. from calculate.update.update import UpdateError
  21. from calculate.lib.utils.git import GitError
  22. _ = lambda x: x
  23. setLocalTranslate('cl_update3', sys.modules[__name__])
  24. __ = getLazyLocalTranslate(_)
  25. class ClUpdateProfileAction(Action):
  26. """
  27. Действие обновление конфигурационных файлов
  28. """
  29. # ошибки, которые отображаются без подробностей
  30. native_error = (FilesError,
  31. TemplatesError,
  32. UpdateError, GitError)
  33. successMessage = __("The profile was successfully updated")
  34. failedMessage = __("Failed to update the profile")
  35. interruptMessage = __("Profile update manually interrupted")
  36. # список задач для действия
  37. tasks = [
  38. {'name': 'migrate_repository',
  39. 'method': 'Update.migrateCacheRepository('
  40. 'cl_update_profile_url,cl_update_profile_branch,'
  41. 'cl_update_profile_storage)',
  42. 'message': __("Repository transfer"),
  43. 'condition': lambda Get: not (
  44. Get('cl_update_profile_storage').is_local(
  45. Get('cl_update_profile_url'),
  46. Get('cl_update_profile_branch')))
  47. },
  48. {'name': 'reconfigure_vars1',
  49. 'method': 'Update.invalidateVariables("cl_update_profile_storage")',
  50. 'depend': Tasks.has('migrate_repository')
  51. },
  52. {'name': 'drop_binhosts',
  53. 'method': 'Update.drop_binhosts(update.cl_update_profile_datavars)'
  54. },
  55. {'name': 'reconfigure_vars',
  56. 'method': 'Update.reconfigureProfileVars(cl_update_profile_datavars,'
  57. 'cl_chroot_path)'
  58. },
  59. {'name': 'reps_synchronization',
  60. 'group': __("Repositories synchronization"),
  61. 'tasks': [
  62. {'name': 'sync_reps',
  63. 'foreach': 'cl_update_profile_sync_rep',
  64. 'message': __("Syncing the {eachvar:capitalize} repository"),
  65. 'method': 'Update.syncRepositories(eachvar)',
  66. # TODO: неиспользуемое условие
  67. # 'condition': lambda Get: Get('cl_update_profile_sync_rep')
  68. },
  69. {'name': 'sync_reps:regen_cache',
  70. 'foreach': 'cl_update_sync_overlay_rep',
  71. 'message': __("Updating the {eachvar:capitalize} repository cache"),
  72. 'essential': False,
  73. 'method': 'Update.regenCache(eachvar)',
  74. 'condition': (
  75. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  76. Get('cl_update_metadata_force') != 'skip' or
  77. Get('cl_update_metadata_force') == 'force'))
  78. },
  79. {'name': 'emerge_metadata',
  80. 'message': __("Metadata transfer"),
  81. 'method': 'Update.emergeMetadata()',
  82. 'condition': (
  83. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  84. Get('cl_update_metadata_force') != 'skip' or
  85. Get('cl_update_metadata_force') == 'force'))
  86. },
  87. {'name': 'eix_update',
  88. 'message': __("Updating the eix cache for "
  89. "{cl_update_eix_repositories}"),
  90. 'method': 'Update.eixUpdate(cl_repository_name)',
  91. 'condition': (
  92. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  93. Get('cl_update_eixupdate_force') != 'skip' or
  94. Get('cl_update_eixupdate_force') == 'force'))
  95. },
  96. # сообщение удачного завершения при обновлении репозиториев
  97. {'name': 'success_syncrep',
  98. 'message': __("Synchronization finished"),
  99. 'depend': (Tasks.success() & Tasks.has_any("sync_reps",
  100. "sync_other_reps",
  101. "emerge_metadata",
  102. "eix_update")),
  103. }
  104. ]
  105. },
  106. {'name': 'reps_synchronization',
  107. 'group': __("Setting up the profile"),
  108. 'tasks': [
  109. {'name': 'set_profile',
  110. 'message': __("Switching to profile {cl_update_profile_system}"),
  111. 'method': 'Update.setProfile(cl_update_profile_system)'
  112. },
  113. {'name': 'revision',
  114. 'message': __("Fixing the settings"),
  115. 'method': 'Update.applyProfileTemplates(cl_template_clt_set,'
  116. 'True,False,"update_profile")',
  117. 'condition': lambda Get: Get('cl_templates_locate')
  118. },
  119. {'name': 'reconfigure',
  120. 'message': __("The system is being configured"),
  121. 'method': 'Update.applyProfileTemplates(cl_template_clt_set,'
  122. 'True,False,"merge")',
  123. 'condition': lambda Get: (
  124. Get('cl_update_templates_locate') and
  125. Get('cl_update_skip_setup_set') == 'off')
  126. },
  127. {'name': 'dispatch_conf',
  128. 'message': __("Updating configuration files"),
  129. 'method': 'Update.dispatchConf()',
  130. 'condition': lambda Get: Get('cl_dispatch_conf') != 'skip'
  131. },
  132. ]
  133. }
  134. ]