mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Rename files
This commit is contained in:
parent
45fcc5bed8
commit
c5edde0053
3 changed files with 30 additions and 19 deletions
|
@ -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):
|
|
@ -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:
|
|
@ -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'))
|
Loading…
Reference in a new issue