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.
calculate-utils-3-update/update/variables/update.py

245 lines
7.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#-*- coding: utf-8 -*-
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
import re
from os import path
from calculate.lib.datavars import (Variable,VariableError,ReadonlyVariable,
ReadonlyTableVariable,TableVariable)
from calculate.lib.utils.portage import searchProfile
from calculate.lib.utils.files import readLinesFile, readFile
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_update3',sys.modules[__name__])
class VariableAcUpdateSync(ReadonlyVariable):
"""
Action variable which has value "up" for package install and
install this package
"""
def get(self):
action = self.Get("cl_action")
if action in ("sync",):
if self.Get('cl_update_world'):
return self.Get('cl_update_world')
return ""
class VariableClUpdateWorld(Variable):
def get(self):
if self.Get('cl_rebuild_world_set') == "on":
return "rebuild"
else:
return ""
class VariableClRebuildWorldSet(Variable):
"""
List of action update world, rebuild world,
"""
type = "bool"
opt = ["--rebuild-world"]
untrusted = True
value = "off"
def init(self):
self.help = _("Rebuild world")
self.label = _("Rebuild world")
class VariableClUpdateRevSet(Variable):
"""
List of action update world, rebuild world,
"""
type = "bool"
opt = ["--update-rev"]
untrusted = True
value = "off"
check_after = ["cl_update_sync_rep"]
def init(self):
self.help = _("revision update")
self.label = _("Revision update")
def check(self,value):
if ( value == "off" and self.Get('cl_rebuild_world_set') != 'on' and
not self.Get('cl_update_sync_rep')):
raise VariableError(_("Select at least one update action"))
class VariableClUpdateRep(Variable):
"""
Обновлять репозитории до конкретной ревизии или до последней
"""
type = "choice"
value = "rev"
def choice(self):
return ["last","rev"]
class VariableClUpdateRepData(ReadonlyTableVariable):
"""
Информация о репозиториях
"""
source = ['cl_update_rep_name',
'cl_update_rep_url',
'cl_update_rep_path',
'cl_update_rep_rev',
'cl_update_branch_name']
class VariableClUpdateRepName(Variable):
"""
Список имен используемых репозиториев
"""
type = "list"
value = []
class VariableClUpdateRepUrl(Variable):
"""
Список путей до репозиториев
"""
type = "list"
value = []
class VariableClUpdateSystemProfile(ReadonlyVariable):
"""
Профиль системы (симлинк /etc/make.profile')
"""
def get(self):
try:
return path.normpath(
path.join('/etc',os.readlink('/etc/make.profile')))
except:
raise VariableError(_("Failed to determine system profile"))
class VariableClUpdateLaymanStorage(ReadonlyVariable):
"""
Путь к репозиториям layman
"""
def get(self):
laymanConf = "/etc/layman/layman.cfg"
reStorage = re.compile("^storage\s*:\s*(\S+)")
if path.exists(laymanConf):
for line in readLinesFile(laymanConf):
match = reStorage.search(line)
if match:
return match.group(1)
return "/var/lib/layman"
class VariableClUpdateRepPath(ReadonlyVariable):
"""
Пути до репозиториев
"""
type = "list"
mapPath = {'portage':'/usr/portage'}
def get(self):
repPath = self.Get('cl_update_layman_storage')
def generatePaths(names):
for name in names:
if name in self.mapPath:
yield self.mapPath[name]
else:
yield path.join(repPath,name)
return list(generatePaths(self.Get('cl_update_rep_name')))
class VariableClUpdateRepRev(Variable):
"""
Ревизии до которых необходимо обновить репозитории
"""
type = "list"
def get(self):
if self.Get('cl_update_rep') == 'rev':
revPaths = searchProfile(self.Get('cl_update_system_profile'),
"rev")
if revPaths:
revPath = revPaths[-1]
dictNamesRevs = dict(map(lambda x:x.strip().partition('=')[::2],
readLinesFile(revPath)))
return map(lambda x:dictNamesRevs.get(x,"last"),
self.Get('cl_update_rep_name'))
return ["last"]*len(self.Get('cl_update_rep_name'))
class VariableClUpdateBranch(TableVariable):
"""
Выбор веток репозиториев до которых необходимо обновиться
"""
opt = ["--branch"]
metavalue = 'BRANCHES'
untrusted = True
source = ["cl_update_branch_rep",
"cl_update_branch_name"]
def init(self):
self.help = _("set branches for repository (REPOSITORY:BRANCH)")
self.label = _("Repository branch")
def raiseReadonlyIndexError(self,fieldname="",variablename="",
value=""):
"""
Неизвестный оврелей
"""
raise VariableError(_("Repository %s not found")%value)
class VariableClUpdateBranchRep(ReadonlyVariable):
"""
Список доступных репозиторием
"""
type = "list"
def init(self):
self.label = _("Repository")
def get(self):
return self.Get('cl_update_rep_name')
class VariableClUpdateBranchName(Variable):
"""
Список доступных репозиторием
"""
type = "choiceedit-list"
def init(self):
self.label = _("Branch")
def choice(self):
return ["master","develop","update"]
def get(self):
def generateBranch():
for reppath in self.Get('cl_update_rep_path'):
headPath = path.join(reppath,".git/HEAD")
yield readFile(headPath).rpartition('/')[2].strip() or "master"
return list(generateBranch())
class VariableClUpdateSyncRep(Variable):
"""
Обновляемый репозиторий
"""
type = "choice-list"
element = "selecttable"
opt = ["cl_update_sync_rep"]
metavalue = "REPOSITORIES"
untrusted = True
def init(self):
self.help = _("synchronize repositories (all by default)")
self.label = _("Synchronize repositories")
def get(self):
return self.Get('cl_update_rep_name')
def choice(self):
return self.Get('cl_update_rep_name')