Подготовка команды для обновления flash

Mike Khiretskiy 9 years ago
parent 3c428920b4
commit ce5ff4aa36

@ -62,6 +62,7 @@ class Builder(Update):
Restore = "builder_restore"
Image = "builder_image"
Profile = "builder_profile"
UpdateMenu = "builder_menu"
All = (Prepare, Break, Update, Restore, Image, Profile)
def init(self):
@ -1008,7 +1009,7 @@ class Builder(Update):
raise BuilderError(_("Failed to remount Flash drive"))
p = process('/bin/mount', '-o', 'remount,rw', dn, stderr=STDOUT)
if p.failed():
self.printERROR(p.read())
self.printERROR(p.read().strip())
return False
return True

@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
# Copyright 2015 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 sys
from calculate.core.server.func import Action, Tasks
from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate
from calculate.lib.utils.files import FilesError
from calculate.update.emerge_parser import EmergeError
from calculate.update.update import UpdateError
from ..datavars import BuilderError
from calculate.lib.utils.portage import GitError
from calculate.install.distr import DistributiveError, IsoDistributive
from calculate.builder.variables.action import Actions
setLocalTranslate('cl_builder3', sys.modules[__name__])
__ = getLazyLocalTranslate(_)
class ClBuilderMenuAction(Action):
"""
Действие обновление конфигурационных файлов
"""
# ошибки, которые отображаются без подробностей
native_error = (DistributiveError, FilesError, UpdateError,
BuilderError, GitError, EmergeError)
successMessage =__("Boot menu updated successfully")
failedMessage = __("Failed to update boot menu")
interruptMessage = __("Boot menu updating manually interrupted")
# список задач для действия
tasks = [
{'name': 'mount_flash',
'method': 'Builder.remount_rw(cl_builder_flash_path)',
},
{'name': 'protect_off',
'method': 'Builder.setVariable("cl_protect_use_set","off",True)'
},
{'name': 'image_menu',
'method': 'Builder.set_builder_action("%s")' % Actions.ImageMenu,
},
{'name': 'image_menu:sync_vmlinuz',
'message': __("Extracting kernels from ISO images"),
'method': 'Builder.sync_vmlinuz(cl_builder_flash_path)'
},
{'name': 'image_menu:update_menu',
'message': __("Recreating ISO image menu"),
'method': 'Builder.update_menu(cl_builder_flash_path)',
},
]

@ -18,6 +18,7 @@ import sys
from os import path
import os
import re
from calculate.install.distr import DistributiveError, IsoDistributive
from calculate.install.variables.kernel import KernelConfig
from calculate.lib.utils.dracut import Dracut
from calculate.lib.utils.portage import getSquashList
@ -1235,10 +1236,20 @@ class VariableClBuilderFlashRepository(ReadonlyVariable):
def get(self):
return path.join(self.Get('cl_builder_flash_path'), "iso")
class VariableClBuilderFlashPath(ReadonlyVariable):
class VariableClBuilderFlashDevPath(Variable):
"""
Путь, куда подключена flash (загрузка либо с флешки, либо с iso)
Путь до устройства flash
"""
opt = ["-d", "--disk"]
metavalue = "FLASH"
type = "choiceedit"
def init(self):
self.label = _("Flash drive")
self.help = _("set Flash drive")
untrusted = True
def get(self):
root_type_ext = self.Get('os_root_type_ext')
if root_type_ext == RootType.LiveFlash:
@ -1247,6 +1258,58 @@ class VariableClBuilderFlashPath(ReadonlyVariable):
return Dracut.IsoScanPath
return ""
def choice(self):
root_type_ext = self.Get('os_root_type_ext')
if root_type_ext == RootType.LiveFlash:
choices = [(Dracut.IsoLive, _("Boot Flash"))]
elif root_type_ext == RootType.IsoScan:
choices = [(Dracut.IsoScanPath, _("Boot Flash"))]
else:
choices = []
return choices + \
[(x,x) for x in self.select('install.os_disk_dev',
install_os_disk_format="vfat")]
def check(self, value):
if not value:
raise VariableError(_("Please specify Flash drive"))
if not path.exists(value):
raise VariableError(_("Flash drive %s not found")%value)
try:
image = IsoDistributive(value)
image.getIsoContentDirectory()
image.close()
except DistributiveError as e:
raise VariableError(str(e).strip())
class VariableClBuilderFlashDev(ReadonlyVariable):
"""
Устройство flash
"""
object = ""
def get(self):
try:
iso_path = self.Get('cl_builder_flash_dev_path')
if iso_path:
return IsoDistributive(iso_path)
except DistributiveError:
return ""
return ""
class VariableClBuilderFlashPath(ReadonlyVariable):
"""
Путь, куда подключена flash (загрузка либо с флешки, либо с iso)
"""
def get(self):
try:
iso = self.Get('cl_builder_flash_dev')
if iso:
return iso.getIsoContentDirectory()
except DistributiveError:
return ""
return ""
class VariableClBuilderFlashUuid(ReadonlyVariable):
"""
UUID flash, используется для перестроения меню

@ -16,13 +16,13 @@
import sys
from calculate.lib.datavars import VariableError, DataVarsError, DataVars
from calculate.lib.datavars import VariableError, DataVarsError
from calculate.core.server.func import WsdlBase
from calculate.install.install import InstallError, Install
from calculate.update.emerge_parser import EmergeError
from .builder import Builder
from calculate.update.update import Update, UpdateError
from calculate.update.update import UpdateError
from .datavars import BuilderError
from .variables.action import Actions as BuilderActions
from calculate.lib.utils.portage import GitError
@ -32,6 +32,7 @@ from utils.cl_builder_break import ClBuilderBreakAction
from utils.cl_builder_update import ClBuilderUpdateAction
from utils.cl_builder_restore import ClBuilderRestoreAction
from utils.cl_builder_image import ClBuilderImageAction
from utils.cl_builder_menu import ClBuilderMenuAction
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
setLocalTranslate('cl_builder3',sys.modules[__name__])
__ = getLazyLocalTranslate(_)
@ -193,6 +194,38 @@ class Wsdl(WsdlBase):
'brief': {'next': __("Perform"),
'name': __("Update the Build")}
},
{
# идентификатор метода
'method_name': Builder.Method.UpdateMenu,
# категория метода
'category': __('Builder'),
# заголовок метода
'title': __("Update Boot Menu"),
# иконка для графической консоли
'image': 'format-indent-less-rtl,format-indent-more',
# метод присутствует в графической консоли
'gui': True,
# консольная команда
'command': 'cl-builder-menu',
# права для запуска метода
'rights': ['build'],
# объект содержащий модули для действия
'logic': {'Builder': Builder,
'Install': Install},
# описание действия
'action': ClBuilderMenuAction,
# объект переменных
'datavars': "builder",
'native_error': (VariableError, DataVarsError,
InstallError, BuilderError, GitError),
# значения по умолчанию для переменных этого метода
'setvars': {'cl_action!': BuilderActions.Image},
# описание груп (список лямбда функций)
'groups': [
lambda group: group(_("Update Boot Menu"),
normal=('cl_builder_flash_dev_path',),
next_label=_("Perform"))],
},
{
# идентификатор метода
'method_name': Builder.Method.Restore,

Loading…
Cancel
Save