Show
Ignore:
Timestamp:
08/10/07 13:54:50 (5 years ago)
Author:
trivoallan
Message:

cleverbox :


fixes #2, #10

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cleverbox/trunk/cleverbox/scripts/admin.py

    r133 r143  
    11# -*- coding: utf-8 -*- 
    22 
     3import shutils 
    34import cmd 
    45import os 
     
    1213 
    1314_defaults = { 
    14     'env_dir_layout'       : ('clients-available', 'clients-enabled', 
    15                               'projects-available', 'projects-enabled'), 
     15    'env_dir_layout'    : ('clients-available', 'clients-enabled', 
     16                           'projects-available', 'projects-enabled', 
     17                           'profiles/default'), 
    1618    'client_dir_layout' : ('htdocs', 'logs', 'tmp', 'uploads', 
    1719                           'var/svn', 'var/trac'), 
     20    'profile_files'     : ('project.apache.conf', 'trac-defaults.ini', 'permissions.ini') 
    1821} 
    1922 
     
    133136        collected_infos['apache_group'] = raw_input('Webserver group id [%d]> ' % d_gid).strip() or d_gid 
    134137 
    135         # SSH user & group 
    136         d_uid = '1001' 
    137         d_gid = '1001' 
    138         collected_infos['ssh_user'] = raw_input('SSH user id [%s]> ' % d_uid).strip() or d_uid 
    139         collected_infos['ssh_group'] = raw_input('SSH group id [%s]> ' % d_gid).strip() or d_gid 
    140  
    141         # Virtual Host mode : single or multi ? 
    142         d_vhost_mode = 'single' 
    143         collected_infos['vhost_mode'] = raw_input('Virtual host mode (either "single" or "multi") [%s]> ' % d_vhost_mode).strip() or d_vhost_mode 
     138        # root user & group 
     139        # we keep the ssh_user notion for backward compatibility. 
     140        # this will have to disappear in a future release  
     141        collected_infos['ssh_user'] = 0 
     142        collected_infos['ssh_group'] = 0 
     143 
     144        # Host server domain name 
     145        collected_infos['domain'] = raw_input('Domain name > ').strip() 
    144146         
    145         if collected_infos['vhost_mode'] == 'multi': 
    146             collected_infos['domain'] = raw_input('Domain name > ').strip() 
    147          
    148         # Cleverbox assets 
    149         d_cleverbox_assets = '/usr/share/cleverbox' 
    150         collected_infos['assets_dir'] = raw_input('Cleverbox assets directory [%s]> ' % d_cleverbox_assets).strip() or d_cleverbox_assets 
    151  
    152147        # Authentication backend password (if any) 
    153148        collected_infos['authbackend_pass'] = raw_input('Authentication backend password (if any) []> ').strip() or '' 
     149 
     150        # Default configuration profile 
     151        dcp = 'default' 
     152        collected_infos['default_profile'] = raw_input('Default configuration profile [%s]> ' % dcp).strip() or dcp 
    154153                 
    155154        # Write ini file 
     
    174173        # Create directory structure 
    175174        try: 
    176             print "\n\tCreating directory structure\n" 
     175            print "\n\tCreating directory layout\n" 
    177176            env_dirs = [] 
    178177            for dirname in _defaults['env_dir_layout']: 
     
    185184        # Create VERSION file 
    186185        try: 
     186            print "\n\tCreating VERSION file\n" 
    187187            fd = open( os.path.join(self.envname, 'VERSION'), 'w' ) 
    188188            fd.write(_version) 
    189189        finally: 
    190190            fd.close() 
     191 
     192        # Default configuration profile 
     193        print "\n\tCreating default configuration profile\n" 
     194        for filename in _defaults['profile_files']: 
     195            shutils.copy('/usr/share/cleverbox/assets/' + filename, os.path.join(self.envname, 'profile', 'default')) 
     196         
    191197 
    192198        print 
     
    695701            collected_infos['full_name'] = raw_input('Full Name [%s]> ' % dfn).strip() or dfn 
    696702 
     703            print 
     704            print "  What configuration profile should be used ?" 
     705            print "  Those reside in %s/profiles/" % self.envname 
     706            print 
     707 
     708            dp = self.getConfig('default_profile', 'general') 
     709            collected_infos['profile'] = raw_input('Configuration profile [%s]> ' % dp).strip() or dp 
     710 
    697711            # Project creation 
    698712            print 
     
    751765        TODO : clients may not be stored in 'clients_root', be careful with that. 
    752766        """ 
    753         conf_template = open('%s/%s.%s' % (self.getConfig('assets_dir', 'general'), 'apache.conf', self.getConfig('vhost_mode', 'general'))) 
     767        conf_template = open(os.path.join(self.envname, 'profiles', infos['profile'], 'project.apache.conf')) 
    754768        conf_data = conf_template.read() % {'client_name'      : infos['client'], 
    755769                                            'project_name'     : infos['short_name'], 
     
    841855        # Grant default permissions 
    842856        perms_config = ConfigParser.SafeConfigParser() 
    843         perms_config.read(os.path.join(self.getConfig('assets_dir', 'general'), 'permissions.ini')) 
     857        perms_config.read(os.path.join(self.envname, 'profiles', infos['profile'], 'permissions.ini')) 
    844858        for profile in perms_config.options('trac'): 
    845859            os.system( trac_perms_cmd % {'env_path'   : trac_env_path, 
     
    868882        chmod g+w /$CLIENTSROOT/$CLIENTNAME/var/svn/$PROJECTNAME 
    869883        chown -R www-data:dev /$CLIENTSROOT/$CLIENTNAME/var/trac/$PROJECTNAME/db 
    870         chown dev:www-data /$CLIENTSROOT/$CLIENTNAME/var/trac/conf/trac.ini 
    871         chmod g+w /$CLIENTSROOT/$CLIENTNAME/var/trac/conf/trac.ini 
     884            chown dev:www-data /$CLIENTSROOT/$CLIENTNAME/var/trac/conf/trac.ini 
     885            chmod g+w /$CLIENTSROOT/$CLIENTNAME/var/trac/conf/trac.ini 
    872886        """ 
    873887 
     
    909923 
    910924    def _project_trac_defaultconf(self, infos): 
     925        """ 
     926        Overrides project's default trac.ini with values provided in configuration profile. 
     927        """ 
     928         
    911929        # New defaults 
    912930        tracdefaults_config = ConfigParser.SafeConfigParser() 
    913         tracdefaults_config.read(os.path.join(self.getConfig('assets_dir', 'general'), 'trac-defaults.ini')) 
     931        tracdefaults_config.read(os.path.join(self.envname, 'profiles', infos['profile'], 'trac-defaults.ini')) 
    914932         
    915933        # Trac base config file 
    916         project_config_path = os.path.join('%s/%s/var/trac/%s/conf/trac.ini' % (self.getConfig('clients_root', 'general'), infos['client'], infos['short_name'])) 
     934        project_config_path = os.path.join(self.getConfig('clients_root', 'general', infos['client'], 'var', 'trac', infos['short_name'], 'conf', 'trac.ini')) 
    917935        tracproject_config = ConfigParser.SafeConfigParser() 
    918936        tracproject_config.read(project_config_path)