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.
125 lines
3.8 KiB
125 lines
3.8 KiB
#!/usr/bin/python
|
|
#-*- coding: utf-8 -*-
|
|
|
|
# Copyright 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.
|
|
|
|
from calculate.api.client.function import get_sid
|
|
from PySide import QtGui
|
|
from ReturnMessage import ReturnedMessage
|
|
|
|
#class ret_mes():
|
|
# def __init__ (self, pid):
|
|
# self.type = "pid"
|
|
# self.message = pid
|
|
|
|
def show_msg(text, title = None):
|
|
msgBox = QtGui.QMessageBox()
|
|
if title:
|
|
msgBox.setWindowTitle(title)
|
|
msgBox.setText(text)
|
|
msgBox.setStandardButtons(QtGui.QMessageBox.Ok)
|
|
msgBox.exec_()
|
|
|
|
client_types = "gui"
|
|
|
|
|
|
def client_list_methods(client):
|
|
""" get & show all available methods for this certificate """
|
|
DAT = 0 # Access to data soap structure
|
|
RES = 0 # Access to result
|
|
COM = 0 # Getting command group
|
|
# METH = 1 # Getting method line
|
|
|
|
results = client.service.get_methods(client_types)
|
|
if not results:
|
|
# print _('no methods available')
|
|
return 1
|
|
try:
|
|
if results[DAT][RES][RES][COM] == '0':
|
|
# print _('no methods available')
|
|
return 1
|
|
except:
|
|
pass
|
|
# print _("\nYou can execute:")
|
|
|
|
return results[DAT]
|
|
|
|
def client_list_pid(client):
|
|
""" get all process id for this session """
|
|
sid = get_sid(client.SID_FILE)
|
|
try:
|
|
list_pid = client.service.list_pid(sid = sid)
|
|
if list_pid[0][0] == 0:
|
|
return []
|
|
else:
|
|
return list_pid[0]
|
|
except:
|
|
print "Error get list pid from server"
|
|
return []
|
|
|
|
|
|
def gen_pid_ls(client, pid_ls):
|
|
""" generation list with pid for this session """
|
|
sid = get_sid(client.SID_FILE)
|
|
|
|
try:
|
|
list_pid = client.service.list_pid(sid = sid)
|
|
if list_pid[0][0] == 0:
|
|
# print _("Not found pid for this session!")
|
|
return 0
|
|
else:
|
|
for i in list_pid[0]:
|
|
pid_ls.append(i)
|
|
except:
|
|
# print _("Server get pids error")
|
|
return 0
|
|
return pid_ls
|
|
|
|
def pid_inf(ClientObj, client, sid, pids):
|
|
""" get and show information about process """
|
|
for pid in pids:
|
|
s = client.service.pid_info(sid, pid)
|
|
if s == "":
|
|
show_msg ("PID not found")
|
|
return 1
|
|
if s[0][0] == "Permission denied":
|
|
show_msg ("Permission denied")
|
|
return 1
|
|
pid_str = str(pid)
|
|
ClientObj.process_dict[pid_str] = {}
|
|
ClientObj.process_dict[pid_str]['name'] = str(s[0][3])
|
|
ClientObj.process_dict[pid_str]['result'] = \
|
|
ReturnedMessage("pid", None, pid_str)
|
|
ClientObj.process_dict[pid_str]['layout'] = QtGui.QVBoxLayout()
|
|
# meth_res = ret_mes(str(pid))
|
|
# ClientObj.process_dict[pid]['result'] = meth_res
|
|
|
|
def client_pid_info(ClientObj, client, pid):
|
|
""" get information about selected process (or about all) """
|
|
pid = int (pid)
|
|
# try:
|
|
pid_ls = []
|
|
pid_get = []
|
|
pid_get.append(pid)
|
|
sid = get_sid(client.SID_FILE)
|
|
if pid > 0:
|
|
pid_inf(ClientObj, client, sid, pid_get)
|
|
elif pid == 0:
|
|
if gen_pid_ls(client, pid_ls):
|
|
pid_inf(ClientObj, client, sid, pid_ls)
|
|
# except:
|
|
# show_msg("Error get process information")
|
|
# return 1
|
|
return 0 |