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-core/core/server/test2.py

481 lines
20 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 2010-2012 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 soaplib, sys, time, os
from soaplib.serializers.primitive import String, Integer, Any, Boolean
from soaplib.serializers.clazz import Array, ClassSerializer
from soaplib.service import rpc, DefinitionBase
from calculate.core.server.api_types import ReturnedMessage
from calculate.core.server.api_types import (ChoiceValue, Table, Option, Field,
GroupField, ViewInfo)
from calculate.lib.datavars import VariableError, DataVarsError
from calculate.install.cl_install import DataVarsInstall
from calculate.core.server.baseClass import Basic
class SH2 (ClassSerializer):
#name = String
#times = Integer
#boolvariable = Boolean
#boolvariable2 = Boolean
#radiovariable = String
#radiovariable2 = String
#combovariable = String
#comboEdit1 = String
#comboEdit2 = String
#multichoice_add = String
#multichoice = String
os_location_data = Array(Array(String))
os_install_mbr = Array(String)
os_install_locale_lang = String
r = String
#compliance = {'disk' : 'os_location_data', \
#'mbr' : 'os_install_mbr', \
#'lang' : 'os_install_locale_lang'}
# for check parameters without call method
CheckOnly = Boolean
#class ExampleInfo (ClassSerializer):
#disk = Array(Array(String))
#mbr = String
#lang = String
#CheckOnly = Boolean
class ApiWsdl:
def test2_meth (self, name, times, town) :
print 'name = ', name, 'times = ', times, 'town = ',town
try:
results = []
self.writeFile()
for i in range( 0, times ) :
results.append('Hello!!!, %s %d'%(name, i))
# Помещение данных в словарь процессов
self.briefParams('say_hello_view')
self.setData (results)
self.startTask("NewTask", True)
self.addMessage(type = 'warning', message = 'enter name!')
# Учёт процесса выполнения
perc = 0
while self.getProgress() < 100:
time.sleep(0.2)
perc += 20
# Увеличение процента выполнения процесса
self.setProgress (perc)
#question = self.askQuestion('enter name: ', None)
#print question
#print self.askPassword ('Please, your enter pass: ')
self.endTask("Message with result work task 1!")
#if not question in [None, "", []]:
#head = [' ', question, 'two', question]
#else:
head = [town,'One','Two','Three','Four']
body = [['One','11','12','13','14'],['Two','21','22','23','24'],\
['Three','31','32','33','34'], ['Four','41','42','43','44']]
self.printTable("Table 1!", head, body)
self.startTask("Second task!", True)
perc = 0
while self.getProgress() < 50:
time.sleep(0.3)
perc += 10
# Увеличение процента выполнения процесса
self.setProgress (perc)
self.printERROR ('you not entered country!')
self.endTask("Message about error task 2!")
self.endFrame()
# necessary for correct complete the process
return True
# Обработка сигнала прерывания работы процесса
except KeyboardInterrupt:
# Необходимо передать Fasle для сохранения данных о процессе
return False
except:
return False
def check_params (self, dv, info):
errors = []
for var in filter(lambda x:x.lower() == x,
info._type_info.keys()):
if info.__getattribute__(var) != None:
try:
dv.Set(var, info.__getattribute__(var))
except VariableError, e:
mess = ''
messages = e.message if type(e.message) == list else [e.message]
for error in messages:
mess += str(error) + '\n'
errors.append(ReturnedMessage(type = 'error', field = var,
message = mess))
return errors
#dv.Set('os_location_data',rrr.disk)
from calculate.core.server.baseClass import Basic
from calculate.core.server.decorators import Dec
@rpc(Integer, SH2, _returns = Array(ReturnedMessage))
@Dec.check_permissions(["test2"])
@Dec.console('cl-test2')
@Dec.gui('Core.Test', 'test2 install', \
'voicecall,system-software-install,system-log-out')
def test2 ( self, sid, rrr):
import threading
curThread = threading.currentThread()
print curThread.lang
curThread.lang = self.get_lang(sid)
name_meth = 'test2'
dv = DataVarsInstall()
dv.importInstall()
#print '++++++++++',rrr.compliance
#print rrr.disk
#print rrr.r
errors = self.check_params(dv, rrr)
if errors:
#print "$$$$$$$$$$$$$$", errors
return errors
#if rrr.mbr:
#dv.Set('os_location_data',rrr.disk)
#dv.Set('os_install_mbr',rrr.mbr)
#else:
#dv.Set('os_install_locale_lang',rrr.lang)
self.set_cache(sid, name_meth, 'dv', dv)
#if rrr.name == 'qqq':
#errors = []
#errors.append(ReturnedMessage(type = 'error', field = 'name', \
#message = 'Do not input "qqq"!'))
#errors.append(ReturnedMessage(type = 'error', field = 'boolvariable', \
#message = 'Choose this!'))
#return errors
if rrr.CheckOnly:
returnmess = ReturnedMessage(type = '', message = None)
return [returnmess]
sh = self.get_cache(sid, name_meth, 'dv')
#if sh == None:
#sh = SH2()
##sh.name = name
#times = sh.times
#name = sh.name
#sh.iii = 4
#town = sh.combovariable
#print "------->>>", name, times, town
#self.set_cache(sid, name_meth, sh)
test2_meth = type("CommonInstall",(self.Common, ApiWsdl, object), {})
name = sh.name
pid = self.startprocess(sid, target=test2_meth, method="test2_meth",\
method_name = 'test2', \
args_proc = (name[0], times, town))
returnmess = ReturnedMessage(type = 'pid', message = pid)
#returnmess.type = "pid"
#returnmess.message = pid
return [returnmess]
@rpc(Integer, Integer, Boolean, _returns = ViewInfo)
def test2_view (self, sid, step, expert = False):
#print "+++++++++++++++++++", step
##if step == 0:
##view = ViewInfo(groups=[])
##group = GroupField(name=_("TEST2_METHOD"),nextlabel=_("Next"),last=False)
##group.fields = []
#import threading
#curThread = threading.currentThread()
#print curThread.lang
#curThread.lang = self.get_lang(sid)
#print curThread.lang
##from func import get_lang
#print 'LANG = ',self.get_lang(sid)
dv = DataVarsInstall()
dv.importInstall()
view = ViewInfo(dv, [(_("First group"), \
('os_location_data', 'os_install_mbr'), (),\
_("Next")), \
(_("Secound group"), \
('os_install_locale_lang', ), (), \
_("Done"))],step)
#self.set_cache(sid, 'test2', dv)
return view
#group.fields.append(Field(
#name = "name",
#label = _("YOUR NAME: "),
#type = "str",
#default = 'Vasya',
#opt = Option(shortopt="-n",
#longopt="--name",
#metavalue="NAME"),
#help = \
#_("Please, enter your name"),
#element = "input"))
#group.fields.append(Field(
#name = "times",
#label = _("TIMES: "),
#type = "int",
#opt = Option(longopt="--times",
#metavalue="TIMES"),
#help = \
#_("Enter times"),
#element = "input"))
#group.fields.append(Field(
#name = "Partition_table",
#label = _("Mount Points: "),
#opt = Option(longopt="--times",
#metavalue="TIMES"),
#element = "table",
## Table
#tablevalue = Table(
#head = ['Partition','Mount Point','Filesystem', \
#'Perform format','Label','Size'],
#body = [['/dev/sda1','swap','swap','off',None,'4G'],\
#['/dev/sda2','/','reiserfs','on','CLD','10G'],\
#['/dev/sda3','/var/calculate','ext4','off',None,'30G']],
#values = [ChoiceValue(
#typefield = 'combo',
#values = ['/dev/sda1','/dev/sda2','/dev/sda3'],
#readonly = False,
#onChanged = ['',None,'get_body','get_body','get_body','get_body']),
#ChoiceValue(
#typefield = 'comboEdit',
#values = ['/','swap','/var/calculate'],
#readonly = False),
#ChoiceValue(
#typefield = 'multichoice_add',
#values = ['swap','reiserfs','ext4'],
#readonly = False),
#ChoiceValue(
#typefield = 'check',
#values = ['on','off'],
#readonly = False),
#ChoiceValue(
#typefield = 'input',
#values = [],
#readonly = True),
#ChoiceValue(
#typefield = 'input',
#values = [],
#readonly = True)]
#)))
#group.fields.append(Field(
#name = "expert",
#label = _("Press for advanced settings..."),
#type = "label",
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#help = \
#_("you not human? This is a anti-bot test"),
#element = "expert"))
#group.fields.append(Field(
#name = "boolvariable",
#label = _("you BOT?"),
#type = "bool",
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#help = \
#_("you not human? This is a anti-bot test"),
#element = "bool"))
#group.fields.append(Field(
#name = "boolvariable2",
#label = _("you BOT?"),
#type = "bool",
#default = 'on',
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#help = \
#_("you not human? This is a anti-bot test"),
#element = "bool"))
#group.fields.append(Field(
#name = "combovariable",
#label = _("check city number: "),
#choice = ['Moscow','Piter','New York','London'],
#type = "str",
#default = 'London',
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#help = \
#_("you not human? This is a anti-bot test"),
#element = "combo"))
#group.fields.append(Field(
#name = "Partition_table2",
#label = _("Mount Points: "),
#opt = Option(longopt="--times",
#metavalue="TIMES"),
#element = "table",
## Table
#tablevalue = Table(
#head = ['Partition','Mount Point','Filesystem', \
#'Perform format','Label','Size'],
#body = [['/dev/sda1','swap','swap','off',None,'4G'],\
#['/dev/sda2','/','reiserfs','on','CLD','10G'],\
#['/dev/sda3','/var/calculate','ext4','off',None,'30G']],
#values = [ChoiceValue(
#typefield = 'combo',
#values = ['/dev/sda1','/dev/sda2','/dev/sda3'],
#readonly = False,
#onChanged = ['',None,'get_body','get_body','get_body','get_body']),
#ChoiceValue(
#typefield = 'comboEdit',
#values = ['/','swap','/var/calculate'],
#readonly = False),
#ChoiceValue(
#typefield = 'multichoice_add',
#values = ['swap','reiserfs','ext4'],
#readonly = False),
#ChoiceValue(
#typefield = 'check',
#values = ['on','off'],
#readonly = False),
#ChoiceValue(
#typefield = 'input',
#values = [],
#readonly = True),
#ChoiceValue(
#typefield = 'input',
#values = [],
#readonly = True)]
#)))
#group.fields.append(Field(
#name = "button_view1",
#label = _("Next Step"),
#value = 'test2_view',
#default = '1',
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#element = "button"))
#view.groups.append(group)
#return view
#elif step == 1:
#view = ViewInfo(groups=[])
#group = GroupField(name=_("TEST2_METHOD"),nextlabel=_("Next"),last=True)
#group.fields = []
#group.fields.append(Field(
#name = "radiovariable",
#label = _("check city: "),
#choice = ['Moscow','Piter','New York','London'],
#type = "str",
##default = 'London',
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#help = \
#_("you not human? This is a anti-bot test"),
#element = "radio"))
#group.fields.append(Field(
#name = "radiovariable2",
#label = _("check village: "),
#choice = ['aaaaaa','bbbb','ccccc','dddddd'],
#type = "str",
##default = 'bbbb',
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#help = \
#_("you not human? This is a anti-bot test"),
#element = "radio"))
#group.fields.append(Field(
#name = "comboEdit1",
#label = _("check city number: "),
#choice = ['Moscow','Piter','New York','London'],
#type = "str",
##default = 'London',
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#help = \
#_("you not human? This is a anti-bot test"),
#element = "comboEdit"))
#group.fields.append(Field(
#name = "comboEdit2",
#label = _("check population: "),
#choice = ['1000','10000','500000','2000000'],
#type = "str",
##default = '2000000',
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#help = \
#_("you not human? This is a anti-bot test"),
#element = "comboEdit"))
#group.fields.append(Field(
#name = "multichoice_add",
#label = _("check population: "),
#choice = ['aa','bb','cc','dd'],
#type = "str",
#default = '22,33',
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#help = \
#_("you not human? This is a anti-bot test"),
#element = "multichoice_add"))
#group.fields.append(Field(
#name = "multichoice",
#label = _("check population: "),
#choice = ['1000','10000','500000','2000000'],
#type = "str",
#default = 'qwe,ert',
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#help = \
#_("you not human? This is a anti-bot test"),
#element = "multichoice"))
#group.fields.append(Field(
#name = "button_view0",
#label = _("previous step"),
#value = 'test2_view',
#default = '0',
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#element = "button"))
#group.fields.append(Field(
#name = "button_call",
#label = _("call method"),
#value = 'test2',
#opt = Option(longopt="--bot",
#metavalue="BOT"),
#element = "button"))
#view.groups.append(group)
#return view