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.

448 lines
22 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_rep_list',
  140. 'message': __("Repository cache update"),
  141. 'method': Object('update_rep_list()'),
  142. 'condition': lambda Get: (isPkgInstalled(
  143. "app-eselect/eselect-repository", 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('syncOtherRepository(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': 'update_fastlogin_domain',
  249. 'method': "Update.update_fastlogin_domain_path()"
  250. },
  251. {'name': 'premerge_group',
  252. 'group': __("Checking for updates"),
  253. 'tasks': [
  254. {'name': 'premerge',
  255. 'message': __("Calculating dependencies"),
  256. 'method': 'Update.premerge("-uDN","@world")',
  257. 'condition': lambda Get: (
  258. Get('cl_update_sync_only_set') == 'off' and
  259. Get('cl_update_pretend_set') == 'on') and \
  260. (Get('cl_update_world') != "update" or
  261. Get('cl_update_outdate_set') == 'on' or
  262. Get('cl_update_settings_changes_set') == 'on' or
  263. Get('cl_update_binhost_recheck_set') == 'on' or
  264. Get('cl_update_force_fix_set') == 'on' or
  265. Get('update.cl_update_package_cache_set') == 'on')
  266. }],
  267. },
  268. {'name': 'update',
  269. 'condition': lambda Get:Get('cl_update_pretend_set') == 'off' and \
  270. (Get('cl_update_world') != "update" or
  271. Get('cl_update_outdate_set') == 'on' or
  272. Get('cl_update_settings_changes_set') == 'on' or
  273. Get('cl_update_binhost_recheck_set') == 'on' or
  274. Get('cl_update_force_fix_set') == 'on' or
  275. Get('update.cl_update_package_cache_set') == 'on')
  276. },
  277. {'name': 'update_other',
  278. 'condition': lambda Get: ( Get('cl_update_pretend_set') == 'off' and
  279. Get('cl_update_sync_only_set') == 'off')
  280. },
  281. {'name': 'update:update_world',
  282. 'group': __("Updating packages"),
  283. 'tasks': [
  284. {'name': 'update_world',
  285. 'message': __("Calculating dependencies"),
  286. 'method': 'Update.emerge_ask(cl_update_pretend_set,'
  287. '"-uDN","@world")',
  288. }
  289. ],
  290. 'condition': lambda Get: Get('cl_update_sync_only_set') == 'off'
  291. },
  292. {'name': 'update_other:update_perl',
  293. 'group': __("Updating Perl modules"),
  294. 'tasks': [
  295. {'name': 'update_other:perl_cleaner',
  296. 'message': __('Find & rebuild packages and Perl header files '
  297. 'broken due to a perl upgrade'),
  298. 'method': 'Update.emergelike("perl-cleaner", "all")',
  299. 'condition': UpdateConditions.was_installed(
  300. 'dev-lang/perl$', EmergeMark.PerlCleaner),
  301. 'decoration': 'Update.update_task("%s")' % EmergeMark.PerlCleaner
  302. },
  303. ]
  304. },
  305. {'name': 'update_other:depclean',
  306. 'group': __("Cleaning the system from needless packages"),
  307. 'tasks': [
  308. {'name': 'update_other:update_depclean',
  309. 'message': __("Calculating dependencies"),
  310. 'method': 'Update.depclean()',
  311. 'condition': UpdateConditions.need_depclean(
  312. '.*', EmergeMark.Depclean),
  313. 'decoration': 'Update.update_task("%s")' % EmergeMark.Depclean
  314. },
  315. ]
  316. },
  317. {'name': 'update_other:update_modules',
  318. 'group': __("Rebuilding dependent modules"),
  319. 'tasks': [
  320. {'name': 'update_other:module_rebuild',
  321. 'message': __('Updating Kernel modules'),
  322. 'method': 'Update.emerge("","@module-rebuild")',
  323. 'condition': UpdateConditions.was_installed(
  324. 'sys-kernel/.*source', EmergeMark.KernelModules),
  325. 'decoration': 'Update.update_task("%s")' %
  326. EmergeMark.KernelModules
  327. },
  328. {'name': 'update_other:x11_module_rebuild',
  329. 'message': __('Updating X.Org server modules'),
  330. 'method': 'Update.emerge("","@x11-module-rebuild")',
  331. 'condition': UpdateConditions.was_installed(
  332. 'x11-base/xorg-server', EmergeMark.XorgModules),
  333. 'decoration': 'Update.update_task("%s")' %
  334. EmergeMark.XorgModules
  335. },
  336. {'name': 'update_other:preserved_rebuild',
  337. 'message': __('Updating preserved libraries'),
  338. 'method': 'Update.emerge("","@preserved-rebuild")',
  339. 'condition': lambda Get: (UpdateConditions.was_installed(
  340. '.*', EmergeMark.PreservedLibs)() or
  341. UpdateConditions.force_preserved(Get)),
  342. 'decoration': 'Update.update_task("%s")' %
  343. EmergeMark.PreservedLibs
  344. },
  345. {'name': 'update_other:revdev_rebuild',
  346. 'message': __('Checking reverse dependencies'),
  347. 'method': 'Update.revdep_rebuild("revdep-rebuild")',
  348. 'condition': lambda Get: (Get(
  349. 'cl_update_revdep_rebuild_set') == 'on' and
  350. UpdateConditions.was_installed(
  351. '.*', EmergeMark.RevdepRebuild)()),
  352. 'decoration': 'Update.update_task("%s")' %
  353. EmergeMark.RevdepRebuild
  354. },
  355. {'name': 'update_other:dispatch_conf_end',
  356. 'message': __("Updating configuration files"),
  357. 'method': 'Update.dispatchConf()',
  358. 'condition': lambda Get: (Get('cl_dispatch_conf') != 'skip' and
  359. Get('cl_update_pretend_set') == 'off')
  360. },
  361. ]
  362. },
  363. {'name': 'set_upto_date_cache',
  364. 'method': 'Update.setUpToDateCache()',
  365. 'condition': lambda Get: Get('cl_update_sync_only_set') == 'off' and \
  366. Get('cl_update_pretend_set') == 'off'
  367. }
  368. ]
  369. # список задач для действия
  370. tasks = [
  371. {'name': 'check_schedule',
  372. 'method': 'Update.checkSchedule(cl_update_autocheck_interval,'
  373. 'cl_update_autocheck_set)',
  374. 'condition': lambda Get: (
  375. Get('cl_update_autocheck_schedule_set') == 'on'),
  376. },
  377. {'name': 'check_run',
  378. 'method': 'Update.checkRun(cl_update_wait_another_set)'
  379. },
  380. ] + get_synchronization_tasks("Update") + [
  381. {'name': 'system_configuration',
  382. 'group': __("System configuration"),
  383. 'tasks': [
  384. {'name': 'binhost_changed',
  385. 'method': 'Update.message_binhost_changed()'
  386. },
  387. {'name': 'revision',
  388. 'message': __("Fixing the settings"),
  389. 'method': 'Update.applyTemplates(install.cl_source,'
  390. 'cl_template_clt_set,True,None,False)',
  391. 'condition': lambda Get, GetBool: (Get('cl_templates_locate') and
  392. (Get('cl_update_world') != "update" or
  393. GetBool('cl_update_outdate_set') or
  394. GetBool('cl_update_binhost_recheck_set') or
  395. GetBool('cl_update_force_fix_set') or
  396. GetBool('update.cl_update_package_cache_set')))
  397. },
  398. {'name': 'dispatch_conf',
  399. 'message': __("Updating configuration files"),
  400. 'method': 'Update.dispatchConf()',
  401. 'condition': lambda Get, GetBool: (Get('cl_dispatch_conf') != 'skip' and
  402. Get('cl_update_pretend_set') == 'off' and
  403. (GetBool('cl_update_outdate_set') or
  404. GetBool('cl_update_binhost_recheck_set') or
  405. GetBool('cl_update_force_fix_set') or
  406. GetBool('update.cl_update_package_cache_set')))
  407. },
  408. ]
  409. }
  410. ] + emerge_tasks + [
  411. {'name': 'failed',
  412. 'error': __("Update failed"),
  413. 'depend': (Tasks.failed() & Tasks.hasnot("interrupt") &
  414. (Tasks.hasnot("check_schedule") |
  415. Tasks.success_all("check_schedule")))},
  416. {'name': 'failed',
  417. 'depend': Tasks.failed_all("check_schedule")
  418. },
  419. # сообщение удачного завершения при обновлении ревизии
  420. {'name': 'update:save_portage_hash',
  421. 'method': 'Update.save_portage_state_hash()',
  422. },
  423. # сообщение удачного завершения при обновлении ревизии
  424. {'name': 'success_rev',
  425. 'message': __("System update finished!"),
  426. 'condition': lambda Get: (Get('cl_update_rev_set') == 'on' and
  427. Get('cl_update_pretend_set') == 'off')
  428. },
  429. # сообщение удачного завершения при пересоздании world
  430. {'name': 'success_world',
  431. 'message': __("World rebuild finished!"),
  432. 'condition': lambda Get: Get('cl_rebuild_world_set') == 'on'
  433. },
  434. ]