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/cl_template.py

120 lines
4.5 KiB

#-*- 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
import subprocess
import re
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.core.server.baseClass import Basic
class ClTemplate (ClassSerializer):
args = String
class ApiWsdl:
def cl_template_meth (self, args) :
try:
# create list for subprocess.Popen
a = ['cl-template']+args.split()
reg = re.compile("\x1b\[[0-9]{1}[;]?[\d]{0,3}m")
try:
p = subprocess.Popen(a, stdout = subprocess.PIPE, \
stderr = subprocess.PIPE)
# if stdout read one line at
for line in p.stdout.readlines():
escape_list = reg.findall(line)
for i in escape_list:
line = line.replace(i,'')
# delete escape characters (can not be transferred to xml)
#line = line.replace('\x1b[1;33m','')
#line = line.replace('\x1b[0m','')
#line = line.replace('\x1b[1;31m','')
self.addMessage(type = 'normal', message = line)
# if stderr read all
line = p.stderr.read()
if line != '':
escape_list = reg.findall(line)
for i in escape_list:
line = line.replace(i,'')
# delete escape characters (can not be transferred to xml)
#line = line.replace('\x1b[1;33m','')
#line = line.replace('\x1b[0m','')
#line = line.replace('\x1b[1;31m','')
self.printERROR(line)
except Exception, e:
self.printERROR (e)
sys.exit()
return True
# Signal processing interruption of the process
except KeyboardInterrupt:
# You need to pass Fasle for save data on process
return False
# other exceptions
except Exception, e:
print e
self.printERROR (e)
return False
from calculate.core.server.baseClass import Basic
from calculate.core.server.decorators import Dec
@rpc(Integer, ClTemplate, _returns = Array(ReturnedMessage))
@Dec.check_permissions(['cl_template'])
@Dec.console('cl-template')
@Dec.gui(_('Utilities'),'Overlay Templates', 'tab-duplicate,edit-copy')
def cl_template ( self, sid, cltemplate):
cl_template_meth = type("CommonInstall",
(self.Common, ApiWsdl, object), {})
try:
args = cltemplate.args
except:
args = ''
pid = self.startprocess(sid, target=cl_template_meth, \
method_name='cl_template', \
method="cl_template_meth", args_proc = (args, ))
# must be returned to the client process PID
returnmess = ReturnedMessage(type = 'pid', message = pid)
return [returnmess]
@rpc( _returns = ViewInfo)
def cl_template_view (self):
view = ViewInfo(groups=[])
group = GroupField(name=_("cl-template"),nextlabel=_("Next"),last=True)
group.fields = []
group.fields.append(Field(
name = "args",
label = _("arguments: "),
type = "str",
help = \
_("Please, enter cl-template arguments"),
element = "input"))
view.groups.append(group)
return view