From 15853557c9f7a15fae901f176847d66b7c6edeaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B8=D1=80=D0=B5=D1=86=D0=BA=D0=B8=D0=B9=20=D0=9C?= =?UTF-8?q?=D0=B8=D1=85=D0=B0=D0=B8=D0=BB?= Date: Mon, 10 Jun 2013 17:37:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=20=D0=BD=D0=B0=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?API.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 2 +- update/cl_update.py | 97 ----------------------------------- update/utils/__init__.py | 0 update/utils/cl_update.py | 43 ++++++++++++++++ update/wsdl_update.py | 104 +++++++++++++++++--------------------- 5 files changed, 91 insertions(+), 155 deletions(-) delete mode 100644 update/cl_update.py create mode 100644 update/utils/__init__.py create mode 100644 update/utils/cl_update.py diff --git a/setup.py b/setup.py index 3079c21..50637d0 100755 --- a/setup.py +++ b/setup.py @@ -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']) diff --git a/update/cl_update.py b/update/cl_update.py deleted file mode 100644 index 36197c6..0000000 --- a/update/cl_update.py +++ /dev/null @@ -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()) diff --git a/update/utils/__init__.py b/update/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/update/utils/cl_update.py b/update/utils/cl_update.py new file mode 100644 index 0000000..22a3186 --- /dev/null +++ b/update/utils/cl_update.py @@ -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)', + }] diff --git a/update/wsdl_update.py b/update/wsdl_update.py index eb804a3..017ebd1 100644 --- a/update/wsdl_update.py +++ b/update/wsdl_update.py @@ -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"))]}, + ]