25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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