Rename files

This commit is contained in:
Kloadut 2012-10-10 20:53:42 +02:00
parent 45fcc5bed8
commit c5edde0053
3 changed files with 30 additions and 19 deletions

View file

@ -31,7 +31,6 @@ if not __debug__:
gettext.install('YunoHost')
try:
sys.path.append('lib')
from yunohost import YunoHostError, YunoHostLDAP, str_to_func, colorize, pretty_print_dict
except ImportError:
sys.stderr.write('Require YunoHost lib')
@ -342,6 +341,18 @@ def parse_dict(action_dict):
args = parsers['general'].parse_args()
return { 'ldap' : ldap, 'args' : args }
def display_error(error):
"""
Nice error displaying
"""
if not __debug__ :
traceback.print_exc()
if os.isatty(1):
print('\n' + colorize(_("Error: "), 'red') + error.message)
else:
print(json.dumps({ 'error' : error.message }))
def main():
"""
Main instructions
@ -355,25 +366,24 @@ def main():
"""
action = parse_dict(action_dict)
try:
# Connect to LDAP if the action is requiring it
if action['ldap']:
yldap = YunoHostLDAP()
except YunoHostError, error:
display_error(error)
return error.code
try:
if action['ldap']:
result = action['args'].func(vars(action['args']), yldap)
else:
result = action['args'].func(vars(action['args']))
#except TypeError:
#print(_("Not (yet) implemented function"))
#return 1
except TypeError:
print(_("Not (yet) implemented function"))
return 1
except YunoHostError, error:
if not __debug__ :
traceback.print_exc()
if os.isatty(1):
print('\n' + colorize(_("Error: "), 'red') + error.message)
else:
print(json.dumps({ 'error' : error.message }))
display_error(error)
return error.code
else:
if os.isatty(1):

View file

@ -6,7 +6,6 @@ import ldap
import ldap.modlist as modlist
import re
import getpass
sys.path.append('./') # Local temporary hack
def colorize(astr, color):
@ -141,7 +140,7 @@ class YunoHostLDAP:
"""
self.conn = ldap.initialize('ldap://localhost:389')
self.base = 'dc=yunohost,dc=org'
self.pwd = getpass.getpass(_('LDAP Admin Password: '))
self.pwd = getpass.getpass(colorize(_('LDAP Admin Password: '), 'yellow'))
try:
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)
except ldap.INVALID_CREDENTIALS:

View file

@ -32,14 +32,14 @@ def user_create(args, yldap):
for arg in required_args:
if not args[arg]:
if os.isatty(1):
args[arg] = raw_input(colorize(arg.capitalize()+': ', 'yellow'))
args[arg] = raw_input(colorize(arg.capitalize()+': ', 'cyan'))
else:
raise Exception
# Password
if not args['password']:
if os.isatty(1):
args['password'] = getpass.getpass(colorize('Password: ', 'yellow'))
pwd2 = getpass.getpass(colorize('Retype password:', 'yellow'))
args['password'] = getpass.getpass(colorize('Password: ', 'cyan'))
pwd2 = getpass.getpass(colorize('Retype password:', 'cyan'))
if args['password'] != pwd2:
raise YunoHostError(22, _("Passwords doesn't match"))
else:
@ -78,8 +78,10 @@ def user_create(args, yldap):
'mailalias' : args['mail']
})
#TODO: check if mail belongs to a domain
if yldap.add(rdn, attr_dict):
win_msg(_("User successfully created"))
return attr_dict
return { _("Fullname") : fullname, _("Username") : args['username'], _("Mail") : args['mail'] }
else:
raise YunoHostError(169, _('An error occured during user creation'))