Переписан на новый API.

master3.1.6
parent c5ce02bcc6
commit 15853557c9

@ -31,4 +31,4 @@ setup(
url = "http://calculate-linux.org",
license = "http://www.apache.org/licenses/LICENSE-2.0",
package_dir = {'calculate.update': "update"},
packages = ['calculate.update','calculate.update.variables'])
packages = ['calculate.update','calculate.update.utils','calculate.update.variables'])

@ -1,97 +0,0 @@
#-*- coding: utf-8 -*-
# Copyright 2010 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
from os import path
import re
import sys
import pwd
import time
import traceback
from datavars import DataVarsUpdate, DataVars, __version__,__app__
from calculate.lib.cl_template import Template, ProgressTemplate,TemplatesError
from calculate.lib.utils.files import runOsCommand, isMount
from calculate.lib.utils.common import getpathenv,appendProgramToEnvFile, \
removeProgramToEnvFile
from calculate.core.server.func import safetyWrapper
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
setLocalTranslate('cl_update3',sys.modules[__name__])
__ = getLazyLocalTranslate(_)
class UpdateError(Exception):
"""Update Error"""
class Update:
"""
Update logic object
Has fundamental method update for system update
"""
def __init__(self):
self.homeDir = ""
self.clTempl = None
self.clVars = None
def applyTemplates(self):
"""Apply templates for user"""
if self.clTempl:
self.closeClTemplate()
self.clVars.Set("cl_chroot_path","/", True)
self.clVars.Set("cl_merge_set","on",True)
self.clTempl = ProgressTemplate(self.setProgress,self.clVars,
cltObj=True,cltFilter=True,
printSUCCESS=self.printSUCCESS,
printWARNING=self.printWARNING,
askConfirm=self.askConfirm,
dispatchConf=self.dispatchConf,
printERROR=self.printERROR)
dirsFiles = self.clTempl.applyTemplates()
if self.clTempl.getError():
self.printERROR(self.clTempl.getError().strip())
return False
else:
return dirsFiles
def initVars(self,datavars=None):
"""Primary variables initialization"""
if not datavars:
self.clVars = DataVarsDesktop()
self.clVars.importDesktop()
self.clVars.flIniFile()
else:
self.clVars = datavars
def closeClTemplate(self,*args):
if self.clTempl:
if self.clTempl.cltObj:
self.clTempl.cltObj.closeFiles()
self.clTempl.closeFiles()
self.clTempl = None
@safetyWrapper(native_errors=(TemplatesError,UpdateError),
man_int=__("Update manually interrupted"),
post_action=closeClTemplate,
success_message=__("Update finished!"))
def update(self, datavars=None):
"""
Creating user profile and userdir
"""
self.initVars(datavars)
return bool(self.applyTemplates())

@ -0,0 +1,43 @@
#-*- coding: utf-8 -*-
# Copyright 2010-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 sys
from calculate.core.server.func import Action
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
from calculate.lib.utils.files import FilesError
from calculate.install.install import (MigrationError, TemplatesError,
InstallError)
setLocalTranslate('cl_update3',sys.modules[__name__])
__ = getLazyLocalTranslate(_)
class ClUpdateAction(Action):
"""
Действие обновление конфигурационных файлов
"""
# ошибки, которые отображаются без подробностей
native_error = (FilesError,)
successMessage = __("Update finished!")
failedMessage = __("Failed to update system")
interruptMessage = __("Update manually interrupted")
# список задач для дейсвия
tasks = [
{'name':'dispatch',
'method':'Install.applyTemplates(install.cl_source,cl_template_clt_set,'\
'True,None)',
}]

@ -1,4 +1,6 @@
# Copyright 2012 Calculate Ltd. http://www.calculate-linux.org
#-*- coding: utf-8 -*-
# Copyright 2010-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.
@ -12,65 +14,53 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import soaplib, sys, time, os
import threading
import sys, time, os
from soaplib.serializers.primitive import String, Integer, Any, Boolean
from soaplib.serializers.clazz import Array
from soaplib.service import rpc, DefinitionBase
from calculate.core.server.api_types import ReturnedMessage, CommonInfo
from calculate.core.server.api_types import ChoiceValue, Table, Option, Field, \
GroupField, ViewInfo, ViewParams
from calculate.lib.datavars import VariableError,DataVarsError
from calculate.update.cl_update import UpdateError
from calculate.lib.datavars import VariableError,DataVarsError,DataVars
from cl_update import Update,DataVarsUpdate
import cl_update
from calculate.core.server.func import WsdlBase
from calculate.install.install import InstallError,Install
from utils.cl_update import ClUpdateAction
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
from calculate.core.server.decorators import Dec
from calculate.core.server.func import catchExcept,commonView
core_method = Dec.core_method
setLocalTranslate('cl_update3',sys.modules[__name__])
import traceback
from functools import wraps,WRAPPER_ASSIGNMENTS
setLocalTranslate('cl_core3',sys.modules[__name__])
__ = getLazyLocalTranslate(_)
class UpdateInfo(CommonInfo):
"""Parameters for method install"""
cl_update_rev_set = String
cl_rebuild_world_set = String
updateCatchExcept = catchExcept(VariableError,DataVarsError,
cl_update.UpdateError)
class Wsdl:
"""
cl-update
"""
@rpc(Integer, UpdateInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Update'),title=__('Update world'),
image='software-properties,preferences-desktop',
gui=True,command='cl-update',
rights=['update'])
def update(self, sid, info):
return self.callMethod(sid,info,method_name="update",
logicClass=Update,
method="update")
def update_vars(self,dv=None):
if not dv:
dv = DataVarsUpdate()
dv.importUpdate()
dv.flIniFile()
dv.Set('cl_action','sync',True)
dv.addGroup(None,
normal=('cl_rebuild_world_set','cl_update_rev_set'),
expert=('cl_templates_locate',
'cl_verbose_set','cl_dispatch_conf'),
next_label=_("Update"))
return dv
@rpc(Integer, ViewParams,_returns = ViewInfo)
def update_view (self, sid, params):
return commonView(self,sid,params,"update")
class Wsdl(WsdlBase):
methods = [
#
# Обновить текущую конфигурацию системы (world,ревизия)
#
{
# идентификатор метода
'method_name':"update",
# категория метода
'category':__('Update'),
# заголовок метода
'title':__("Update configuration"),
# иконка для графической консоли
'image':'software-properties,preferences-desktop',
# метод присутствует в графической консоли
'gui':True,
# консольная команда
'command':'cl-update',
# права для запуска метода
'rights':['update'],
# объект содержащий модули для действия
'logic':{'Install':Install},
# описание действия
'action':ClUpdateAction,
# объект переменных
'datavars':"update",
'native_error':(VariableError,DataVarsError,
InstallError),
# значения по умолчанию для переменных этого метода
'setvars':{'cl_action!':'sync'},
# описание груп (список лямбда функций)
'groups':[
lambda group:group(_("Update configuration"),
normal=('cl_rebuild_world_set','cl_update_rev_set'),
expert=('cl_templates_locate',
'cl_verbose_set','cl_dispatch_conf'),
next_label=_("Update"))]},
]

Loading…
Cancel
Save