<s> """<STR_LIT>""" <EOL> from django . contrib . auth . models import Group <EOL> from django . core . management . base import BaseCommand <EOL> from modoboa . core import PERMISSIONS <EOL> from modoboa . core . extensions import exts_pool <EOL> from modoboa . core . models import User , ObjectAccess <EOL> from modoboa . lib . cryptutils import random_key <EOL> from modoboa . lib import events <EOL> from modoboa . lib import models as lib_models <EOL> from modoboa . lib . permissions import add_permissions_to_group <EOL> import modoboa . relaydomains . models as relay_models <EOL> class Command ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> help = "<STR_LIT>" <EOL> def handle ( self , * args , ** options ) : <EOL> """<STR_LIT>""" <EOL> if not User . objects . filter ( is_superuser = True ) . count ( ) : <EOL> admin = User ( username = "<STR_LIT>" , is_superuser = True ) <EOL> admin . set_password ( "<STR_LIT:password>" ) <EOL> admin . save ( ) <EOL> ObjectAccess . objects . create ( <EOL> user = admin , content_object = admin , is_owner = True ) <EOL> param_name = "<STR_LIT>" <EOL> qset = lib_models . Parameter . objects . filter ( name = param_name ) <EOL> if not qset . exists ( ) : <EOL> lib_models . Parameter . objects . create ( <EOL> name = param_name , value = random_key ( ) ) <EOL> for service_name in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> relay_models . Service . objects . get_or_create ( name = service_name ) <EOL> exts_pool . load_all ( ) <EOL> superadmin = User . objects . filter ( is_superuser = True ) . first ( ) <EOL> groups = PERMISSIONS . keys ( ) + [ <EOL> role [ <NUM_LIT:0> ] for role <EOL> in events . raiseQueryEvent ( "<STR_LIT>" , superadmin , None ) <EOL> ] <EOL> for groupname in groups : <EOL> group , created = Group . objects . get_or_create ( name = groupname ) <EOL> permissions = ( <EOL> PERMISSIONS . get ( groupname , [ ] ) + <EOL> events . raiseQueryEvent ( "<STR_LIT>" , groupname ) <EOL> ) <EOL> if not permissions : <EOL> continue <EOL> add_permissions_to_group ( group , permissions ) <EOL> for extname in exts_pool . extensions . keys ( ) : <EOL> extension = exts_pool . get_extension ( extname ) <EOL> extension . load_initial_data ( ) <EOL> events . raiseEvent ( "<STR_LIT>" , extname ) </s>
