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.

1763 lines
54 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2013-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 os
  16. import sys
  17. import re
  18. from os import path
  19. from calculate.lib.cl_template import SystemIni
  20. from calculate.lib.cl_log import log
  21. from calculate.lib.datavars import (Variable, VariableError,
  22. ReadonlyVariable, ReadonlyTableVariable,
  23. TableVariable, FieldValue,
  24. HumanReadable, CriticalError,
  25. SimpleDataVars, DataVarsError)
  26. from calculate.lib.utils.binhosts import Binhosts, PackagesIndex, HOURS
  27. from calculate.lib.utils.files import readFile, listDirectory, process, pathJoin
  28. from calculate.lib.configparser import ConfigParser
  29. from calculate.lib.cl_lang import setLocalTranslate
  30. from calculate.lib.utils.text import simplify_profiles
  31. from calculate.lib.utils.git import Git, GitError
  32. from calculate.lib.utils.portage import Layman
  33. from ..profile import (RepositoryStorageSet, DEFAULT_BRANCH,
  34. LocalStorage, ProfileRepository, CacheStorage)
  35. from calculate.lib.variables import linux as lib_linux
  36. from calculate.lib.variables import env
  37. from calculate.update.update_info import UpdateInfo
  38. from itertools import chain
  39. from urlparse import urlparse
  40. import time
  41. _ = lambda x: x
  42. setLocalTranslate('cl_update3', sys.modules[__name__])
  43. class VariableAcUpdateSync(ReadonlyVariable):
  44. """
  45. Action variable which has value "up" for package install and
  46. install this package
  47. """
  48. def get(self):
  49. action = self.Get("cl_action")
  50. if action in ("sync",):
  51. if self.Get('cl_update_world'):
  52. return self.Get('cl_update_world')
  53. return ""
  54. class VariableClUpdateWorldDefault(Variable):
  55. """
  56. Ad-hoc
  57. """
  58. value = "update"
  59. class VariableClUpdateWorld(Variable):
  60. type = "choice"
  61. opt = ["--world"]
  62. syntax = "--{choice}-world"
  63. metavalue = "MODE"
  64. def init(self):
  65. self.help = ("'rebuild' - " + _("rebuild the system packages list") +
  66. ",\n'merge' - " + _("append the profile packages list") +
  67. ",\n'update' - " + _("update the system packages list"))
  68. self.label = _("System packages list")
  69. def get(self):
  70. return self.Get('cl_update_world_default')
  71. def choice(self):
  72. return [("rebuild", _("Rebuild")),
  73. ("merge", _("Merge")),
  74. ("update", _("Update"))]
  75. class VariableClRebuildWorldSet(Variable):
  76. """
  77. List of action update world, rebuild world,
  78. """
  79. type = "bool"
  80. opt = ["--rebuild-world"]
  81. untrusted = True
  82. value = "off"
  83. def init(self):
  84. self.help = _("Rebuild world")
  85. self.label = _("Rebuild world")
  86. class VariableClUpdateRevSet(Variable):
  87. """
  88. List of action update world, rebuild world,
  89. """
  90. type = "bool"
  91. opt = ["--update-rev"]
  92. untrusted = True
  93. value = "on"
  94. check_after = ["cl_update_sync_rep",
  95. "cl_update_metadata_force",
  96. "cl_update_other_set",
  97. "cl_update_eixupdate_force"]
  98. def init(self):
  99. self.help = _("make a revision update")
  100. self.label = _("Make a revision update")
  101. class VariableClUpdateRep(Variable):
  102. """
  103. Обновлять репозитории до конкретной ревизии или до последней
  104. """
  105. type = "choice"
  106. value = "rev"
  107. def choice(self):
  108. return ["last", "rev"]
  109. class VariableClUpdateRepData(ReadonlyTableVariable):
  110. """
  111. Информация о репозиториях
  112. """
  113. source = ['cl_update_rep_name',
  114. 'cl_update_rep_url',
  115. 'cl_update_rep_path',
  116. 'cl_update_rep_rev']
  117. class VariableClUpdateRepName(Variable):
  118. """
  119. Список имен используемых репозиториев
  120. """
  121. type = "list"
  122. value = []
  123. def humanReadable(self):
  124. return [x.capitalize() for x in self.Get()]
  125. class VariableClUpdateRepUrl(Variable):
  126. """
  127. Список путей до репозиториев
  128. """
  129. type = "list"
  130. value = []
  131. class VariableClUpdateLaymanConfig(ReadonlyVariable):
  132. """
  133. Объект конфига layman
  134. """
  135. type = "object"
  136. def get(self):
  137. chroot = self.Get('cl_chroot_path')
  138. cp = ConfigParser()
  139. cp.read(path.join(chroot, 'etc/layman/layman.cfg'))
  140. return cp
  141. class VariableClUpdateLaymanStorage(Variable):
  142. """
  143. Путь к репозиториям layman
  144. """
  145. param_name = "storage"
  146. fallback_value = "var/lib/layman"
  147. def get(self):
  148. cp = self.Get('cl_update_layman_config')
  149. res = cp.get('MAIN', self.param_name, fallback=self.fallback_value)
  150. return pathJoin(self.Get('cl_chroot_path'), res)
  151. class VariableClUpdateRepPath(ReadonlyVariable):
  152. """
  153. Пути до репозиториев
  154. """
  155. type = "list"
  156. mapPath = {'portage': 'usr/portage',
  157. 'gentoo': 'usr/portage'}
  158. def get(self):
  159. repPath = self.Get('cl_update_layman_storage')
  160. chroot_path = self.Get('cl_chroot_path')
  161. def generatePaths(names):
  162. for name in names:
  163. if name in self.mapPath:
  164. yield path.join(chroot_path, self.mapPath[name])
  165. else:
  166. yield path.join(repPath, name)
  167. return list(generatePaths(self.Get('cl_update_rep_name')))
  168. class VariableClUpdateRepRev(Variable):
  169. """
  170. Ревизии до которых необходимо обновить репозитории
  171. """
  172. type = "list"
  173. def get(self):
  174. cp = ConfigParser()
  175. revisions = self.Get('update.cl_update_binhost_revisions')
  176. if revisions:
  177. cp.read_string(unicode(revisions[0]))
  178. branch = self.Get('cl_update_branch')
  179. def generateBranch():
  180. for repname, branchname in zip(
  181. self.Get('cl_update_rep_name'),
  182. self.Get('cl_update_branch_name')):
  183. if branchname == Git.Reference.Tag:
  184. yield cp.get("vcs", repname, fallback=branch)
  185. else:
  186. yield branchname
  187. return list(generateBranch())
  188. class VariableClUpdateBranch(Variable):
  189. """
  190. Ветка на которую будет обновляться репозиторий если -getbinpkg
  191. """
  192. value = Git.Reference.Master
  193. class VariableClUpdateBranchData(TableVariable):
  194. """
  195. Выбор веток репозиториев до которых необходимо обновиться
  196. """
  197. opt = ["--branch"]
  198. metavalue = 'REFS'
  199. untrusted = True
  200. source = ["cl_update_branch_rep",
  201. "cl_update_branch_name"]
  202. def init(self):
  203. self.help = _("set references for repository (REPOSITORY:REF)")
  204. self.label = _("Repositories references")
  205. def raiseReadonlyIndexError(self, fieldname="", variablename="", value=""):
  206. """
  207. Неизвестный оврелей
  208. """
  209. raise VariableError(_("Repository %s not found") % value)
  210. class VariableClUpdateBranchRep(ReadonlyVariable):
  211. """
  212. Список доступных репозиторием
  213. """
  214. type = "list"
  215. def init(self):
  216. self.label = _("Repository")
  217. def get(self):
  218. return self.Get('cl_update_rep_name')
  219. class VariableClUpdateBinhostData(ReadonlyTableVariable):
  220. """
  221. Таблица содержащая
  222. binhost/содержимое файла ревизий/время доступа
  223. """
  224. source = ["cl_update_binhost_host",
  225. "cl_update_binhost_revisions",
  226. "cl_update_binhost_timestamp",
  227. "cl_update_binhost_time"]
  228. def get_logger(self, stub=False):
  229. class StubLogger(object):
  230. def info(self, message):
  231. pass
  232. if not stub and (not self.Get('cl_ebuild_phase')):
  233. # проверка на chroot_path
  234. return log("binhost-scan.log",
  235. filename=pathJoin(
  236. self.Get('cl_chroot_path'),
  237. "/var/log/calculate/binhost-scan.log"),
  238. formatter="%(message)s")
  239. else:
  240. return StubLogger()
  241. def get(self, hr=HumanReadable.No):
  242. last_ts = self.Get('cl_update_last_timestamp')
  243. if self.GetBool('cl_update_binhost_stable_opt_set'):
  244. binhost_list = self.Get('cl_update_binhost_list')
  245. else:
  246. binhost_list = self.Get('cl_update_binhost_unstable_list')
  247. if (self.GetBool('cl_update_binhost_stable_opt_set') and
  248. not self.GetBool('cl_update_binhost_stable_set')):
  249. stabilization = True
  250. else:
  251. stabilization = False
  252. binhosts_data = Binhosts(
  253. self.GetInteger('cl_update_binhost_timeout'),
  254. self.Get('cl_update_binhost_revision_path'),
  255. self.Get('cl_update_binhost_timestamp_path'),
  256. last_ts,
  257. binhost_list
  258. )
  259. binhost = self.Get('cl_update_binhost')
  260. recheck = self.GetBool('cl_update_binhost_recheck_set')
  261. if not recheck and binhost and binhost in binhost_list:
  262. ts, t, good, downgrade = binhosts_data.get_timestamp(binhost)
  263. # условие актуальности текущего сервера
  264. if ts and good and not downgrade:
  265. status, data = binhosts_data.check_binhost(binhost)
  266. if status == binhosts_data.BinhostStatus.Success:
  267. return [[binhost, data, ts, str(t)]]
  268. logger = self.get_logger(stub=binhosts_data.is_cache())
  269. ret_val = None
  270. logger.info("Started scan on: {date}, current timestamp: {ts}".format(
  271. date=time.ctime(), ts=last_ts))
  272. for host, ts, t, good, downgrade in binhosts_data.get_sorted():
  273. if ret_val is None:
  274. status, data = binhosts_data.check_binhost(host)
  275. else:
  276. status, data = binhosts_data.BinhostStatus.UnknownError, ""
  277. if not good:
  278. if ts == "0":
  279. reason = "FAILED (Wrong binhost)"
  280. data = ""
  281. t = 0
  282. else:
  283. reason = "OUTDATED"
  284. elif downgrade:
  285. reason = "SKIP"
  286. elif not data and ret_val is None:
  287. errors = {
  288. binhosts_data.BinhostStatus.Updating: "UPDATING",
  289. binhosts_data.BinhostStatus.BadEnv:
  290. "FAILED (Bad env)",
  291. binhosts_data.BinhostStatus.EnvNotFound:
  292. "FAILED (Env not found)",
  293. }
  294. reason = errors.get(status, "FAILED (Unknown)")
  295. else:
  296. reason = ""
  297. if ret_val is None and data and (
  298. not downgrade or stabilization):
  299. ret_val = [[host, data, ts, str(t)]]
  300. host = "-> %s" % host
  301. logger.info("{host:<60} {speed:<7} {timestamp:<10} {reason}".format(
  302. host=host, speed=float(t) / 1000.0, timestamp=ts,
  303. reason=reason))
  304. return ret_val or [[]]
  305. class VariableClUpdateBinhostRecheckSet(Variable):
  306. """
  307. Принудительно обновить binhost
  308. """
  309. type = "bool"
  310. value = "off"
  311. opt = ["--scan"]
  312. def init(self):
  313. self.help = _("search for the most appropriate update server")
  314. self.label = _("Search for the most appropriate update server")
  315. class VariableClUpdateBinhostHost(FieldValue, ReadonlyVariable):
  316. """
  317. Список имен прочих репозиториев
  318. """
  319. type = "list"
  320. source_variable = "cl_update_binhost_data"
  321. column = 0
  322. class VariableClUpdateBinhostRevisions(FieldValue, ReadonlyVariable):
  323. """
  324. Список имен прочих репозиториев
  325. """
  326. type = "list"
  327. source_variable = "cl_update_binhost_data"
  328. column = 1
  329. class VariableClUpdateBinhostTimestamp(FieldValue, ReadonlyVariable):
  330. """
  331. Список имен прочих репозиториев
  332. """
  333. type = "list"
  334. source_variable = "cl_update_binhost_data"
  335. column = 2
  336. class VariableClUpdateLastTimestamp(ReadonlyVariable):
  337. """
  338. Текущий timestamp
  339. """
  340. def get(self):
  341. ini = SystemIni(self.parent)
  342. return ini.getVar('system', 'last_update') or "0"
  343. class VariableClUpdateBinhostTime(FieldValue, ReadonlyVariable):
  344. """
  345. Список имен прочих репозиториев
  346. """
  347. type = "list"
  348. source_variable = "cl_update_binhost_data"
  349. column = 3
  350. class VariableClUpdateBranchName(Variable):
  351. """
  352. Список доступных репозиторием
  353. """
  354. type = "choiceedit-list"
  355. def init(self):
  356. self.label = _("Reference")
  357. def choice(self):
  358. return [
  359. Git.Reference.Tag,
  360. Git.Reference.Master,
  361. Git.Reference.Develop,
  362. Git.Reference.Update]
  363. def get(self):
  364. if "getbinpkg" in self.Get('cl_features'):
  365. return [Git.Reference.Tag for x in self.Get('cl_update_rep_name')]
  366. else:
  367. branch = self.Get('cl_update_branch')
  368. return [branch for x in self.Get('cl_update_rep_name')]
  369. class VariableClUpdateSyncRep(Variable):
  370. """
  371. Обновляемый репозиторий
  372. """
  373. type = "choice-list"
  374. element = "selecttable"
  375. opt = ["-r", "--repositories"]
  376. metavalue = "REPOSITORIES"
  377. untrusted = True
  378. @property
  379. def rep_name(self):
  380. return self.Get('update.cl_update_rep_name')
  381. def init(self):
  382. self.help = _("synchronized repositories (all by default)")
  383. self.label = _("Synchronized repositories")
  384. def set(self, value):
  385. orderList = self.rep_name
  386. return sorted(value, key=lambda x:
  387. (orderList.index(x) if x in orderList else -1), reverse=True)
  388. def get(self):
  389. return list(reversed(self.rep_name))
  390. def choice(self):
  391. return [ (x, x.capitalize()) for x in self.rep_name]
  392. class VariableClUpdateSyncOverlayRep(ReadonlyVariable):
  393. """
  394. Обновляемые репозитории (исключая portage)
  395. """
  396. type = "list"
  397. def get(self):
  398. return filter(lambda x: x not in ("portage", "gentoo"),
  399. self.Get('cl_update_sync_rep'))
  400. class VariableClUpdateOutdateSet(ReadonlyVariable):
  401. """
  402. Флаг устанавливаемый в ходе обновления репозиториев,
  403. сообщающий что хотя бы один из запланированных репозиториев
  404. обновлен и следует обновляет различные метаданные
  405. Если обновляются прочие оверлеи - данные считаются что устарели
  406. """
  407. type = "bool"
  408. def get(self):
  409. if (self.Get('cl_update_other_set') == 'on' and
  410. self.Get('cl_update_other_rep_name')):
  411. return "on"
  412. return "off"
  413. class VariableClUpdateMetadataForce(Variable):
  414. """
  415. Принудительное действие с метаданными
  416. """
  417. type = "choice"
  418. value = "auto"
  419. opt = ["--update-metadata"]
  420. syntax = "--{choice}-update-metadata"
  421. metavalue = "MODE"
  422. # untrusted = True
  423. def init(self):
  424. self.help = ("'force' - " + _("force the update ebuilds metadata") +
  425. ",\n'skip' - " + _("skip the ebuild metadata update") +
  426. ",\n'auto' - " + _("update metadata if it is outdated"))
  427. self.label = _("Update metadata")
  428. def choice(self):
  429. return [("force", _("Force")),
  430. ("skip", _("Skip")),
  431. ("auto", _("If needed"))]
  432. class VariableClUpdateEgencacheForce(Variable):
  433. """
  434. Принудительное выполнение egencache
  435. """
  436. type = "choice"
  437. value = "auto"
  438. opt = ["--egencache"]
  439. syntax = "--{choice}-egencache"
  440. metavalue = "MODE"
  441. # untrusted = True
  442. def init(self):
  443. self.help = (
  444. "'force' - " + _("force the update of the overlays cache") +
  445. ",\n'skip' - " + _("skip the update of the overlays cache") +
  446. ",\n'auto' - " + _("update the overlays cache if outdated"))
  447. self.label = _("Update the overlays cache")
  448. def choice(self):
  449. return [("force", _("Force")),
  450. ("skip", _("Skip")),
  451. ("auto", _("If needed"))]
  452. class VariableClUpdateEixupdateForce(Variable):
  453. """
  454. Принудительное действие с eix-update
  455. """
  456. type = "choice"
  457. value = "auto"
  458. opt = ["--eix-update"]
  459. syntax = "--{choice}-eix-update"
  460. metavalue = "MODE"
  461. # untrusted = True
  462. def init(self):
  463. self.help = ("'force' - " + _("force the eix cache update") +
  464. ",\n'skip' - " + _("skip the eix cache update") +
  465. ",\n'auto' - " + _("update the eix cache if it "
  466. "is outdated"))
  467. self.label = _("Update the eix cache")
  468. def choice(self):
  469. return [("force", _("Force")),
  470. ("skip", _("Skip")),
  471. ("auto", _("If needed"))]
  472. class VariableClUpdateOtherSet(Variable):
  473. """
  474. Обновить остальные оверлеи
  475. """
  476. type = "bool"
  477. value = "off"
  478. opt = ["-o", "--update-other"]
  479. def init(self):
  480. self.help = _("update other overlays")
  481. self.label = _("Update other overlays")
  482. class VariableClUpdateOtherRepData(ReadonlyTableVariable):
  483. """
  484. Информация о прочих репозиториях
  485. """
  486. source = ['cl_update_other_rep_name',
  487. 'cl_update_other_rep_path']
  488. portdir_overlay = "main.cl_portdir_overlay"
  489. def generator(self):
  490. repNames = self.Get('update.cl_update_rep_name')
  491. chroot_path = self.Get('cl_chroot_path')
  492. layman = Layman(self.Get('update.cl_update_layman_installed'),
  493. self.Get('update.cl_update_layman_make'),
  494. self.Get('update.cl_update_layman_conf'),
  495. prefix=chroot_path)
  496. layman_overlays = layman.get_installed()
  497. for rpath in self.Get(self.portdir_overlay):
  498. repo_file = path.join(rpath, "profiles/repo_name")
  499. rname = readFile(repo_file).strip() or path.basename(rpath)
  500. if rname in layman_overlays and rname not in repNames:
  501. yield (rname, rpath)
  502. def get(self, hr=HumanReadable.No):
  503. return list(self.generator())
  504. class VariableClUpdateOtherRepName(FieldValue, ReadonlyVariable):
  505. """
  506. Список имен прочих репозиториев
  507. """
  508. type = "list"
  509. source_variable = "cl_update_other_rep_data"
  510. column = 0
  511. class VariableClUpdateOtherRepPath(FieldValue, ReadonlyVariable):
  512. """
  513. Список путей до прочих репозиториев
  514. """
  515. type = "list"
  516. source_variable = "cl_update_other_rep_data"
  517. column = 1
  518. class VariableClUpdateLaymanInstalled(VariableClUpdateLaymanStorage):
  519. """
  520. Путь до файла layman installed.xml
  521. """
  522. param_name = "installed"
  523. fallback_value = "var/lib/layman/installed.xml"
  524. class VariableClUpdateLaymanMake(VariableClUpdateLaymanStorage):
  525. """
  526. Путь до файла make.conf изменяемого layman`ом
  527. """
  528. param_name = "make_conf"
  529. fallback_value = "var/lib/layman/make.conf"
  530. class VariableClUpdateLaymanConf(VariableClUpdateLaymanStorage):
  531. """
  532. Путь до конфигурационного файла репозиториев для layman
  533. """
  534. param_name = "repos_conf"
  535. fallback_value = "etc/portage/repos.conf/layman.conf"
  536. class VariableClUpdatePretendSet(Variable):
  537. """
  538. Запустить предварительную проверку на обновления
  539. """
  540. type = "bool"
  541. value = "off"
  542. opt = ["-p", "--pretend"]
  543. def init(self):
  544. self.label = _("Pretend a package update")
  545. self.help = _("instead of actually performing the update, "
  546. "simply display the list of packages that "
  547. "will be installed")
  548. class VariableClUpdateSyncOnlySet(Variable):
  549. """
  550. Не выполнять установку/обновление пакетов при обновлении
  551. """
  552. type = "bool"
  553. value = "off"
  554. opt = ["-s", "--sync-only"]
  555. def init(self):
  556. self.label = _("Only synchronize repositories")
  557. self.help = _("do not update packages")
  558. def check(self, value):
  559. if (value == "on" and self.Get('cl_rebuild_world_set') != 'on' and
  560. not self.Get('cl_update_sync_rep') and
  561. self.Get('cl_update_other_set') == 'off' and
  562. self.Get('cl_update_rev_set') == 'off' and
  563. self.Get('cl_update_metadata_force') != "force" and
  564. self.Get('cl_update_eixupdate_force') != "force"):
  565. raise VariableError(_("Select at least one sync repository"))
  566. class VariableClUpdateWaitAnotherSet(Variable):
  567. """
  568. Ждать завершения другого процесса обновления
  569. """
  570. type = "bool"
  571. value = "on"
  572. opt = ["--wait-another-update"]
  573. def init(self):
  574. self.label = _("Wait for another update to be complete")
  575. self.help = _("wait until the running update is finished")
  576. class VariableClUpdateProfileStorage(ReadonlyVariable):
  577. type = "object"
  578. def get(self):
  579. return RepositoryStorageSet(
  580. LocalStorage('/var/lib/layman'),
  581. CacheStorage('/var/calculate/tmp/update'))
  582. class VariableClUpdateRepHost(Variable):
  583. type = "list"
  584. value = ['calculate']
  585. class VariableClUpdateRepHostUrl(Variable):
  586. type = "list"
  587. value = ['git://github.com/calculatelinux/%s.git']
  588. class VariableClUpdateProfileDatavars(ReadonlyVariable):
  589. type = "object"
  590. profile = "cl_update_profile_system"
  591. profiles_path = "cl_update_profile_path"
  592. profiles_shortname = "cl_update_profile_shortname"
  593. def get(self):
  594. profile = self.Get(self.profile)
  595. path_profile = self.Select(self.profiles_path,
  596. where=self.profiles_shortname,
  597. eq=profile, limit=1)
  598. if path_profile:
  599. return DataVarsUpdateProfile(path_profile)
  600. return ""
  601. class VariableClUpdateProfileLinuxFullname(ReadonlyVariable):
  602. """
  603. Имя системы в профиле
  604. """
  605. def init(self):
  606. self.label = _("Distribution name")
  607. datavars = "cl_update_profile_datavars"
  608. def get(self):
  609. dv = self.Get(self.datavars)
  610. if dv:
  611. try:
  612. subname = dv.Get('os_linux_subname')
  613. linuxname = dv.Get('os_linux_name')
  614. linuxver = dv.Get('os_linux_ver')
  615. if subname:
  616. return "%s %s %s" % (linuxname, linuxver, subname)
  617. return "%s %s" % (linuxname, linuxver)
  618. except DataVarsError as s:
  619. raise VariableError("Wrong Calculate Linux profile")
  620. return ""
  621. class VariableClUpdateProfileDependData(ReadonlyTableVariable):
  622. """
  623. Зависимые репозитории
  624. """
  625. source = ['cl_update_profile_depend_name',
  626. 'cl_update_profile_depend_url']
  627. datavars = "cl_update_profile_datavars"
  628. def init(self):
  629. self.label = _("Used repositories")
  630. @staticmethod
  631. def url_like(url1, url2):
  632. match1 = VariableClUpdateProfileUrl.re_url.search(url1)
  633. match2 = VariableClUpdateProfileUrl.re_url.search(url2)
  634. if match1 and match2:
  635. return match1.group(2).lower() == match2.group(2).lower()
  636. return False
  637. def get(self, hr=HumanReadable.No):
  638. dv = self.Get(self.datavars)
  639. # TODO: неиспользуемая переменная возможно
  640. # испольуется для инициализации
  641. # url = self.Get('cl_update_profile_url').lower()
  642. if dv:
  643. if hr == HumanReadable.Yes:
  644. return reversed(zip([x.capitalize() for x in dv.Get('cl_update_rep_name')],
  645. dv.Get('cl_update_rep_url')))
  646. else:
  647. return reversed(zip(dv.Get('cl_update_rep_name'),
  648. dv.Get('cl_update_rep_url')))
  649. return ""
  650. setValue = Variable.setValue
  651. class VariableClUpdateTemplatesLocate(Variable):
  652. """
  653. Выбранные типы хранилищ шаблонов
  654. """
  655. type = "choice-list"
  656. element = "selecttable"
  657. opt = ["-T", "--templates"]
  658. metavalue = "TEMPLATES"
  659. untrusted = True
  660. check_after = ['cl_update_profile_system']
  661. profile_datevars = "update.cl_update_profile_datavars"
  662. descriptionMap = {'overlay': _('Overlay templates'),
  663. 'local': _('Local templates'),
  664. 'calculate': _("Calculate overlay templates"),
  665. 'distros': _('Distribution templates'),
  666. 'distro': _('Distribution templates'),
  667. 'remote': _('Remote templates'),
  668. 'clt': _('clt templates')}
  669. def init(self):
  670. self.label = _("Templates location")
  671. self.help = _("select the location for templates %s") \
  672. % ",".join(self.get())
  673. def get(self):
  674. dv = self.Get(self.profile_datevars)
  675. if dv:
  676. return dv.Get('cl_template_location') + ['clt']
  677. else:
  678. return self.Get('cl_templates_locate')
  679. def choice(self):
  680. descr = lambda x: self.descriptionMap.get(x,
  681. _("%s overlay templates" % x))
  682. return map(lambda x: (x, descr(x)), self.get())
  683. class VariableClUpdateProfileDependName(FieldValue, ReadonlyVariable):
  684. type = "list"
  685. source_variable = "cl_update_profile_depend_data"
  686. column = 0
  687. def init(self):
  688. self.label = _("Name")
  689. class VariableClUpdateProfileDependUrl(FieldValue, ReadonlyVariable):
  690. type = "list"
  691. source_variable = "cl_update_profile_depend_data"
  692. column = 1
  693. def init(self):
  694. self.label = _("URL")
  695. class VariableClUpdateProfileRepName(ReadonlyVariable):
  696. type = "list"
  697. def get(self):
  698. dv = self.Get('cl_update_profile_datavars')
  699. if dv:
  700. return dv.Get('cl_update_rep_name')
  701. return []
  702. class VariableClUpdateProfileSyncRep(ReadonlyVariable):
  703. type = "list"
  704. def get(self):
  705. return list(reversed(self.Get('cl_update_profile_rep_name')))
  706. class VariableClUpdateProfileRepUrl(ReadonlyVariable):
  707. type = "list"
  708. def get(self):
  709. dv = self.Get('cl_update_profile_datavars')
  710. if dv:
  711. return dv.Get('cl_update_rep_url')
  712. return []
  713. class VariableClUpdateProfileLinuxVer(ReadonlyVariable):
  714. """
  715. Имя системы в профиле
  716. """
  717. def init(self):
  718. self.label = _("System profile version")
  719. def get(self):
  720. dv = self.Get('cl_update_profile_datavars')
  721. if dv:
  722. return dv.Get('os_linux_ver')
  723. return ""
  724. class VariableClUpdateProfileLinuxName(ReadonlyVariable):
  725. """
  726. Имя системы в профиле
  727. """
  728. def get(self):
  729. dv = self.Get('cl_update_profile_datavars')
  730. if dv:
  731. dv.Get('os_linux_name')
  732. return ""
  733. class VariableClUpdateProfileUrl(Variable):
  734. """
  735. URL текущего репозитория
  736. """
  737. untrusted = True
  738. check_after = ["cl_update_profile_branch"]
  739. check_action = "update_profile"
  740. opt = ["--url"]
  741. metavalue = "URL"
  742. profile = "cl_profile_system"
  743. branch = "cl_update_profile_branch"
  744. storage = "cl_update_profile_storage"
  745. default_url = "git://github.com/calculatelinux/distros.git"
  746. profiles_shortname = 'cl_update_profile_shortname'
  747. @property
  748. def current_root(self):
  749. return '/'
  750. @property
  751. def rep_names(self):
  752. return self.Get("update.cl_update_rep_name")
  753. def init(self):
  754. self.label = _("Profile repository")
  755. self.help = _("set the profile repository")
  756. re_url = re.compile(
  757. r"^(?:(%s)://)?(\w[\w\./:-]+?\w)(\.git)?$" % "|".join(
  758. ["http", "https", "git"]))
  759. re_shortname = re.compile('^(?:([\w\.-]+):)?([\w\.-]+)$')
  760. @classmethod
  761. def normalize_url(cls, url):
  762. match = cls.re_url.match(url)
  763. if not match:
  764. raise VariableError(_("Wrong repository URL"))
  765. url = match.group(2)
  766. url = "%s://%s" % (match.group(1) or "git", url)
  767. url = "%s.git" % url
  768. return url
  769. def url_by_shortname(self, value):
  770. match = self.re_shortname.match(value)
  771. if not match.group(1):
  772. template = self.Get('update.cl_update_rep_host_url')
  773. if template:
  774. template = template[0]
  775. else:
  776. template = self.Select('update.cl_update_rep_host_url',
  777. where='update.cl_update_rep_host',
  778. eq=match.group(1), limit=1)
  779. if not template:
  780. raise VariableError(_("Failed to determine the repository host"))
  781. try:
  782. return template % match.group(2)
  783. except TypeError:
  784. raise VariableError(_("Failed to determine the repository host"))
  785. def set(self, value):
  786. if self.re_shortname.match(value):
  787. value = self.url_by_shortname(value)
  788. return self.normalize_url(value)
  789. def check(self, value):
  790. if not value:
  791. raise VariableError("Need to specify profile repository")
  792. try:
  793. branch = self.Get(self.branch)
  794. self.Get(self.storage).get_profiles(value, branch)
  795. except GitError as e:
  796. raise VariableError(str(e))
  797. if not self.Get(self.profiles_shortname):
  798. raise VariableError(_("Repository %s has no profiles") %
  799. value.encode('utf-8'))
  800. def get(self):
  801. try:
  802. profile = self.Get(self.profile)
  803. if profile:
  804. while (profile != self.current_root and
  805. ".git" not in listDirectory(profile) and
  806. "repo_name" not in listDirectory(
  807. path.join(profile,"profiles"))):
  808. profile = path.dirname(profile)
  809. if profile == self.current_root:
  810. return self.default_url
  811. if ".git" not in listDirectory(profile):
  812. repo_name = readFile(path.join(
  813. profile,"profiles/repo_name")).strip()
  814. if (repo_name in self.rep_names and
  815. self.Get('cl_action') == self.check_action):
  816. raise CriticalError(
  817. _("You need to update the repositories before "
  818. "you change the profile"))
  819. git = Git()
  820. return git.get_url(profile, "origin") or self.default_url
  821. except CriticalError as e:
  822. raise VariableError(str(e))
  823. except Exception as e:
  824. pass
  825. return self.default_url
  826. class VariableClUpdateProfileRepoName(ReadonlyVariable):
  827. def init(self):
  828. self.label = _("Repository name")
  829. storage = "cl_update_profile_storage"
  830. url = "cl_update_profile_url"
  831. def get(self):
  832. rep_set = self.Get(self.storage)
  833. url = self.Get(self.url)
  834. if url:
  835. rep = rep_set.get_repository(url, branch=None)
  836. if rep:
  837. return rep.repo_name
  838. return ""
  839. class VariableClUpdateProfileBranch(Variable):
  840. """
  841. Текущий репозиторий
  842. """
  843. untrusted = True
  844. type = "edit"
  845. opt = ["--branch"]
  846. metavalue = "BRANCH"
  847. storage = "cl_update_profile_storage"
  848. url = "cl_update_profile_url"
  849. value = DEFAULT_BRANCH
  850. def init(self):
  851. self.label = _("Repository branch")
  852. self.help = _("set the repository branch")
  853. def check(self, value):
  854. pass
  855. ## TODO: проверка ветки
  856. # try:
  857. # url = self.Get('cl_update_profile_url')
  858. # self.Get('cl_update_profile_storage').get_profiles(url, value)
  859. # except GitError as e:
  860. # raise VariableError(str(e))
  861. class VariableClProfileRepository(ReadonlyVariable):
  862. """
  863. Репозиторий из которого будут получены профили
  864. """
  865. type = "object"
  866. def get(self):
  867. try:
  868. profile_dn = self.Get('cl_profile_system')
  869. while profile_dn != '/' and ".git" not in listDirectory(profile_dn):
  870. profile_dn = path.dirname(profile_dn)
  871. if profile_dn == '/':
  872. return ""
  873. ls = LocalStorage(path.dirname(profile_dn))
  874. return ProfileRepository(path.basename(profile_dn), ls)
  875. except Exception:
  876. return ""
  877. class VariableClProfileData(ReadonlyTableVariable):
  878. """
  879. Таблица данных о текущих профилях системы
  880. """
  881. source = []
  882. repository = "cl_profile_repository"
  883. def profile_filter(self, profiles):
  884. arch = self.Get('os_arch_machine_gentoo')
  885. return [x for x in profiles if x.arch == arch]
  886. def get(self, hr=HumanReadable.No):
  887. rep = self.Get(self.repository)
  888. if not rep:
  889. return [[]]
  890. profiles = rep.get_profiles()
  891. if not profiles:
  892. return [[]]
  893. repo_name = profiles[0].repository.repo_name
  894. filtered_profiles = self.profile_filter(profiles)
  895. full_name = [x.profile for x in filtered_profiles]
  896. profile_path = [x.path for x in filtered_profiles]
  897. profile_arch = [x.arch for x in filtered_profiles]
  898. short_name = simplify_profiles(full_name)
  899. full_name = ["%s:%s" % (repo_name, x) for x in full_name]
  900. return zip(full_name,
  901. short_name,
  902. profile_path,
  903. profile_arch)
  904. setValue = Variable.setValue
  905. class VariableClUpdateProfileRepository(ReadonlyVariable):
  906. """
  907. Репозиторий из которого будет извлечён список профилей
  908. """
  909. type = "object"
  910. url = "cl_update_profile_url"
  911. storage = "cl_update_profile_storage"
  912. branch = "cl_update_profile_branch"
  913. sync_set = "update.cl_update_profile_sync_set"
  914. def get(self):
  915. url = self.Get(self.url)
  916. if not url:
  917. return ""
  918. try:
  919. rep_set = self.Get(self.storage)
  920. branch = self.Get(self.branch)
  921. rep = rep_set.get_repository(url, branch=None)
  922. if rep and self.Get(self.sync_set) == 'on':
  923. rep.sync()
  924. return rep_set.get_repository(url, branch=None) or ""
  925. except GitError:
  926. return ""
  927. class VariableClUpdateProfileRepositoryName(ReadonlyVariable):
  928. """
  929. Название репозитория, из которого будут извлечены профили
  930. """
  931. def get(self):
  932. rep = self.Get('cl_update_profile_repository')
  933. if rep:
  934. return rep.repo_name
  935. return ""
  936. class VariableClUpdateProfileData(VariableClProfileData):
  937. source = ["cl_update_profile_fullname",
  938. "cl_update_profile_shortname",
  939. "cl_update_profile_path",
  940. "cl_update_profile_arch"]
  941. repository = "cl_update_profile_repository"
  942. class VariableClUpdateProfileFullname(FieldValue, ReadonlyVariable):
  943. """
  944. Полное название профиля
  945. """
  946. type = "list"
  947. source_variable = "cl_update_profile_data"
  948. column = 0
  949. class VariableClUpdateProfileShortname(FieldValue, ReadonlyVariable):
  950. """
  951. Упрощенное название профиля
  952. """
  953. type = "list"
  954. source_variable = "cl_update_profile_data"
  955. column = 1
  956. class VariableClUpdateProfilePath(FieldValue, ReadonlyVariable):
  957. """
  958. Путь от корня до профиля
  959. """
  960. type = "list"
  961. source_variable = "cl_update_profile_data"
  962. column = 2
  963. class VariableClUpdateProfileArch(FieldValue, ReadonlyVariable):
  964. """
  965. Архитектура профиля
  966. """
  967. type = "list"
  968. source_variable = "cl_update_profile_data"
  969. column = 3
  970. class VariableClUpdateProfileSystem(Variable):
  971. """
  972. Профиль системы (симлинк /etc/make.profile')
  973. """
  974. type = "choice"
  975. opt = ["cl_update_profile_system"]
  976. untrusted = True
  977. metavalue = "PROFILE"
  978. profiles_path = "cl_update_profile_path"
  979. profiles_shortname = "cl_update_profile_shortname"
  980. profiles_fullname = "cl_update_profile_fullname"
  981. profiles_arch = "cl_update_profile_arch"
  982. profile = "cl_profile_system"
  983. url = "cl_update_profile_url"
  984. gentoo_arch = 'os_arch_machine_gentoo'
  985. def init(self):
  986. self.label = _("System profile")
  987. self.help = _("set the system profile")
  988. def check(self, profile):
  989. if not profile:
  990. raise VariableError(_("You must specify the profile"))
  991. path_profile = self.Select(self.profiles_path,
  992. where=self.profiles_shortname,
  993. eq=profile, limit=1)
  994. profile_fullname = self.Select(self.profiles_fullname,
  995. where=self.profiles_shortname,
  996. eq=profile, limit=1)
  997. if path_profile:
  998. dv = DataVarsUpdateProfile(path_profile)
  999. if ":" in profile_fullname:
  1000. repo_name = profile_fullname.partition(":")[0]
  1001. else:
  1002. repo_name = ""
  1003. try:
  1004. if (not dv.Get('cl_update_rep_name') or
  1005. not dv.Get('cl_update_rep_url')):
  1006. raise VariableError(
  1007. _("Repository variables "
  1008. "were not configured for the profile"))
  1009. if not dv.Get('os_linux_name'):
  1010. raise VariableError("")
  1011. if repo_name not in list(dv.Get('cl_update_rep_name')):
  1012. raise VariableError(
  1013. _("Overlay %s is not specified "
  1014. "in cl_update_rep_name") % repo_name)
  1015. except (DataVarsError, VariableError) as e:
  1016. if str(e):
  1017. message = ". " + str(e)
  1018. else:
  1019. message = ""
  1020. raise VariableError(_("The selected profile is not Calculate")
  1021. + message)
  1022. else:
  1023. raise VariableError(_("Wrong Calculate profile"))
  1024. def get(self):
  1025. try:
  1026. profile_system = self.Get(self.profile)
  1027. profile = self.Select(self.profiles_shortname,
  1028. where=self.profiles_path,
  1029. eq=profile_system, limit=1)
  1030. if profile:
  1031. return profile
  1032. except VariableError:
  1033. pass
  1034. shortname = self.Get(self.profiles_shortname)
  1035. if len(shortname) == 1:
  1036. return shortname[0]
  1037. return ""
  1038. def choice(self):
  1039. url = self.Get(self.url)
  1040. if not url:
  1041. return []
  1042. arch = self.Get(self.gentoo_arch)
  1043. profiles = zip(*self.Select([self.profiles_shortname,
  1044. self.profiles_fullname],
  1045. where=self.profiles_arch, eq=arch))
  1046. if profiles:
  1047. short_name, full_name = profiles
  1048. return zip(short_name, full_name)
  1049. return []
  1050. class DataVarsUpdateProfile(SimpleDataVars):
  1051. """
  1052. Упрощенная модель переменных для получения данных с удаленного профиля
  1053. """
  1054. source = ['cl_update_rep_name',
  1055. 'cl_update_rep_url',
  1056. 'cl_update_rep_path',
  1057. 'cl_update_rep_rev',
  1058. 'cl_update_branch_name']
  1059. def __init__(self, profile, chroot_path='/', recheck=None, stable=None):
  1060. SimpleDataVars.__init__(
  1061. self,
  1062. lib_linux.VariableOsLinuxName(),
  1063. lib_linux.VariableOsLinuxShortname(),
  1064. lib_linux.VariableOsLinuxSubname(),
  1065. lib_linux.VariableOsLinuxVer(),
  1066. lib_linux.VariableClProfileSystem(),
  1067. env.VariableClRepositoryData(),
  1068. env.VariableClRepositoryName(),
  1069. env.VariableClRepositoryLocation(),
  1070. env.VariableClChrootPath(),
  1071. env.VariableClTemplateLocation(),
  1072. env.VariableClTemplatePath(),
  1073. env.VariableClEmergeConfig(systemRoot=chroot_path),
  1074. env.VariableClEmergeInfo(systemRoot=chroot_path),
  1075. env.VariableClFeatures(),
  1076. env.VariableClMakeProfile(),
  1077. env.VariableClEbuildPhase(),
  1078. VariableClUpdateRepData(section="update"),
  1079. VariableClUpdateRepPath(section="update"),
  1080. VariableClUpdateRepRev(section="update"),
  1081. VariableClUpdateBranch(section="update"),
  1082. VariableClUpdateBranchName(section="update"),
  1083. VariableClUpdateLaymanConfig(section="update"),
  1084. VariableClUpdateLaymanStorage(section="update"),
  1085. VariableClUpdateRepName(section="update"),
  1086. VariableClUpdateRep(section="update"),
  1087. VariableClUpdateRepUrl(section="update"),
  1088. VariableClUpdateBinhost(section="update"),
  1089. VariableClUpdateBinhostData(section="update"),
  1090. VariableClUpdateBinhostHost(section="update"),
  1091. VariableClUpdateBinhostRecheckSet(section="update"),
  1092. VariableClUpdateBinhostRevisions(section="update"),
  1093. VariableClUpdateBinhostTime(section="update"),
  1094. VariableClUpdateBinhostTimestamp(section="update"),
  1095. VariableClUpdateLastTimestamp(section="update"),
  1096. VariableClUpdateBinhostTimeout(section="update"),
  1097. VariableClUpdateBinhostTimestampPath(section="update"),
  1098. VariableClUpdateBinhostList(section="update"),
  1099. VariableClUpdateBinhostUnstableList(section="update"),
  1100. VariableClUpdateBinhostStableSet(section="update"),
  1101. VariableClUpdateBinhostStableOptSet(section="update"),
  1102. VariableClUpdateBinhostRevisionPath(section="update"),
  1103. )
  1104. self['cl_profile_system'] = profile
  1105. self['cl_chroot_path'] = chroot_path
  1106. if recheck is not None:
  1107. self['cl_update_binhost_recheck_set'] = recheck
  1108. if stable is not None:
  1109. self['cl_update_binhost_stable_opt_set'] = stable
  1110. self.flIniFileFrom(profile)
  1111. def __repr__(self):
  1112. return "Profile variables"
  1113. class VariableClUpdateProfileSyncSet(Variable):
  1114. """
  1115. Синхронизировать репозиторий перед сменой профиля
  1116. """
  1117. type = "bool"
  1118. value = "off"
  1119. opt = ["-u", "--update-cache"]
  1120. def init(self):
  1121. self.label = _("Update the cache")
  1122. self.help = _("Update the cache")
  1123. class VariableClUpdateAutocheckSet(Variable):
  1124. """
  1125. Выполнять/невыполнять автопроверку обновлений
  1126. """
  1127. type = "bool"
  1128. value = "on"
  1129. opt = ["-a", "--autocheck"]
  1130. def init(self):
  1131. self.label = _("Automatically check updates")
  1132. self.help = _("automatically check updates")
  1133. class VariableClUpdateAutocheckInterval(Variable):
  1134. """
  1135. Интервал выполнения проверки
  1136. """
  1137. type = "choiceedit"
  1138. opt = ["-I", "--autocheck-interval"]
  1139. metavalue = "INTERVAL"
  1140. def init(self):
  1141. self.label = _("Interval for the updates checking")
  1142. self.help = _("set interval for the updates checking")
  1143. def choice(self):
  1144. return [["6h", _("every six hours")],
  1145. ["12h", _("every twelve hours")],
  1146. ["1d", _("daily")]]
  1147. class VariableClUpdateAutocheckScheduleSet(Variable):
  1148. """
  1149. Запустить проверку только если со времени последнего запуска прошло
  1150. необходимое время
  1151. """
  1152. type = "bool"
  1153. value = "off"
  1154. opt = ["--schedule"]
  1155. def init(self):
  1156. self.label = _("Consider the autocheck schedule")
  1157. self.help = _("consider the autocheck schedule")
  1158. class VariableClUpdateEmergelistSet(Variable):
  1159. """
  1160. Вывести список пакетов в формате emerge
  1161. """
  1162. type = "bool"
  1163. value = "off"
  1164. opt = ["-e", "--emergelist"]
  1165. def init(self):
  1166. self.label = _("Emerge-like packages list")
  1167. self.help = _("display the packages list in emerge format")
  1168. class VariableClUpdateKernelVersion(ReadonlyVariable):
  1169. """
  1170. Текущая версия ядра
  1171. """
  1172. def get(self):
  1173. return process('/bin/uname', '-r').read().strip()
  1174. class VariableClUpdateKernelSrcPath(ReadonlyVariable):
  1175. """
  1176. Каталог содержащий исходный код текущего ядра
  1177. """
  1178. def get(self):
  1179. kernel_ver = self.Get('cl_update_kernel_version')
  1180. for template_path in ("/lib/modules/%s/build",
  1181. "/usr/src/linux-%s"):
  1182. src_path = template_path % kernel_ver
  1183. if path.exists(src_path):
  1184. if path.islink(src_path):
  1185. return os.readlink(src_path)
  1186. else:
  1187. return src_path
  1188. else:
  1189. return ""
  1190. class VariableClUpdateKernelPkg(ReadonlyVariable):
  1191. """
  1192. Пакет текущего ядра
  1193. """
  1194. def get(self):
  1195. src_path = self.Get('cl_update_kernel_src_path')
  1196. if src_path:
  1197. qfile = process('/usr/bin/qfile', '-vC', src_path)
  1198. if qfile.success():
  1199. return qfile.read().partition(" ")[0]
  1200. return ""
  1201. class VariableClUpdateLinesLimit(Variable):
  1202. """
  1203. Количество выводимых строк при ошибке
  1204. """
  1205. type = "int"
  1206. value = "30"
  1207. class VariableClUpdateSkipSetupSet(Variable):
  1208. """
  1209. Пропустить выполнение cl-setup-system в cl-update-profile
  1210. """
  1211. type = "bool"
  1212. value = "off"
  1213. opt = ["--skip-setup-system"]
  1214. def init(self):
  1215. self.label = _("Skip the system setup")
  1216. self.help = _("skip the system setup")
  1217. class VariableClUpdateCleanpkgSet(Variable):
  1218. """
  1219. Пропустить выполнение cl-setup-system в cl-update-profile
  1220. """
  1221. type = "bool"
  1222. value = "off"
  1223. opt = ["--clean-pkg"]
  1224. def init(self):
  1225. self.label = _("Clean obsolete programs archives")
  1226. self.help = _("clean obsolete programs archives")
  1227. class VariableClUpdateOutdatedKernelPath(Variable):
  1228. """
  1229. Файл-флаг наличия устаревшего, неудаленного ядра
  1230. """
  1231. value = "/var/lib/calculate/calculate-update/outdated_kernel"
  1232. class VariableClUpdateSkipRbSet(Variable):
  1233. """
  1234. Пропусить revdep-rebuild
  1235. """
  1236. type = "bool"
  1237. value = "off"
  1238. opt = ["-R", "--skip-revdep-rebuild"]
  1239. def init(self):
  1240. self.label = _("Skip reverse dependencies check")
  1241. self.help = _("skip reverse dependencies check")
  1242. class VariableClUpdateOutdatedKernelSet(ReadonlyVariable):
  1243. """
  1244. Есть наличие устаревшего ядра
  1245. """
  1246. type = "bool"
  1247. def get(self):
  1248. ui = UpdateInfo(self.parent)
  1249. return "on" if ui.outdated_kernel else "off"
  1250. class VariableClUpdateBinhostList(Variable):
  1251. """
  1252. Список хостов с бинарными обновлениями
  1253. """
  1254. type = "list"
  1255. value = ["ftp://ftp.calculate-linux.ru/calculate"]
  1256. class VariableClUpdateBinhostUnstableList(Variable):
  1257. """
  1258. Список хостов с бинарными обновлениями
  1259. """
  1260. type = "list"
  1261. value = ["ftp://ftp.calculate-linux.ru/testing"]
  1262. class VariableClUpdateBinhostStableSet(Variable):
  1263. """
  1264. Удлять лишние файлы из репозиториев (например созданные пользователем)
  1265. """
  1266. type = "bool"
  1267. value = "on"
  1268. class VariableClUpdateBinhostStableOptSet(Variable):
  1269. """
  1270. Удлять лишние файлы из репозиториев (например созданные пользователем)
  1271. """
  1272. type = "bool"
  1273. value = "on"
  1274. opt = ["--stable"]
  1275. def init(self):
  1276. self.label = _("Use only stable updates")
  1277. self.help = _("use only stable updates")
  1278. def get(self):
  1279. return self.Get('cl_update_binhost_stable_set')
  1280. class VariableClUpdateBinhost(Variable):
  1281. """
  1282. Хост с бинарными обновлениями
  1283. """
  1284. value = ""
  1285. class VariableClUpdateBinhostRevisionPath(Variable):
  1286. """
  1287. Путь до revisions файлов
  1288. """
  1289. type = "list"
  1290. value = [
  1291. "grp/ini.env"
  1292. ]
  1293. class VariableClUpdateBinhostTimestampPath(Variable):
  1294. """
  1295. Путь до файла timestamp
  1296. """
  1297. value = "timestamp"
  1298. class VariableClUpdateBinhostTimeout(Variable):
  1299. """
  1300. Таймаут на проверку одного binhost
  1301. """
  1302. type = "int"
  1303. value = "5"
  1304. class VariableClUpdateCheckRepSet(Variable):
  1305. """
  1306. Удлять лишние файлы из репозиториев (например созданные пользователем)
  1307. """
  1308. type = "bool"
  1309. value = "off"
  1310. opt = ["--check-repos", "-C"]
  1311. def init(self):
  1312. self.label = _("Check the repositories integrity")
  1313. self.help = _("check and fix the repositories integrity")
  1314. class VariableClUpdateForceFixSet(Variable):
  1315. """
  1316. Удлять лишние файлы из репозиториев (например созданные пользователем)
  1317. """
  1318. type = "bool"
  1319. value = "off"
  1320. opt = ["--force-fix"]
  1321. def init(self):
  1322. self.label = _("Force fix the settings")
  1323. self.help = _("force fix the settings")
  1324. class VariableClUpdateOnedepthSet(Variable):
  1325. """
  1326. Удлять лишние файлы из репозиториев (например созданные пользователем)
  1327. """
  1328. type = "bool"
  1329. value = "off"
  1330. opt = ["--one-depth", "-1"]
  1331. def init(self):
  1332. self.label = _("Clear the history of repositories")
  1333. self.help = _("clear the history of repositories")
  1334. class VariableClUpdateEixRepositories(ReadonlyVariable):
  1335. """
  1336. Отображаемый список обновляемых репозиториев eix
  1337. """
  1338. def get(self):
  1339. return ", ".join(
  1340. x.capitalize() for x in reversed(list(chain(
  1341. self.Get('update.cl_update_rep_name'),
  1342. self.Get('update.cl_update_other_rep_name')))))
  1343. class VariableClUpdatePortageBinhost(ReadonlyVariable):
  1344. """
  1345. Прописываемый в /etc/portage/make.conf/binhost репозиторий
  1346. """
  1347. value_format = "{update.cl_update_binhost}/grp/{os_arch_machine}"
  1348. class VariableClUpdatePackageCache(ReadonlyVariable):
  1349. """
  1350. Путь кэшированного Packages
  1351. """
  1352. def get(self):
  1353. cache_path = "var/cache/edb"
  1354. chroot_path = self.Get('cl_chroot_path')
  1355. base_url = self.Get('cl_update_portage_binhost')
  1356. if not base_url:
  1357. return ""
  1358. parsed_url = urlparse(base_url)
  1359. host = parsed_url.netloc
  1360. port = parsed_url.port
  1361. user = None
  1362. passwd = None
  1363. user_passwd = ""
  1364. if "@" in host:
  1365. user, host = host.split("@", 1)
  1366. user_passwd = user + "@"
  1367. if ":" in user:
  1368. user, passwd = user.split(":", 1)
  1369. if port is not None:
  1370. port_str = ":%s" % (port,)
  1371. if host.endswith(port_str):
  1372. host = host[:-len(port_str)]
  1373. return os.path.join(chroot_path, cache_path, "binhost",
  1374. host, parsed_url.path.lstrip("/"),
  1375. "Packages")
  1376. class VariableClUpdatePackageCacheSet(Variable):
  1377. """
  1378. Необходимость обновить Packages
  1379. """
  1380. type = "bool"
  1381. def get(self):
  1382. packages_fn = self.Get('cl_update_package_cache')
  1383. if not path.exists(packages_fn):
  1384. return "on"
  1385. pi = PackagesIndex(readFile(packages_fn))
  1386. try:
  1387. ttl = int(pi.get("TTL", "0"))
  1388. if ttl > HOURS:
  1389. return "off"
  1390. except ValueError:
  1391. return "on"
  1392. return "on"
  1393. class VariableClUpdateWithBdepsSet(Variable):
  1394. """
  1395. Добавление --with-bdeps при вызове emerge
  1396. """
  1397. type = "bool"
  1398. value = "off"
  1399. class VariableClUpdateWithBdepsOptSet(Variable):
  1400. """
  1401. Добавление --with-bdeps при вызове emerge (опция)
  1402. """
  1403. type = "bool"
  1404. opt = ["--with-bdeps"]
  1405. def init(self):
  1406. self.help = _("save packages used during build")
  1407. self.label = _("Save packages used during build")
  1408. def get(self):
  1409. return self.Get('cl_update_with_bdeps_set')
  1410. class VariableClUpdateForceDepcleanSet(Variable):
  1411. """
  1412. Принудительный вызов depclean
  1413. """
  1414. type = "bool"
  1415. value = "off"