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.

315 lines
14 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.update.emerge_parser import EmergeError
  22. from calculate.lib.utils.git import GitError
  23. from calculate.lib.utils.portage import (EmergeLog,
  24. EmergeLogNamedTask, PackageList)
  25. from calculate.update.update_tasks import EmergeMark
  26. _ = lambda x: x
  27. setLocalTranslate('cl_update3', sys.modules[__name__])
  28. __ = getLazyLocalTranslate(_)
  29. class UpdateConditions(object):
  30. @staticmethod
  31. def was_installed(pkg, task_name):
  32. def func():
  33. task = EmergeLog(EmergeLogNamedTask(task_name))
  34. return bool(PackageList(task.list)[pkg])
  35. return func
  36. @staticmethod
  37. def need_depclean(pkg, task_name):
  38. def func(Get):
  39. task = EmergeLog(EmergeLogNamedTask(task_name))
  40. return (bool(PackageList(task.list)[pkg])
  41. or Get('cl_update_outdated_kernel_set') == 'on')
  42. return func
  43. class ClUpdateAction(Action):
  44. """
  45. Действие обновление конфигурационных файлов
  46. """
  47. # ошибки, которые отображаются без подробностей
  48. native_error = (FilesError, UpdateError,
  49. TemplatesError,
  50. GitError, EmergeError)
  51. successMessage = None
  52. failedMessage = None
  53. interruptMessage = __("Update manually interrupted")
  54. emerge_tasks = [
  55. {'name': 'premerge_group',
  56. 'group': __("Checking for updates"),
  57. 'tasks': [
  58. {'name': 'premerge',
  59. 'message': __("Calculating dependencies"),
  60. 'method': 'Update.premerge("-uDN","--with-bdeps=y","@world")',
  61. 'condition': lambda Get:Get('cl_update_sync_only_set') == 'off'
  62. }],
  63. },
  64. {'name': 'premerge:update',
  65. 'condition': lambda Get:Get('cl_update_pretend_set') == 'off',
  66. 'depend': Tasks.result("premerge", eq='yes')
  67. },
  68. {'name': 'update_other',
  69. 'condition': lambda Get: ( Get('cl_update_pretend_set') == 'off' and
  70. Get('cl_update_sync_only_set') == 'off')
  71. },
  72. {'name': 'update:update_world',
  73. 'group': __("Updating packages"),
  74. 'tasks': [
  75. {'name': 'update:update_world',
  76. 'message': __("Calculating dependencies"),
  77. 'method': 'Update.emerge("","-uDN","--with-bdeps=y","@world")',
  78. }
  79. ]
  80. },
  81. {'name': 'update:update_perl',
  82. 'group': __("Updating Perl"),
  83. 'tasks': [
  84. {'name': 'update:perl_cleaner',
  85. 'message': __('Find & rebuild packages and Perl header files '
  86. 'broken due to a perl upgrade'),
  87. 'method': 'Update.emergelike("perl-cleaner", "all")',
  88. 'condition': UpdateConditions.was_installed(
  89. 'dev-lang/perl$', EmergeMark.PerlCleaner),
  90. 'decoration': 'Update.update_task("%s")' % EmergeMark.PerlCleaner
  91. },
  92. ]
  93. },
  94. {'name': 'update_other:depclean',
  95. 'group': __("Cleaning the system from needless packages"),
  96. 'tasks': [
  97. {'name': 'update_other:update_depclean',
  98. 'message': __("Calculating dependencies"),
  99. 'method': 'Update.depclean()',
  100. 'condition': UpdateConditions.need_depclean(
  101. '.*', EmergeMark.Depclean),
  102. 'decoration': 'Update.update_task("%s")' % EmergeMark.Depclean
  103. },
  104. ]
  105. },
  106. {'name': 'update_other:update_modules',
  107. 'group': __("Rebuilding dependent modules"),
  108. 'tasks': [
  109. {'name': 'update_other:module_rebuild',
  110. 'message': __('Updating Kernel modules'),
  111. 'method': 'Update.emerge("","@module-rebuild")',
  112. 'condition': UpdateConditions.was_installed(
  113. 'sys-kernel/.*source', EmergeMark.KernelModules),
  114. 'decoration': 'Update.update_task("%s")' %
  115. EmergeMark.KernelModules
  116. },
  117. {'name': 'update_other:x11_module_rebuild',
  118. 'message': __('Updating X.Org server modules'),
  119. 'method': 'Update.emerge("","@x11-module-rebuild")',
  120. 'condition': UpdateConditions.was_installed(
  121. 'x11-base/xorg-server', EmergeMark.XorgModules),
  122. 'decoration': 'Update.update_task("%s")' %
  123. EmergeMark.XorgModules
  124. },
  125. {'name': 'update_other:preserved_rebuild',
  126. 'message': __('Updating preserved libraries'),
  127. 'method': 'Update.emerge("","@preserved-rebuild")',
  128. 'condition': UpdateConditions.was_installed(
  129. '.*', EmergeMark.PreservedLibs),
  130. 'decoration': 'Update.update_task("%s")' %
  131. EmergeMark.PreservedLibs
  132. },
  133. {'name': 'update_other:revdev_rebuild',
  134. 'message': __('Checking reverse dependencies'),
  135. 'method': 'Update.revdep_rebuild("revdep-rebuild")',
  136. 'condition': lambda Get: (Get(
  137. 'cl_update_skip_rb_set') == 'off' and
  138. UpdateConditions.was_installed(
  139. '.*', EmergeMark.RevdepRebuild)()),
  140. 'decoration': 'Update.update_task("%s")' %
  141. EmergeMark.RevdepRebuild
  142. },
  143. {'name': 'update_other:dispatch_conf_end',
  144. 'message': __("Updating configuration files"),
  145. 'method': 'Update.dispatchConf()',
  146. 'condition': lambda Get: (Get('cl_dispatch_conf') != 'skip' and
  147. Get('cl_update_pretend_set') == 'off')
  148. },
  149. ]
  150. },
  151. {'name': 'update:set_upto_date_cache',
  152. 'method': 'Update.setUpToDateCache()'
  153. }
  154. ]
  155. # список задач для действия
  156. tasks = [
  157. {'name': 'check_schedule',
  158. 'method': 'Update.checkSchedule(cl_update_autocheck_interval,'
  159. 'cl_update_autocheck_set)',
  160. 'condition': lambda Get: (
  161. Get('cl_update_autocheck_schedule_set') == 'on'),
  162. },
  163. {'name': 'check_run',
  164. 'method': 'Update.checkRun(cl_update_wait_another_set)'
  165. },
  166. {'name': 'reps_synchronization',
  167. 'group': __("Repositories synchronization"),
  168. 'tasks': [
  169. # запасная синхронизация, в ходе которой ветки обновляются до
  170. # master
  171. {'name': 'sync_reps_fallback',
  172. 'foreach': 'cl_update_sync_rep',
  173. 'message':
  174. __("Fallback syncing the {eachvar:capitalize} repository"),
  175. 'method': 'Update.syncRepositories(eachvar)',
  176. 'condition': lambda Get: ("getbinpkg" in Get('cl_features') and
  177. not Get('cl_update_binhost_data')[0])
  178. },
  179. # обновление переменных информации из binhost
  180. {'name': 'update_binhost_list',
  181. 'method': 'Update.update_binhost_list()',
  182. 'condition': lambda Get: ("getbinpkg" in Get('cl_features') and
  183. not Get('cl_update_binhost_data')[0])
  184. },
  185. {'name': 'sync_reps',
  186. 'foreach': 'cl_update_sync_rep',
  187. 'message': __("Syncing the {eachvar:capitalize} repository"),
  188. 'method': 'Update.syncRepositories(eachvar)',
  189. 'condition': lambda Get: Get('cl_update_sync_rep')
  190. },
  191. {'name': 'check_binhost',
  192. 'method': 'Update.check_binhost()',
  193. 'condition': lambda Get: "getbinpkg" in Get('cl_features')
  194. },
  195. {'name': 'sync_other_reps',
  196. 'foreach': 'cl_update_other_rep_name',
  197. 'message': __("Syncing the {eachvar:capitalize} repository"),
  198. 'method': 'Update.syncLaymanRepository(eachvar)',
  199. 'condition': lambda Get: Get('cl_update_other_set') == 'on'
  200. },
  201. {'name': 'trim_reps',
  202. 'foreach': 'cl_update_sync_rep',
  203. 'message': __("Cleaning the history of the "
  204. "{eachvar:capitalize} repository"),
  205. 'method': 'Update.trimRepositories(eachvar)',
  206. 'condition': lambda Get: (Get('cl_update_sync_rep') and
  207. Get('cl_update_onedepth_set') == 'on')
  208. },
  209. {'name': 'sync_reps:regen_cache',
  210. 'foreach': 'cl_update_sync_overlay_rep',
  211. 'essential': False,
  212. 'method': 'Update.regenCache(eachvar)',
  213. 'condition': (
  214. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  215. Get('cl_update_egencache_force') != 'skip' or
  216. Get('cl_update_egencache_force') == 'force'))
  217. },
  218. {'name': 'sync_other_reps:regen_other_cache',
  219. 'foreach': 'cl_update_other_rep_name',
  220. 'method': 'Update.regenCache(eachvar)',
  221. 'essential': False,
  222. },
  223. {'name': 'emerge_metadata',
  224. 'message': __("Metadata transfer"),
  225. 'method': 'Update.emergeMetadata()',
  226. 'condition': (
  227. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  228. Get('cl_update_metadata_force') != 'skip' or
  229. Get('cl_update_metadata_force') == 'force'))
  230. },
  231. {'name': 'eix_update',
  232. 'message': __("Updating the eix cache for "
  233. "{cl_update_eix_repositories}"),
  234. 'method': 'Update.eixUpdate(cl_repository_name)',
  235. 'condition': (
  236. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  237. Get('cl_update_eixupdate_force') != 'skip' or
  238. Get('cl_update_eixupdate_force') == 'force'))
  239. },
  240. {'name': 'update_setup_cache',
  241. 'message': __("Updating the cache of configurable packages"),
  242. 'method': 'Update.updateSetupCache()',
  243. 'essential': False,
  244. 'condition': lambda Get: Get('cl_update_outdate_set') == 'on'
  245. },
  246. {'name': 'sync_reps:cleanpkg',
  247. 'message': __("Removing obsolete distfiles and binary packages"),
  248. 'method': 'Update.cleanpkg()',
  249. 'condition': (lambda Get: Get('cl_update_cleanpkg_set') == 'on' and
  250. Get('cl_update_outdate_set') == 'on'),
  251. 'essential': False
  252. },
  253. # сообщение удачного завершения при обновлении репозиториев
  254. {'name': 'success_syncrep',
  255. 'message': __("Synchronization finished"),
  256. 'depend': (Tasks.success() & Tasks.has_any("sync_reps",
  257. "sync_other_reps",
  258. "emerge_metadata",
  259. "eix_update")),
  260. }
  261. ]
  262. },
  263. {'name': 'reps_synchronization',
  264. 'group': __("System configuration"),
  265. 'tasks': [
  266. {'name': 'revision',
  267. 'message': __("Fixing the settings"),
  268. 'method': 'Update.applyTemplates(install.cl_source,'
  269. 'cl_template_clt_set,True,None,False)',
  270. 'condition': lambda Get: Get('cl_templates_locate')
  271. },
  272. {'name': 'dispatch_conf',
  273. 'message': __("Updating configuration files"),
  274. 'method':'Update.dispatchConf()',
  275. 'condition': lambda Get: (Get('cl_dispatch_conf') != 'skip' and
  276. Get('cl_update_pretend_set') == 'off')
  277. },
  278. {'name': 'binhost_changed',
  279. 'method': 'Update.message_binhost_changed()'
  280. },
  281. ]
  282. }
  283. ] + emerge_tasks + [
  284. {'name': 'failed',
  285. 'error': __("Update failed"),
  286. 'depend': (Tasks.failed() & Tasks.hasnot("interrupt") &
  287. (Tasks.hasnot("check_schedule") |
  288. Tasks.success_all("check_schedule")))},
  289. {'name': 'failed',
  290. 'depend': Tasks.failed_all("check_schedule")
  291. },
  292. # сообщение удачного завершения при обновлении ревизии
  293. {'name': 'success_rev',
  294. 'message': __("System update finished!"),
  295. 'condition': lambda Get: (Get('cl_update_rev_set') == 'on' and
  296. Get('cl_update_pretend_set') == 'off')
  297. },
  298. # сообщение удачного завершения при пересоздании world
  299. {'name': 'success_world',
  300. 'message': __("World rebuild finished!"),
  301. 'condition': lambda Get: Get('cl_rebuild_world_set') == 'on'
  302. },
  303. ]