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.

308 lines
14 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. #-*- coding: utf-8 -*-
  2. # Copyright 2010-2013 Calculate Ltd. 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.utils.colortext import get_color_print, Colors
  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.update.package_tools import GitError, Eix, EmergeLog, \
  23. EmergeLogNamedTask, PackageList
  24. setLocalTranslate('cl_update3', sys.modules[__name__])
  25. __ = getLazyLocalTranslate(_)
  26. class ClUpdateAction(Action):
  27. """
  28. Действие обновление конфигурационных файлов
  29. """
  30. # ошибки, которые отображаются без подробностей
  31. native_error = (FilesError, UpdateError, GitError, EmergeError)
  32. successMessage = None
  33. failedMessage = __("Update failed")
  34. interruptMessage = __("Update manually interrupted")
  35. def was_installed(pkg, task_name):
  36. def func():
  37. task = EmergeLog(EmergeLogNamedTask(task_name))
  38. return bool(PackageList(task.list)[pkg])
  39. return func
  40. def need_upgrade(pkg):
  41. def func():
  42. return bool(Eix(pkg, Eix.Option.Upgrade).get_packages())
  43. return func
  44. def pkg_color(text):
  45. return text
  46. log_names = {'premerge': "check updates",
  47. 'python_updater': "update python modules",
  48. 'perl_cleaner': "update perl modules",
  49. 'kernel_modules': "update kernel modules",
  50. 'depclean': "depclean",
  51. 'xorg_modules': "update xorg modules",
  52. 'preserved_libs': "update preserved libs",
  53. 'revdep': "revdep rebuild"}
  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_portage',
  73. 'group': __("Updating Portage"),
  74. 'tasks': [
  75. {'name': 'update:update_portage_pkg',
  76. 'message': __("Updating {0}").format(
  77. pkg_color("sys-apps/portage")),
  78. 'method': 'Update.emerge("-u","portage")',
  79. 'condition': need_upgrade('sys-apps/portage$')
  80. },
  81. ]
  82. },
  83. {'name': 'update:update_python',
  84. 'group': __("Updating Python"),
  85. 'tasks': [
  86. {'name': 'update:update_python_pkg',
  87. 'message': __('Updating {0}').format(
  88. pkg_color('dev-lang/python')),
  89. 'method': 'Update.emerge("-u","dev-lang/python")',
  90. 'condition': need_upgrade('dev-lang/python$')
  91. },
  92. {'name': 'update:python_updater',
  93. 'message': __('Find & rebuild packages broken due '
  94. 'to a Python upgrade'),
  95. 'method': 'Update.emergelike("python-updater")',
  96. 'condition': was_installed('dev-lang/python$',
  97. log_names['python_updater']),
  98. 'decoration': 'Update.update_task("%s")' % log_names[
  99. 'python_updater']
  100. },
  101. ]
  102. },
  103. {'name': 'update:update_perl',
  104. 'group': __("Updating Perl"),
  105. 'tasks': [
  106. {'name': 'update:update_perl_pkg',
  107. 'message': __('Updating {0}').format(pkg_color('dev-lang/perl')),
  108. 'method': 'Update.emerge("-u","dev-lang/perl")',
  109. 'condition': need_upgrade('dev-lang/perl$')
  110. },
  111. {'name': 'update:perl_cleaner',
  112. 'message': __('Find & rebuild packages and Perl header files '
  113. 'broken due to a perl upgrade'),
  114. 'method': 'Update.emergelike("perl-cleaner", "all")',
  115. 'condition': was_installed('dev-lang/perl$',
  116. log_names['perl_cleaner']),
  117. 'decoration': 'Update.update_task("%s")' % log_names[
  118. 'perl_cleaner']
  119. },
  120. ]
  121. },
  122. {'name': 'update:update_calculate',
  123. 'group': __("Updating Calculate Utilities"),
  124. 'tasks': [
  125. {'name': 'update:update_calculate_pkgs',
  126. 'message': __("Calculating dependencies"),
  127. 'method': 'Update.emerge("-u","sys-apps/calculate-utilities")',
  128. 'condition': need_upgrade('sys-apps/calculate-utilities$')
  129. },
  130. ]
  131. },
  132. {'name': 'update:update_world',
  133. 'group': __("Updating packages"),
  134. 'tasks': [
  135. {'name': 'update:update_world',
  136. 'message': __("Calculating dependencies"),
  137. 'method': 'Update.emerge("-uDN","--with-bdeps=y","@world")',
  138. }
  139. ]
  140. },
  141. {'name': 'update_other:depclean',
  142. 'group': __("Cleaning the system from needless packages"),
  143. 'tasks': [
  144. {'name': 'update_other:update_depclean',
  145. 'message': __("Calculating dependencies"),
  146. 'method': 'Update.depclean()',
  147. 'condition': was_installed('.*', log_names['depclean']),
  148. 'decoration': 'Update.update_task("%s")' % log_names['depclean']
  149. },
  150. ]
  151. },
  152. {'name': 'update_other:update_modules',
  153. 'group': __("Rebuilding dependent modules"),
  154. 'tasks': [
  155. {'name': 'update_other:module_rebuild',
  156. 'message': __('Updating Kernel modules'),
  157. 'method': 'Update.emerge("@module-rebuild")',
  158. 'condition': was_installed('sys-kernel/.*source',
  159. log_names['kernel_modules']),
  160. 'decoration': 'Update.update_task("%s")' % log_names[
  161. 'kernel_modules']
  162. },
  163. {'name': 'update_other:x11_module_rebuild',
  164. 'message': __('Updating X.Org server modules'),
  165. 'method': 'Update.emerge("@x11-module-rebuild")',
  166. 'condition': was_installed('x11-base/xorg-server',
  167. log_names['xorg_modules']),
  168. 'decoration': 'Update.update_task("%s")' % log_names[
  169. 'xorg_modules']
  170. },
  171. {'name': 'update_other:preserved_rebuild',
  172. 'message': __('Updating preserved libraries'),
  173. 'method': 'Update.emerge("@preserved-rebuild")',
  174. 'condition': was_installed('.*', log_names['preserved_libs']),
  175. 'decoration': 'Update.update_task("%s")' % log_names[
  176. 'preserved_libs']
  177. },
  178. {'name': 'update_other:revdev_rebuild',
  179. 'message': __('Checking reverse dependencies'),
  180. 'method': 'Update.revdep_rebuild("revdep-rebuild")',
  181. 'condition': was_installed('.*', log_names['revdep']),
  182. 'decoration': 'Update.update_task("%s")' % log_names['revdep']
  183. },
  184. {'name': 'update_other:dispatch_conf_end',
  185. 'message': __("Updating configuration files"),
  186. 'method':'Update.dispatchConf()',
  187. 'condition': lambda Get: ((Get('cl_update_rev_set') == 'on' or
  188. Get('cl_rebuild_world_set') == 'on') and
  189. Get('cl_update_pretend_set') == 'off')
  190. },
  191. ]
  192. },
  193. {'name': 'update:set_upto_date_cache',
  194. 'method': 'Update.setUpToDateCache()'
  195. }
  196. ]
  197. # список задач для дейсвия
  198. tasks = [
  199. {'name': 'check_run',
  200. 'method': 'Update.checkRun(cl_update_wait_another_set)'},
  201. {'name': 'reps_synchronization',
  202. 'group': __("Repositories synchronization"),
  203. 'tasks': [
  204. {'name': 'sync_reps',
  205. 'foreach': 'cl_update_sync_rep',
  206. 'message': __("Syncing the {eachvar:capitalize} repository"),
  207. 'method': 'Update.syncRepositories(eachvar)',
  208. 'condition': lambda Get: Get('cl_update_sync_rep')
  209. },
  210. {'name': 'sync_other_reps',
  211. 'foreach': 'cl_update_other_rep_name',
  212. 'message': __("Syncing the {eachvar:capitalize} repository"),
  213. 'method': 'Update.syncLaymanRepository(eachvar)',
  214. 'condition': lambda Get: Get('cl_update_other_set') == 'on'
  215. },
  216. {'name': 'sync_reps:regen_cache',
  217. 'foreach': 'cl_update_sync_overlay_rep',
  218. 'message': __("Updating the {eachvar:capitalize} repository cache"),
  219. 'essential': False,
  220. 'method': 'Update.regenCache(eachvar)',
  221. 'condition': (
  222. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  223. Get('cl_update_metadata_force') != 'skip' or
  224. Get('cl_update_metadata_force') == 'force'))
  225. },
  226. {'name': 'sync_other_reps:regen_other_cache',
  227. 'foreach': 'cl_update_other_rep_name',
  228. 'message': __("Updating the {eachvar:capitalize} repository cache"),
  229. 'method': 'Update.regenCache(eachvar)',
  230. 'essential': False,
  231. },
  232. {'name': 'emerge_metadata',
  233. 'message': __("Metadata transfer"),
  234. 'method': 'Update.emergeMetadata()',
  235. 'condition': (
  236. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  237. Get('cl_update_metadata_force') != 'skip' or
  238. Get('cl_update_metadata_force') == 'force'))
  239. },
  240. {'name': 'eix_update',
  241. 'message': __("Updating the eix cache"),
  242. 'method': 'Update.eixUpdate()',
  243. 'condition': (
  244. lambda Get: (Get('cl_update_outdate_set') == 'on' and
  245. Get('cl_update_eixupdate_force') != 'skip' or
  246. Get('cl_update_eixupdate_force') == 'force'))
  247. },
  248. # сообщение удачного завершения при обновлении репозиториев
  249. {'name': 'success_syncrep',
  250. 'message': __("Synchronization finished"),
  251. 'depend': (Tasks.success() & Tasks.has_any("sync_reps",
  252. "sync_other_reps",
  253. "emerge_metadata",
  254. "eix_update")),
  255. }
  256. ]
  257. },
  258. {'name': 'reps_synchronization',
  259. 'group': __("System configuration"),
  260. 'tasks': [
  261. {'name': 'revision',
  262. 'message': __("Fixing the settings"),
  263. 'method': 'Update.applyTemplates(install.cl_source,'
  264. 'cl_template_clt_set,True,None,False)',
  265. 'condition': lambda Get: (Get('cl_update_rev_set') == 'on' or
  266. Get('cl_rebuild_world_set') == 'on')
  267. },
  268. {'name': 'world',
  269. 'message': __("Updating the list of system packages"),
  270. 'method': 'Update.applyTemplates(install.cl_source,'
  271. 'cl_template_clt_set,True,None,False)',
  272. 'condition': lambda Get: (Get('cl_update_rev_set') == 'on' or
  273. Get('cl_rebuild_world_set') == 'on')
  274. },
  275. {'name': 'dispatch_conf',
  276. 'message': __("Updating configuration files"),
  277. 'method':'Update.dispatchConf()',
  278. 'condition': lambda Get: ((Get('cl_update_rev_set') == 'on' or
  279. Get('cl_rebuild_world_set') == 'on') and
  280. Get('cl_update_pretend_set') == 'off')
  281. },
  282. ]
  283. }
  284. ] + emerge_tasks + [
  285. # сообщение удачного завершения при обновлении ревизии
  286. {'name': 'success_rev',
  287. 'message': __("System update finished!"),
  288. 'condition': lambda Get: (Get('cl_update_rev_set') == 'on' and
  289. Get('cl_update_pretend_set') == 'off')
  290. },
  291. # сообщение удачного завершения при пересоздании world
  292. {'name': 'success_world',
  293. 'message': __("World rebuild finished!"),
  294. 'condition': lambda Get: Get('cl_rebuild_world_set') == 'on'
  295. }
  296. ]