Bug fixes

This commit is contained in:
Kloadut 2012-10-15 22:48:05 +02:00
parent 6fec72d127
commit 1f4b115b6f
4 changed files with 25 additions and 26 deletions

View file

@ -444,37 +444,35 @@ action_map = {
'actions' : { 'actions' : {
'info': { 'info': {
'action_help' : _("Check System"), 'action_help' : _("Check System"),
'connections' : ['ldap'], 'arguments' : {
'arguments' : {
'-m' : { '-m' : {
'full' : '--memory', 'full' : '--memory',
'help' : _("Check Memory"), 'help' : _("Check Memory"),
'action' : 'store_true', 'action' : 'store_true',
}, },
'-c' : { '-c' : {
'full' : '--cpu', 'full' : '--cpu',
'help' : _("Check CPU"), 'help' : _("Check CPU"),
'action' : 'store_true', 'action' : 'store_true',
}, },
'-d' : { '-d' : {
'full' : '--disk', 'full' : '--disk',
'help' : _("Check Disk"), 'help' : _("Check Disk"),
'action' : 'store_true', 'action' : 'store_true',
}, },
'-i' : { '-i' : {
'full' : '--ifconfig', 'full' : '--ifconfig',
'help' : _("Ifconfig"), 'help' : _("Ifconfig"),
'action' : 'store_true', 'action' : 'store_true',
}, },
'-u' : { '-u' : {
'full' : '--uptime', 'full' : '--uptime',
'help' : _("Show Uptime"), 'help' : _("Show Uptime"),
'action' : 'store_true', 'action' : 'store_true',
}, },
} }
}, },
} }
},
}, },
############################# #############################
# Firewall # # Firewall #
@ -632,13 +630,14 @@ def main(action_map):
""" """
args = parse_dict(action_map) args = parse_dict(action_map)
connections = connect_services(action_map) connections = connect_services(action_map)
try: try:
if connections: if connections:
result = args.func(vars(args), connections) result = args.func(vars(args), connections)
else: else:
result = args.func(vars(args)) result = args.func(vars(args))
except TypeError: except TypeError, error:
print error
print(_("Not (yet) implemented function")) print(_("Not (yet) implemented function"))
return 1 return 1
except YunoHostError, error: except YunoHostError, error:

View file

@ -4,6 +4,7 @@ import os
import sys import sys
import ldap import ldap
import ldap.modlist as modlist import ldap.modlist as modlist
import json
import re import re
import getpass import getpass
@ -72,8 +73,8 @@ def str_to_func(astr):
func = getattr(mod, function) func = getattr(mod, function)
except (AttributeError, ImportError): except (AttributeError, ImportError):
#raise YunoHostError(168, _('Function is not defined')) #raise YunoHostError(168, _('Function is not defined'))
return None return None
else: else:
return func return func
@ -208,7 +209,7 @@ class YunoHostLDAP:
""" """
self.conn = ldap.initialize('ldap://localhost:389') self.conn = ldap.initialize('ldap://localhost:389')
self.base = 'dc=yunohost,dc=org' self.base = 'dc=gavoty,dc=org'
self.pwd = getpass.getpass(colorize(_('LDAP Admin Password: '), 'yellow')) self.pwd = getpass.getpass(colorize(_('LDAP Admin Password: '), 'yellow'))
try: try:
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd) self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)

View file

@ -5,7 +5,7 @@ import sys
import subprocess import subprocess
import psutil import psutil
from datetime import datetime, timedelta from datetime import datetime, timedelta
from psutil._compat import print_ #from psutil._compat import print_
def bytes2human(n): def bytes2human(n):
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y') symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
@ -22,7 +22,7 @@ def check_disk():
templ = "%s,%s/%s,%s,%s" templ = "%s,%s/%s,%s,%s"
for part in psutil.disk_partitions(all=False): for part in psutil.disk_partitions(all=False):
usage = psutil.disk_usage(part.mountpoint) usage = psutil.disk_usage(part.mountpoint)
print_(templ % (part.mountpoint, print(templ % (part.mountpoint,
bytes2human(usage.used), bytes2human(usage.used),
bytes2human(usage.total), bytes2human(usage.total),
bytes2human(usage.free), bytes2human(usage.free),
@ -49,14 +49,14 @@ def uptime():
uptime = datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME) uptime = datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME)
print "Uptime: %s" % (str(uptime).split('.')[0]) print "Uptime: %s" % (str(uptime).split('.')[0])
def monitor_info(args, connections): def monitor_info(args):
if args['memory'] == True: if args['memory']:
check_memory() check_memory()
elif args['cpu'] == True: elif args['cpu']:
check_cpu() check_cpu()
elif args['disk'] == True: elif args['disk']:
check_disk() check_disk()
elif args['ifconfig'] == True: elif args['ifconfig']:
ifconfig() ifconfig()
elif args['uptime'] == True: elif args['uptime']:
uptime() uptime()

View file

@ -9,7 +9,6 @@ import string
import getpass import getpass
from yunohost import YunoHostError, win_msg, colorize, validate from yunohost import YunoHostError, win_msg, colorize, validate
def user_list(args, connections): # TODO : fix def user_list(args, connections): # TODO : fix
print(args) print(args)