Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

427 lignes
20 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, AllTasks
  17. from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate
  18. from calculate.lib.cl_template import TemplatesError
  19. from calculate.lib.utils.binhosts import BinhostError
  20. from calculate.lib.utils.files import FilesError, readFile
  21. from calculate.update.update import UpdateError
  22. from calculate.update.emerge_parser import EmergeError
  23. from calculate.lib.utils.git import GitError
  24. from calculate.lib.utils.portage import (EmergeLog, isPkgInstalled,
  25. EmergeLogNamedTask, PackageList)
  26. from calculate.update.update_tasks import EmergeMark
  27. _ = lambda x: x
  28. setLocalTranslate('cl_update3', sys.modules[__name__])
  29. __ = getLazyLocalTranslate(_)
  30. def get_synchronization_tasks(object_name):
  31. Object = lambda s: "%s.%s"%(object_name, s)
  32. return [
  33. {'name': 'reps_synchronization',
  34. 'group': __("Repositories synchronization"),
  35. 'tasks': [
  36. # создать объект проверки PGP
  37. {'name': 'prepare_gpg',
  38. 'method': Object("prepare_gpg()"),
  39. },
  40. # создать объект хранилище серверов обновлений
  41. {'name': 'create_binhost_data',
  42. 'method': Object('create_binhost_data()')
  43. },
  44. # проверить валиден ли текущий хост
  45. {'name': 'check_current_binhost',
  46. 'message': __("Checking current binhost"),
  47. 'essential': False,
  48. 'method': Object('check_current_binhost(update.cl_update_binhost)'),
  49. 'condition': lambda GetBool, Get: (
  50. not GetBool('update.cl_update_binhost_recheck_set') and
  51. Get('update.cl_update_sync_rep') and
  52. Get('update.cl_update_binhost'))
  53. },
  54. {'name': 'not_use_search:failed_base_binhost',
  55. 'error': __("Failed to use base binhost"),
  56. 'method': Object("delete_binhost()"),
  57. 'depend': AllTasks.failed_all("check_current_binhost")
  58. },
  59. {'name': 'group_find_binhost',
  60. 'group': '',
  61. 'while': (~AllTasks.has_any("detect_best_binhost") &
  62. ((AllTasks.failed_all("update_packages_cache")
  63. & ~AllTasks.has_any("not_use_search")) |
  64. ~AllTasks.has_any("sync_reps"))) & Tasks.success(),
  65. 'condition': lambda GetBool, Get: (GetBool('update.cl_update_usetag_set') and
  66. Get('update.cl_update_sync_rep')),
  67. 'tasks': [
  68. # найти лучший сервер обновлений
  69. {'name': 'detect_best_binhost',
  70. 'method': Object('detect_best_binhost()'),
  71. 'essential': False,
  72. 'depend': (Tasks.success() & ~AllTasks.has_any("not_use_search") &
  73. (~AllTasks.success_one_of("check_current_binhost") |
  74. AllTasks.success_all("sync_reps"))),
  75. },
  76. # запасная синхронизация, в ходе которой ветки обновляются до
  77. # master
  78. {'name': 'sync_reps_fallback',
  79. 'foreach': 'update.cl_update_sync_rep',
  80. 'message':
  81. __("Fallback syncing the {eachvar:capitalize} repository"),
  82. 'method': Object('syncRepositories(eachvar,True)'),
  83. 'depend': Tasks.success() & AllTasks.failed_one_of("detect_best_binhost"),
  84. },
  85. # обновление переменных информации из binhost
  86. {'name': 'sync_reps_fallback:update_binhost_list',
  87. 'method': Object('update_binhost_list()'),
  88. 'depend': Tasks.success() & AllTasks.failed_one_of("detect_best_binhost"),
  89. },
  90. # найти лучший сервер обновлений
  91. {'name': 'sync_reps_fallback:detect_best_binhost',
  92. 'method': Object('detect_best_binhost()'),
  93. 'depend': Tasks.success() & AllTasks.failed_one_of("detect_best_binhost"),
  94. },
  95. {'name': 'sync_reps',
  96. 'foreach': 'update.cl_update_sync_rep',
  97. 'message': __("Checking {eachvar:capitalize} updates"),
  98. 'method': Object('syncRepositories(eachvar)'),
  99. 'condition': lambda Get: Get('update.cl_update_sync_rep'),
  100. 'depend': Tasks.success() & ~AllTasks.success_all("update_packages_cache")
  101. },
  102. {'name': 'sync_reps:update_local_info_binhost',
  103. 'method': Object('update_local_info_binhost()'),
  104. },
  105. {'name': 'sync_reps:update_binhost_list',
  106. 'essential': False,
  107. 'method': Object('update_binhost_list()'),
  108. 'condition': lambda GetBool: GetBool('update.cl_update_outdate_set')
  109. },
  110. {'name': 'sync_reps:update_packages_cache',
  111. 'message': __("Update packages index"),
  112. 'method': Object('download_packages(update.cl_update_portage_binhost,'
  113. 'update.cl_update_package_cache,update.cl_update_package_cache_sign,'
  114. 'update.cl_update_gpg)'),
  115. 'essential': False,
  116. 'condition': lambda Get, GetBool: (
  117. Get('update.cl_update_package_cache') and (
  118. Get('update.cl_update_outdate_set') == 'on' or
  119. Get('update.cl_update_package_cache_set') == 'on'))
  120. },
  121. ],
  122. },
  123. {'name': 'no_server',
  124. 'error': __("Failed to find the binary updates server"),
  125. 'method': Object("delete_binhost()"),
  126. # method: который должен удалить текущую информацию о сервере обновлений
  127. 'depend': (~Tasks.has_any("failed_base_binhost") & (Tasks.failed() |
  128. Tasks.success() & AllTasks.failed_one_of("update_packages_cache"))),
  129. 'condition': lambda GetBool, Get: (GetBool('update.cl_update_usetag_set') and
  130. Get('update.cl_update_sync_rep')),
  131. },
  132. {'name': 'sync_reps',
  133. 'foreach': 'update.cl_update_sync_rep',
  134. 'message': __("Checking {eachvar:capitalize} updates"),
  135. 'method': Object('syncRepositories(eachvar)'),
  136. 'condition': lambda Get, GetBool: (Get('update.cl_update_sync_rep') and
  137. not GetBool('update.cl_update_usetag_set')),
  138. },
  139. {'name': 'update_layman',
  140. 'message': __("Layman cache update"),
  141. 'method': Object('update_layman()'),
  142. 'condition': lambda Get: (isPkgInstalled(
  143. "app-portage/layman", prefix=Get('cl_chroot_path')) and
  144. Get('cl_chroot_path') != "/"),
  145. 'essential': False,
  146. },
  147. {'name': 'sync_other_reps',
  148. 'foreach': 'update.cl_update_other_rep_name',
  149. 'message': __("Syncing the {eachvar:capitalize} repository"),
  150. 'method': Object('syncLaymanRepository(eachvar)'),
  151. 'condition': lambda GetBool: GetBool('update.cl_update_other_set')
  152. },
  153. {'name': 'trim_reps',
  154. 'foreach': 'update.cl_update_sync_rep',
  155. 'message': __("Cleaning the history of the "
  156. "{eachvar:capitalize} repository"),
  157. 'method': Object('trimRepositories(eachvar)'),
  158. 'condition': lambda Get: (Get('update.cl_update_sync_rep') and
  159. Get('update.cl_update_onedepth_set') == 'on')
  160. },
  161. {'name': 'sync_reps:regen_cache',
  162. 'foreach': 'update.cl_update_sync_overlay_rep',
  163. 'essential': False,
  164. 'method': Object('regenCache(eachvar)'),
  165. 'condition': (
  166. lambda Get: (Get('update.cl_update_outdate_set') == 'on' and
  167. Get('update.cl_update_egencache_force') != 'skip' or
  168. Get('update.cl_update_egencache_force') == 'force'))
  169. },
  170. {'name': 'sync_other_reps:regen_other_cache',
  171. 'foreach': 'update.cl_update_other_rep_name',
  172. 'method': Object('regenCache(eachvar)'),
  173. 'essential': False,
  174. },
  175. {'name': 'eix_update',
  176. 'message': __("Updating the eix cache for "
  177. "{update.cl_update_eix_repositories}"),
  178. 'method': Object('eixUpdate(cl_repository_name)'),
  179. 'condition': (
  180. lambda Get: (Get('update.cl_update_outdate_set') == 'on' and
  181. Get('update.cl_update_eixupdate_force') != 'skip' or
  182. Get('update.cl_update_eixupdate_force') == 'force'))
  183. },
  184. {'name': 'update_setup_cache',
  185. 'message': __("Updating the cache of configurable packages"),
  186. 'method': Object('updateSetupCache()'),
  187. 'essential': False,
  188. 'condition': lambda Get: Get('update.cl_update_outdate_set') == 'on'
  189. },
  190. {'name': 'sync_reps:cleanpkg',
  191. 'message': __("Removing obsolete distfiles and binary packages"),
  192. 'method': Object('cleanpkg()'),
  193. 'condition': (
  194. lambda Get: Get('update.cl_update_cleanpkg_set') == 'on' and
  195. Get('update.cl_update_outdate_set') == 'on'),
  196. 'essential': False
  197. },
  198. # сообщение удачного завершения при обновлении репозиториев
  199. {'name': 'success_syncrep',
  200. 'message': __("Synchronization finished"),
  201. 'depend': (Tasks.success() & Tasks.has_any("sync_reps",
  202. "sync_other_reps",
  203. "emerge_metadata",
  204. "eix_update")),
  205. }
  206. ]
  207. },
  208. ]
  209. class UpdateConditions(object):
  210. @staticmethod
  211. def was_installed(pkg, task_name):
  212. def func():
  213. task = EmergeLog(EmergeLogNamedTask(task_name))
  214. return bool(PackageList(task.list)[pkg])
  215. return func
  216. @staticmethod
  217. def need_depclean(pkg, task_name):
  218. def func(Get):
  219. task = EmergeLog(EmergeLogNamedTask(task_name))
  220. return (bool(PackageList(task.list)[pkg])
  221. or Get('cl_update_force_depclean_set') == 'on'
  222. or Get('cl_update_outdated_kernel_set') == 'on')
  223. return func
  224. @staticmethod
  225. def force_preserved(Get):
  226. pfile = "/var/lib/portage/preserved_libs_registry"
  227. content = readFile(pfile).strip()
  228. if not content or content[1:-1].strip() == '':
  229. return False
  230. else:
  231. return True
  232. class ClUpdateAction(Action):
  233. """
  234. Действие обновление конфигурационных файлов
  235. """
  236. # ошибки, которые отображаются без подробностей
  237. native_error = (FilesError, UpdateError,
  238. TemplatesError, BinhostError,
  239. GitError, EmergeError)
  240. successMessage = None
  241. failedMessage = None
  242. interruptMessage = __("Update manually interrupted")
  243. emerge_tasks = [
  244. {'name': 'save_bdeps_val',
  245. 'method': 'Update.save_with_bdeps()',
  246. 'essential': False
  247. },
  248. {'name': 'premerge_group',
  249. 'group': __("Checking for updates"),
  250. 'tasks': [
  251. {'name': 'premerge',
  252. 'message': __("Calculating dependencies"),
  253. 'method': 'Update.premerge("-uDN","@world")',
  254. 'condition': lambda Get: (
  255. Get('cl_update_sync_only_set') == 'off' and
  256. Get('cl_update_pretend_set') == 'on')
  257. }],
  258. },
  259. {'name': 'update',
  260. 'condition': lambda Get:Get('cl_update_pretend_set') == 'off',
  261. },
  262. {'name': 'update_other',
  263. 'condition': lambda Get: ( Get('cl_update_pretend_set') == 'off' and
  264. Get('cl_update_sync_only_set') == 'off')
  265. },
  266. {'name': 'update:update_world',
  267. 'group': __("Updating packages"),
  268. 'tasks': [
  269. {'name': 'update_world',
  270. 'message': __("Calculating dependencies"),
  271. 'method': 'Update.emerge_ask(cl_update_pretend_set,'
  272. '"-uDN","@world")',
  273. }
  274. ],
  275. 'condition': lambda Get: Get('cl_update_sync_only_set') == 'off'
  276. },
  277. {'name': 'update_other:update_perl',
  278. 'group': __("Updating Perl"),
  279. 'tasks': [
  280. {'name': 'update_other:perl_cleaner',
  281. 'message': __('Find & rebuild packages and Perl header files '
  282. 'broken due to a perl upgrade'),
  283. 'method': 'Update.emergelike("perl-cleaner", "all")',
  284. 'condition': UpdateConditions.was_installed(
  285. 'dev-lang/perl$', EmergeMark.PerlCleaner),
  286. 'decoration': 'Update.update_task("%s")' % EmergeMark.PerlCleaner
  287. },
  288. ]
  289. },
  290. {'name': 'update_other:depclean',
  291. 'group': __("Cleaning the system from needless packages"),
  292. 'tasks': [
  293. {'name': 'update_other:update_depclean',
  294. 'message': __("Calculating dependencies"),
  295. 'method': 'Update.depclean()',
  296. 'condition': UpdateConditions.need_depclean(
  297. '.*', EmergeMark.Depclean),
  298. 'decoration': 'Update.update_task("%s")' % EmergeMark.Depclean
  299. },
  300. ]
  301. },
  302. {'name': 'update_other:update_modules',
  303. 'group': __("Rebuilding dependent modules"),
  304. 'tasks': [
  305. {'name': 'update_other:module_rebuild',
  306. 'message': __('Updating Kernel modules'),
  307. 'method': 'Update.emerge("","@module-rebuild")',
  308. 'condition': UpdateConditions.was_installed(
  309. 'sys-kernel/.*source', EmergeMark.KernelModules),
  310. 'decoration': 'Update.update_task("%s")' %
  311. EmergeMark.KernelModules
  312. },
  313. {'name': 'update_other:x11_module_rebuild',
  314. 'message': __('Updating X.Org server modules'),
  315. 'method': 'Update.emerge("","@x11-module-rebuild")',
  316. 'condition': UpdateConditions.was_installed(
  317. 'x11-base/xorg-server', EmergeMark.XorgModules),
  318. 'decoration': 'Update.update_task("%s")' %
  319. EmergeMark.XorgModules
  320. },
  321. {'name': 'update_other:preserved_rebuild',
  322. 'message': __('Updating preserved libraries'),
  323. 'method': 'Update.emerge("","@preserved-rebuild")',
  324. 'condition': lambda Get: (UpdateConditions.was_installed(
  325. '.*', EmergeMark.PreservedLibs)() or
  326. UpdateConditions.force_preserved(Get)),
  327. 'decoration': 'Update.update_task("%s")' %
  328. EmergeMark.PreservedLibs
  329. },
  330. {'name': 'update_other:revdev_rebuild',
  331. 'message': __('Checking reverse dependencies'),
  332. 'method': 'Update.revdep_rebuild("revdep-rebuild")',
  333. 'condition': lambda Get: (Get(
  334. 'cl_update_skip_rb_set') == 'off' and
  335. UpdateConditions.was_installed(
  336. '.*', EmergeMark.RevdepRebuild)()),
  337. 'decoration': 'Update.update_task("%s")' %
  338. EmergeMark.RevdepRebuild
  339. },
  340. {'name': 'update_other:dispatch_conf_end',
  341. 'message': __("Updating configuration files"),
  342. 'method': 'Update.dispatchConf()',
  343. 'condition': lambda Get: (Get('cl_dispatch_conf') != 'skip' and
  344. Get('cl_update_pretend_set') == 'off')
  345. },
  346. ]
  347. },
  348. {'name': 'update:set_upto_date_cache',
  349. 'method': 'Update.setUpToDateCache()'
  350. }
  351. ]
  352. # список задач для действия
  353. tasks = [
  354. {'name': 'check_schedule',
  355. 'method': 'Update.checkSchedule(cl_update_autocheck_interval,'
  356. 'cl_update_autocheck_set)',
  357. 'condition': lambda Get: (
  358. Get('cl_update_autocheck_schedule_set') == 'on'),
  359. },
  360. {'name': 'check_run',
  361. 'method': 'Update.checkRun(cl_update_wait_another_set)'
  362. },
  363. ] + get_synchronization_tasks("Update") + [
  364. {'name': 'system_configuration',
  365. 'group': __("System configuration"),
  366. 'tasks': [
  367. {'name': 'binhost_changed',
  368. 'method': 'Update.message_binhost_changed()'
  369. },
  370. {'name': 'revision',
  371. 'message': __("Fixing the settings"),
  372. 'method': 'Update.applyTemplates(install.cl_source,'
  373. 'cl_template_clt_set,True,None,False)',
  374. 'condition': lambda Get, GetBool: (Get('cl_templates_locate') and
  375. (Get('cl_update_world') != "update" or
  376. GetBool('cl_update_outdate_set') or
  377. GetBool('cl_update_binhost_recheck_set') or
  378. GetBool('cl_update_force_fix_set') or
  379. GetBool('update.cl_update_package_cache_set')))
  380. },
  381. {'name': 'dispatch_conf',
  382. 'message': __("Updating configuration files"),
  383. 'method': 'Update.dispatchConf()',
  384. 'condition': lambda Get, GetBool: (Get('cl_dispatch_conf') != 'skip' and
  385. Get('cl_update_pretend_set') == 'off' and
  386. (GetBool('cl_update_outdate_set') or
  387. GetBool('cl_update_binhost_recheck_set') or
  388. GetBool('cl_update_force_fix_set') or
  389. GetBool('update.cl_update_package_cache_set')))
  390. },
  391. ]
  392. }
  393. ] + emerge_tasks + [
  394. {'name': 'failed',
  395. 'error': __("Update failed"),
  396. 'depend': (Tasks.failed() & Tasks.hasnot("interrupt") &
  397. (Tasks.hasnot("check_schedule") |
  398. Tasks.success_all("check_schedule")))},
  399. {'name': 'failed',
  400. 'depend': Tasks.failed_all("check_schedule")
  401. },
  402. # сообщение удачного завершения при обновлении ревизии
  403. {'name': 'success_rev',
  404. 'message': __("System update finished!"),
  405. 'condition': lambda Get: (Get('cl_update_rev_set') == 'on' and
  406. Get('cl_update_pretend_set') == 'off')
  407. },
  408. # сообщение удачного завершения при пересоздании world
  409. {'name': 'success_world',
  410. 'message': __("World rebuild finished!"),
  411. 'condition': lambda Get: Get('cl_rebuild_world_set') == 'on'
  412. },
  413. ]