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.

329 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_python',
  82. 'group': __("Updating Python"),
  83. 'tasks': [
  84. {'name': 'update:python_updater',
  85. 'message': __('Find & rebuild packages broken due '
  86. 'to a Python upgrade'),
  87. 'method': 'Update.emergelike("python-updater")',
  88. 'condition': UpdateConditions.was_installed(
  89. 'dev-lang/python$', EmergeMark.PythonUpdater),
  90. 'decoration': 'Update.update_task("%s")' %
  91. EmergeMark.PythonUpdater
  92. },
  93. ]
  94. },
  95. {'name': 'update:update_perl',
  96. 'group': __("Updating Perl"),
  97. 'tasks': [
  98. {'name': 'update:perl_cleaner',
  99. 'message': __('Find & rebuild packages and Perl header files '
  100. 'broken due to a perl upgrade'),
  101. 'method': 'Update.emergelike("perl-cleaner", "all")',
  102. 'condition': UpdateConditions.was_installed(
  103. 'dev-lang/perl$', EmergeMark.PerlCleaner),
  104. 'decoration': 'Update.update_task("%s")' % EmergeMark.PerlCleaner
  105. },
  106. ]
  107. },
  108. {'name': 'update_other:depclean',
  109. 'group': __("Cleaning the system from needless packages"),
  110. 'tasks': [
  111. {'name': 'update_other:update_depclean',
  112. 'message': __("Calculating dependencies"),
  113. 'method': 'Update.depclean()',
  114. 'condition': UpdateConditions.need_depclean(
  115. '.*', EmergeMark.Depclean),
  116. 'decoration': 'Update.update_task("%s")' % EmergeMark.Depclean
  117. },
  118. ]
  119. },
  120. {'name': 'update_other:update_modules',
  121. 'group': __("Rebuilding dependent modules"),
  122. 'tasks': [
  123. {'name': 'update_other:module_rebuild',
  124. 'message': __('Updating Kernel modules'),
  125. 'method': 'Update.emerge("","@module-rebuild")',
  126. 'condition': UpdateConditions.was_installed(
  127. 'sys-kernel/.*source', EmergeMark.KernelModules),
  128. 'decoration': 'Update.update_task("%s")' %
  129. EmergeMark.KernelModules
  130. },
  131. {'name': 'update_other:x11_module_rebuild',
  132. 'message': __('Updating X.Org server modules'),
  133. 'method': 'Update.emerge("","@x11-module-rebuild")',
  134. 'condition': UpdateConditions.was_installed(
  135. 'x11-base/xorg-server', EmergeMark.XorgModules),
  136. 'decoration': 'Update.update_task("%s")' %
  137. EmergeMark.XorgModules
  138. },
  139. {'name': 'update_other:preserved_rebuild',
  140. 'message': __('Updating preserved libraries'),
  141. 'method': 'Update.emerge("","@preserved-rebuild")',
  142. 'condition': UpdateConditions.was_installed(
  143. '.*', EmergeMark.PreservedLibs),
  144. 'decoration': 'Update.update_task("%s")' %
  145. EmergeMark.PreservedLibs
  146. },
  147. {'name': 'update_other:revdev_rebuild',
  148. 'message': __('Checking reverse dependencies'),
  149. 'method': 'Update.revdep_rebuild("revdep-rebuild")',
  150. 'condition': lambda Get: (Get(
  151. 'cl_update_skip_rb_set') == 'off' and
  152. UpdateConditions.was_installed(
  153. '.*', EmergeMark.RevdepRebuild)()),
  154. 'decoration': 'Update.update_task("%s")' %
  155. EmergeMark.RevdepRebuild
  156. },
  157. {'name': 'update_other:dispatch_conf_end',
  158. 'message': __("Updating configuration files"),
  159. 'method': 'Update.dispatchConf()',
  160. 'condition': lambda Get: (Get('cl_dispatch_conf') != 'skip' and
  161. Get('cl_update_pretend_set') == 'off')
  162. },
  163. ]
  164. },
  165. {'name': 'update:set_upto_date_cache',
  166. 'method': 'Update.setUpToDateCache()'
  167. }
  168. ]
  169. # список задач для действия
  170. tasks = [
  171. {'name': 'check_schedule',
  172. 'method': 'Update.checkSchedule(cl_update_autocheck_interval,'
  173. 'cl_update_autocheck_set)',
  174. 'condition': lambda Get: (
  175. Get('cl_update_autocheck_schedule_set') == 'on'),
  176. },
  177. {'name': 'check_run',
  178. 'method': 'Update.checkRun(cl_update_wait_another_set)'
  179. },
  180. {'name': 'reps_synchronization',
  181. 'group': __("Repositories synchronization"),
  182. 'tasks': [
  183. # запасная синхронизация, в ходе которой ветки обновляются до
  184. # master
  185. {'name': 'sync_reps_fallback',
  186. 'foreach': 'cl_update_sync_rep',
  187. 'message':
  188. __("Fallback syncing the {eachvar:capitalize} repository"),
  189. 'method': 'Update.syncRepositories(eachvar)',
  190. 'condition': lambda Get: ("getbinpkg" in Get('cl_features') and
  191. not Get('cl_update_binhost_data')[0])
  192. },
  193. # обновление переменных информации из binhost
  194. {'name': 'update_binhost_list',
  195. 'method': 'Update.update_binhost_list()',
  196. 'condition': lambda Get: ("getbinpkg" in Get('cl_features') and
  197. not Get('cl_update_binhost_data')[0])
  198. },
  199. {'name': 'sync_reps',
  200. 'foreach': 'cl_update_sync_rep',
  201. 'message': __("Syncing the {eachvar:capitalize} repository"),
  202. 'method': 'Update.syncRepositories(eachvar)',
  203. 'condition': lambda Get: Get('cl_update_sync_rep')
  204. },
  205. {'name': 'check_binhost',
  206. 'method': 'Update.check_binhost()',
  207. 'condition': lambda Get: "getbinpkg" in Get('cl_features')
  208. },
  209. {'name': 'sync_other_reps',
  210. 'foreach': 'cl_update_other_rep_name',
  211. 'message': __("Syncing the {eachvar:capitalize} repository"),
  212. 'method': 'Update.syncLaymanRepository(eachvar)',
  213. 'condition': lambda Get: Get('cl_update_other_set') == 'on'
  214. },
  215. {'name': 'trim_reps',
  216. 'foreach': 'cl_update_sync_rep',
  217. 'message': __("Cleaning the history of the "
  218. "{eachvar:capitalize} repository"),
  219. 'method': 'Update.trimRepositories(eachvar)',
  220. 'condition': lambda Get: (Get('cl_update_sync_rep') and
  221. Get('cl_update_onedepth_set') == 'on')
  222. },
  223. {'name': 'sync_reps:regen_cache',
  224. 'foreach': 'cl_update_sync_overlay_rep',
  225. 'essential': False,
  226. 'method': 'Update.regenCache(eachvar)',
  227. 'condition': (
  228. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  229. Get('cl_update_egencache_force') != 'skip' or
  230. Get('cl_update_egencache_force') == 'force'))
  231. },
  232. {'name': 'sync_other_reps:regen_other_cache',
  233. 'foreach': 'cl_update_other_rep_name',
  234. 'method': 'Update.regenCache(eachvar)',
  235. 'essential': False,
  236. },
  237. {'name': 'emerge_metadata',
  238. 'message': __("Metadata transfer"),
  239. 'method': 'Update.emergeMetadata()',
  240. 'condition': (
  241. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  242. Get('cl_update_metadata_force') != 'skip' or
  243. Get('cl_update_metadata_force') == 'force'))
  244. },
  245. {'name': 'eix_update',
  246. 'message': __("Updating the eix cache for "
  247. "{cl_update_eix_repositories}"),
  248. 'method': 'Update.eixUpdate(cl_repository_name)',
  249. 'condition': (
  250. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  251. Get('cl_update_eixupdate_force') != 'skip' or
  252. Get('cl_update_eixupdate_force') == 'force'))
  253. },
  254. {'name': 'update_setup_cache',
  255. 'message': __("Updating the cache of configurable packages"),
  256. 'method': 'Update.updateSetupCache()',
  257. 'essential': False,
  258. 'condition': lambda Get: Get('cl_update_outdate_set') == 'on'
  259. },
  260. {'name': 'sync_reps:cleanpkg',
  261. 'message': __("Removing obsolete distfiles and binary packages"),
  262. 'method': 'Update.cleanpkg()',
  263. 'condition': (lambda Get: Get('cl_update_cleanpkg_set') == 'on' and
  264. Get('cl_update_outdate_set') == 'on'),
  265. 'essential': False
  266. },
  267. # сообщение удачного завершения при обновлении репозиториев
  268. {'name': 'success_syncrep',
  269. 'message': __("Synchronization finished"),
  270. 'depend': (Tasks.success() & Tasks.has_any("sync_reps",
  271. "sync_other_reps",
  272. "emerge_metadata",
  273. "eix_update")),
  274. }
  275. ]
  276. },
  277. {'name': 'reps_synchronization',
  278. 'group': __("System configuration"),
  279. 'tasks': [
  280. {'name': 'revision',
  281. 'message': __("Fixing the settings"),
  282. 'method': 'Update.applyTemplates(install.cl_source,'
  283. 'cl_template_clt_set,True,None,False)',
  284. 'condition': lambda Get: Get('cl_templates_locate')
  285. },
  286. {'name': 'dispatch_conf',
  287. 'message': __("Updating configuration files"),
  288. 'method':'Update.dispatchConf()',
  289. 'condition': lambda Get: (Get('cl_dispatch_conf') != 'skip' and
  290. Get('cl_update_pretend_set') == 'off')
  291. },
  292. {'name': 'binhost_changed',
  293. 'method': 'Update.message_binhost_changed()'
  294. },
  295. ]
  296. }
  297. ] + emerge_tasks + [
  298. {'name': 'failed',
  299. 'error': __("Update failed"),
  300. 'depend': (Tasks.failed() & Tasks.hasnot("interrupt") &
  301. (Tasks.hasnot("check_schedule") |
  302. Tasks.success_all("check_schedule")))},
  303. {'name': 'failed',
  304. 'depend': Tasks.failed_all("check_schedule")
  305. },
  306. # сообщение удачного завершения при обновлении ревизии
  307. {'name': 'success_rev',
  308. 'message': __("System update finished!"),
  309. 'condition': lambda Get: (Get('cl_update_rev_set') == 'on' and
  310. Get('cl_update_pretend_set') == 'off')
  311. },
  312. # сообщение удачного завершения при пересоздании world
  313. {'name': 'success_world',
  314. 'message': __("World rebuild finished!"),
  315. 'condition': lambda Get: Get('cl_rebuild_world_set') == 'on'
  316. },
  317. ]