Using new datavars, using ViewParams 'onlyhelp'.

Using printTable from calculate-lib
develop
parent 06ef87a5a0
commit 266c3f3a56

@ -241,12 +241,12 @@ def client_get_cert(cert_path, args):
clVars = DataVarsCore()
clVars.importCore()
clVars.flIniFile()
system_ca_db = clVars.Get('cl_glob_root_cert')
system_ca_db = clVars.Get('core.cl_glob_root_cert')
if os.path.exists(system_ca_db):
if ca_root in open(system_ca_db, 'r').read():
return 0
cl_client_cert_dir = clVars.Get('cl_client_cert_dir')
cl_client_cert_dir = clVars.Get('core.cl_client_cert_dir')
homePath = clVars.Get('ur_home_path')
cl_client_cert_dir = cl_client_cert_dir.replace("~",homePath)
@ -292,7 +292,7 @@ def client_get_cert(cert_path, args):
fd.close()
user_root_cert = clVars.Get('cl_user_root_cert')
user_root_cert = clVars.Get('core.cl_user_root_cert')
user_root_cert = user_root_cert.replace("~",homePath)
fa = open(user_root_cert, 'a')
fa.write(ca_root)
@ -520,4 +520,4 @@ def get_password_from_daemon(server_host, server_port, wait_thread):
# else:
# password = resp if resp else None
# return password
######################### End get password
######################### End get password

@ -109,11 +109,11 @@ def get_CRL(path_to_cert):
clVars.importCore()
clVars.flIniFile()
# user and system ca and root certificates
user_root_cert = clVars.Get('cl_user_root_cert')
user_root_cert = clVars.Get('core.cl_user_root_cert')
homePath = clVars.Get('ur_home_path')
user_root_cert = user_root_cert.replace("~",homePath)
glob_root_cert = clVars.Get('cl_glob_root_cert')
glob_root_cert = clVars.Get('core.cl_glob_root_cert')
if os.path.exists(user_root_cert):
user_ca_certs = open(user_root_cert, 'r').read()
@ -216,18 +216,18 @@ def rm_ca_from_trusted(ca_cert):
clVars.importCore()
clVars.flIniFile()
user_ca_dir = clVars.Get('cl_client_cert_dir')
user_ca_dir = clVars.Get('core.cl_client_cert_dir')
homePath = clVars.Get('ur_home_path')
user_ca_dir = user_ca_dir.replace("~",homePath)
user_ca_dir = os.path.join(user_ca_dir, 'ca')
user_ca_list = os.path.join(user_ca_dir, 'cert_list')
user_ca_db = clVars.Get('cl_user_root_cert')
user_ca_db = clVars.Get('core.cl_user_root_cert')
homePath = clVars.Get('ur_home_path')
user_ca_db = user_ca_db.replace("~",homePath)
system_ca_dir = clVars.Get('cl_core_cert_path')
system_ca_dir = clVars.Get('core.cl_core_cert_path')
system_ca_list = os.path.join(system_ca_dir, 'cert_list')
system_ca_db = clVars.Get('cl_glob_root_cert')
system_ca_db = clVars.Get('core.cl_glob_root_cert')
import hashlib
md5 = hashlib.md5()

@ -43,7 +43,7 @@ def client_signal(client):
Vars.importCore()
Vars.flIniFile()
try:
client_active = Vars.Get('cl_core_client_active_period')
client_active = Vars.Get('core.cl_core_client_active_period')
except:
client_active = 15
while True:
@ -253,7 +253,8 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread):
elif args.method and args.help:
view_params = get_view_params(client, args.method + '_view',
step = None, expert = True)
step = None, expert = True,
onlyhelp = True)
view = get_view(client, args.method, client.sid, view_params)
wait_thread.stop()
sys.stdout.write("\b")
@ -264,7 +265,7 @@ def https_server(client, args, unknown_args, url, clVarsCore, wait_thread):
else:
try:
client.frame_period = clVarsCore.Get('cl_core_get_frame_period')
client.frame_period = clVarsCore.Get('core.cl_core_get_frame_period')
except:
client.frame_period = 2
method_result = call_method(client, args, wait_thread)
@ -343,7 +344,7 @@ def main(wait_thread):
host = args.host
path_to_cert = args.path_to_cert
if not path_to_cert:
path_to_cert = clVarsCore.Get('cl_client_cert_dir')
path_to_cert = clVarsCore.Get('core.cl_client_cert_dir')
path_to_cert = path_to_cert.replace("~",homePath)
for dirs in ['', 'ca', 'trusted']:

@ -114,16 +114,16 @@ class CheckingClientHTTPSConnection(CheckingHTTPSConnection):
clVarsCore.flIniFile()
list_ca_certs.reverse()
system_ca_db = clVarsCore.Get('cl_glob_root_cert')
system_ca_db = clVarsCore.Get('core.cl_glob_root_cert')
clVars = DataVars()
clVars.flIniFile()
homePath = clVars.Get('ur_home_path')
cl_client_cert_dir = clVarsCore.Get('cl_client_cert_dir')
cl_client_cert_dir = clVarsCore.Get('core.cl_client_cert_dir')
cl_client_cert_dir = cl_client_cert_dir.replace("~",homePath)
root_cert_md5 = os.path.join(cl_client_cert_dir, "ca/cert_list")
user_root_cert = clVarsCore.Get('cl_user_root_cert')
user_root_cert = clVarsCore.Get('core.cl_user_root_cert')
user_root_cert = user_root_cert.replace("~",homePath)
for cert in list_ca_certs:
@ -275,7 +275,7 @@ class CheckingClientHTTPSConnection(CheckingHTTPSConnection):
clVars = DataVarsCore()
clVars.importCore()
clVars.flIniFile()
cl_client_cert_dir = clVars.Get('cl_client_cert_dir')
cl_client_cert_dir = clVars.Get('core.cl_client_cert_dir')
homePath = clVars.Get('ur_home_path')
cl_client_cert_dir = cl_client_cert_dir.replace("~",homePath)
root_cert_dir = os.path.join(cl_client_cert_dir, "ca")
@ -379,7 +379,7 @@ class CheckingClientHTTPSConnection(CheckingHTTPSConnection):
self.Vars = DataVarsConsole()
self.Vars.importConsole()
self.Vars.flIniFile()
user_root_cert = self.Vars.Get('cl_user_root_cert')
user_root_cert = self.Vars.Get('core.cl_user_root_cert')
homePath = self.Vars.Get('ur_home_path')
user_root_cert = user_root_cert.replace("~",homePath)
result_user_root = 1
@ -389,7 +389,7 @@ class CheckingClientHTTPSConnection(CheckingHTTPSConnection):
result_user_root = self.connect_trusted_root(sock, \
user_root_cert, self.CRL_PATH)
if result_user_root == 1:
glob_root_cert = self.Vars.Get('cl_glob_root_cert')
glob_root_cert = self.Vars.Get('core.cl_glob_root_cert')
result_root_con = 1
if os.path.exists(glob_root_cert):
sock = socket.create_connection((self.host, self.port),
@ -503,4 +503,4 @@ class HTTPSClientCertTransport(HttpTransport):
self.urlopener.add_handler(proxy_handler)
if proxy_auth_handler:
self.urlopener.add_handler(proxy_auth_handler)
self.urlopener.addheaders = [('User-agent', self.user_agent_string)]
self.urlopener.addheaders = [('User-agent', self.user_agent_string)]

@ -23,6 +23,7 @@ from OpenSSL import crypto
import shlex
from sudsds import MethodNotFound
from calculate.core.server.cert_cmd import getHwAddr, getIpLocal
from calculate.core.server.replace_class import printTable
from calculate.core.client.progressbar import Bar,Percentage,ETA,ProgressBar
from calculate.lib.cl_lang import setLocalTranslate
@ -213,8 +214,8 @@ def print_brief_group(Fields, group_name):
print_group_flag = True
colorPrint._printSUCCESS('%s: ' %(field.label))
res = printTable(data, head)
sys.stdout.write(res+"\n")
sys.stdout.flush()
sys.stdout.write(res)
else:
uncompatible_count += 1
@ -254,42 +255,6 @@ def show_view(view):
return
print "+====== show view! ======+"
def printTable(data, header=None ):
res = []
for row in data:
encode_row = map(lambda x: x.encode('utf-8') if x else '', row)
res.append(encode_row)
data = res
if type(header) == list:
header = map(lambda x: x.encode('utf-8'), header)
lens = [0]*len(data[0])
for row in data:
for numCol, column in enumerate(row):
cLen = len(unicode(str(column).decode('utf-8')))
if lens[numCol] < cLen:
lens[numCol] = cLen
res = ""
spacer = lambda lenList: '+' + '+'.join( '-'*(x+2) for x in lenList ) + '+'
drawRow = lambda lenList, valueList: '|' + "".join(
' %s ' % item + ' ' * (lenList[num] - \
len(unicode(str(item).decode('utf-8')))) + '|'
for num, item in enumerate(valueList) )
if header:
for numCol, column in enumerate(header):
cLen = len(unicode(str(column).decode('utf-8')))
if lens[numCol] < cLen:
lens[numCol] = cLen
res += spacer(lens)+ "\n"
res += drawRow( lens, header )+ "\n"
res+= spacer(lens) + "\n"
for r in data:
res += drawRow( lens, r )+ "\n"
res+= spacer(lens)+ "\n"
return res
def show_table(table, item):
if item.message:
colorPrint._printSUCCESS(item.message)
@ -300,8 +265,8 @@ def show_table(table, item):
data.append(line.string)
res = printTable(data, head)
sys.stdout.write(res+"\n")
sys.stdout.flush()
sys.stdout.write(res)
def show_error(item):
if item.message:
@ -353,11 +318,13 @@ def _create_obj(client, method):
raise Exception(1)
return view_params
def get_view_params(client, method, step = None, expert = None, brief = None):
def get_view_params(client, method, step = None, expert = None, brief = None,
onlyhelp = False):
view_params = _create_obj(client, method)
view_params.step = step
view_params.expert = expert
view_params.brief = brief
view_params.onlyhelp = onlyhelp
return view_params
def callView(client, item, sid):

@ -27,3 +27,4 @@ class DataVarsConsole(DataVars):
self.importData()
self.importData('calculate.core.variables')
self.importData('calculate.console.variables')
self.defaultModule = "console"

@ -14,21 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from calculate.lib.datavars import ReadonlyVariable
from calculate.console.datavars import __version__,__app__
import console
section = "gui"
class VariableClName(ReadonlyVariable):
"""
Package name
"""
value = __app__
class VariableClVer(ReadonlyVariable):
"""
Package version
"""
value = __version__
section = "console"

Loading…
Cancel
Save