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

cleverbox :

  • Factored environment in it's own class.
  • Made environment initialisation atomic
  • Created stubs for unit tests
  • Created stubs for color in cli output
  • It's now possible to use *nix user and group names instead of uid and gid in cleverbox.ini


Work in progress, probably buggy.

Location:
cleverbox/trunk/cleverbox
Files:
10 added
1 modified

Legend:

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

    r173 r177  
    11# -*- coding: utf-8 -*- 
    22 
    3 import shutil 
    4 import cmd 
    5 import os 
    6 import shlex 
    7 import sys 
    8 import traceback 
    9 import re 
     3import shutil, cmd, os, shlex, sys, traceback, re, ConfigParser, posix 
     4from pkg_resources import parse_version 
    105from trac import util 
    116from trac.scripts.admin import TracAdmin 
    12 import ConfigParser 
    13 from pkg_resources import parse_version 
     7from cleverbox.utils import termcolors 
     8from cleverbox.environment import Environment 
    149 
    1510_defaults = { 
     
    2217} 
    2318 
    24 _version = '0.5.dev' 
     19_version = '0.5dev' 
     20 
     21# Set up the terminal color scheme. 
     22class dummy: pass 
     23style = dummy() 
     24style.ERROR = termcolors.make_style(fg='red', opts=('bold',)) 
     25del dummy 
     26 
     27def disable_termcolors(): 
     28    class dummy: 
     29        def __getattr__(self, attr): 
     30            return lambda x: x 
     31    global style 
     32    style = dummy() 
     33 
     34# Disable terminal coloring on Windows, Pocket PC, or if somebody's piping the output. 
     35if sys.platform == 'win32' or sys.platform == 'Pocket PC' or not sys.stdout.isatty(): 
     36    disable_termcolors() 
    2537 
    2638class CleverboxAdmin(cmd.Cmd): 
     
    3143    ruler = '' 
    3244    prompt = "Cleverbox > " 
    33     envname = None 
    34     __env = None 
    3545    _date_format = '%Y-%m-%d' 
    3646    _datetime_format = '%Y-%m-%d %H:%M:%S' 
     
    4959    ## 
    5060 
    51     def env_set(self, envname, env=None): 
    52         self.envname = envname 
    53         self.prompt = "Cleverbox [%s] > " % self.envname 
     61    def env_set(self, env_path): 
     62         
     63        # Load environment 
     64        self.env = Environment(env_path) 
    5465         
    5566        # Check if environment needs an upgrade 
    56         #  - open VERSION 
    5767        try: 
    58             env_version = open(os.path.join(self.envname, 'VERSION')).read().strip() 
    59              
    60             #  - compare with self._version 
    61             #  - if VERSION < self._version : 
    62             if parse_version(env_version) < parse_version(_version):  
     68            if self.env.needs_upgrade(_version): 
    6369                print "\nCleverbox environment needs to be upgraded. Please run :" 
    64                 print "  cleverbox-admin %s upgrade\n" % self.envname 
     70                print "  cleverbox-admin %s upgrade\n" % self.env.path 
    6571                sys.exit(1) 
    6672        except IOError, e: 
    6773            # no VERSION file means user wants to create an environment 
    6874            pass 
     75 
     76        # Set shell prompt 
     77        self.prompt = "Cleverbox [%s] > " % self.env.path 
    6978         
    70         if env is not None: 
    71             self.__env = env 
    72  
    7379        # Read configuration 
     80        # TODO : move to environment.py ? 
    7481        self._config = ConfigParser.SafeConfigParser() 
    75         self._config.read(os.path.join(self.envname, 'cleverbox.ini')) 
    76  
    77  
    78     def env_check(self): 
    79         try: 
    80             pass 
    81             #self.__env = Environment(self.envname) 
    82         except: 
    83             return 0 
    84         return 1 
    85  
    86     def env_open(self): 
    87         try: 
    88             if not self.__env: 
    89                 #self.__env = Environment(self.envname) 
    90                 return self.__env 
    91         except Exception, e: 
    92             print 'Failed to open environment.', e 
    93             traceback.print_exc() 
    94             sys.exit(1) 
     82        self._config.read(self.env.get_file_path('cleverbox.ini')) 
    9583 
    9684    def emptyline(self): 
     
    115103        self.cmdloop() 
    116104 
    117     # 
    118     # Configuration related methods 
    119     # 
    120     def getConfig(self, directive, section): 
    121         try: 
    122             val = self._config.get(section, directive) 
    123         except ConfigParser.NoOptionError, exception: 
    124             val = '' 
    125         return val 
    126  
    127     # 
    128     # Commands 
    129     # 
    130  
    131105    ## Environment 
    132106    _help_initenv = [('initenv', 'Environment initialisation')] 
    133107    def do_initenv(self, line=None): 
    134         print "Environment initialisation in %(env_dir)s" % {'env_dir' : self.envname} 
     108        print "Environment initialisation in %(env_dir)s" % {'env_dir' : self.env.path} 
    135109 
    136110        # Collect local configuration info 
    137         collected_infos = {} 
     111        collected_infos = {'general' : {}, 'trac' : {}} 
    138112 
    139113        # Path to client dir 
    140114        default_root = '/var/cleverbox' 
    141         collected_infos['clients_root'] = raw_input('Projects directory [%s]> ' % default_root).strip() or default_root 
     115        collected_infos['general']['clients_root'] = raw_input('Projects directory [%s]> ' % default_root).strip() or default_root 
    142116 
    143117        # Path to cleverbox assets 
    144118        default_assets_dir = '/usr/share/cleverbox' 
    145         collected_infos['assets_dir'] = raw_input('Cleverbox assets directory [%s]> ' % default_assets_dir).strip() or default_assets_dir 
     119        collected_infos['general']['assets_dir'] = raw_input('Cleverbox assets directory [%s]> ' % default_assets_dir).strip() or default_assets_dir 
    146120 
    147121        try : 
    148             os.makedirs(collected_infos['clients_root'], 0775) 
     122            os.makedirs(collected_infos['general']['clients_root'], 0775) 
    149123        except IOError, ioexception : 
    150124            print ioexception 
     
    152126 
    153127        # Apache user & group 
    154         d_uid = 33 
    155         d_gid = 33 
    156         collected_infos['apache_user'] = raw_input('Webserver user id [%d]> ' % d_uid).strip() or d_uid 
    157         collected_infos['apache_group'] = raw_input('Webserver group id [%d]> ' % d_gid).strip() or d_gid 
     128        d_uid = 'www-data' 
     129        d_gid = 'www-data' 
     130        collected_infos['general']['apache_user'] = raw_input('Webserver user [%s]> ' % d_uid).strip() or d_uid 
     131        collected_infos['general']['apache_group'] = raw_input('Webserver group [%s]> ' % d_gid).strip() or d_gid 
    158132 
    159133        # root user & group 
    160134        # we keep the ssh_user notion for backward compatibility. 
    161135        # this will have to disappear in a future release  
    162         collected_infos['ssh_user'] = 0 
    163         collected_infos['ssh_group'] = 0 
     136        collected_infos['general']['ssh_user'] = 'root' 
     137        collected_infos['general']['ssh_group'] = 'root' 
    164138 
    165139        # Host server domain name 
    166         collected_infos['domain'] = raw_input('Domain name > ').strip() 
     140        collected_infos['general']['domain'] = raw_input('Domain name > ').strip() 
    167141         
    168142        # Authentication backend password (if any) 
    169         collected_infos['authbackend_pass'] = raw_input('Authentication backend password (if any) []> ').strip() or '' 
     143        collected_infos['general']['authbackend_pass'] = raw_input('Authentication backend password (if any) []> ').strip() or '' 
    170144 
    171145        # Default configuration profile 
    172146        dcp = 'default' 
    173         collected_infos['default_profile'] = raw_input('Default configuration profile [%s]> ' % dcp).strip() or dcp 
     147        collected_infos['general']['default_profile'] = raw_input('Default configuration profile [%s]> ' % dcp).strip() or dcp 
    174148                 
    175         # Write ini file 
    176         self._config.add_section('general') 
    177         for directive, value in collected_infos.items() : 
    178             self._config.set('general', directive, str(value)) 
    179  
    180         trac_infos = {} 
    181149        d_lib_dir = '/usr/share/python-support/trac' 
    182         trac_infos['lib_dir'] = raw_input('Trac libs directory [%s]> ' % d_lib_dir).strip() or d_lib_dir 
     150        collected_infos['trac']['lib_dir'] = raw_input('Trac libs directory [%s]> ' % d_lib_dir).strip() or d_lib_dir 
    183151 
    184152        d_assets_dir = '/usr/share/trac' 
    185         trac_infos['assets_dir'] = raw_input('Trac assets directory [%s]> ' % d_assets_dir).strip() or d_assets_dir 
    186  
    187         self._config.add_section('trac') 
    188         for directive, value in trac_infos.items() : 
    189             self._config.set('trac', directive, str(value)) 
     153        collected_infos['trac']['assets_dir'] = raw_input('Trac assets directory [%s]> ' % d_assets_dir).strip() or d_assets_dir 
     154 
     155        # Environment creation 
     156        self.env.create(_version, collected_infos) 
    190157         
    191         fh_config = open(os.path.join(self.envname, 'cleverbox.ini'), 'w+') 
    192         self._config.write(fh_config) 
    193  
    194         # Create directory structure 
    195         try: 
    196             print "\n\tCreating directory layout\n" 
    197             env_dirs = [] 
    198             for dirname in _defaults['env_dir_layout']: 
    199                 env_dirs.append( os.path.join(self.envname, dirname) ) 
    200             map( os.makedirs, env_dirs ) 
    201         except IOError, ioexception : 
    202             print ioexception 
    203             print "** Environment couldn't be initialized in %(env_dir)s\n" % {'env_dir' : self.envname} 
    204  
    205         # Create VERSION file 
    206         try: 
    207             print "\n\tCreating VERSION file\n" 
    208             fd = open( os.path.join(self.envname, 'VERSION'), 'w' ) 
    209             fd.write(_version) 
    210         finally: 
    211             fd.close() 
    212  
    213         # Default configuration profile 
    214         print "\n\tCreating default configuration profile\n" 
    215         for filename in _defaults['profile_files']: 
    216             shutil.copy(collected_infos['assets_dir'] + '/' + filename, os.path.join(self.envname, 'profiles', 'default')) 
    217          
    218  
    219158        print 
    220159        print "Environment successfully initialized\n" 
    221160        print "You need to add this statement to your apache configuration : \n" \ 
    222             "\t'Include %(env_dir)s/clients-enabled/*'\n" % {'env_dir' : self.envname} 
     161            "\t'Include %(env_dir)s/clients-enabled/*'\n" % {'env_dir' : self.env.path} 
    223162 
    224163    _help_upgrade = [('upgrade', 'Executes necessary operation to make environment up to date')] 
    225164    def do_upgrade(self, line=None): 
    226         env_version = open(os.path.join(self.envname, 'VERSION')).read() 
    227         if parse_version(env_version) < parse_version(_version):  
    228             from cleverbox.upgrades import upgrades 
    229             i = 1 
    230             while i: 
    231                 try: 
    232                     upgrade_func = getattr(upgrades, 'do_upgrade_' + str(i)) 
    233                     upgrade_func.__call__(self.envname, env_version) 
    234                 except AttributeError, e: 
    235                     break 
    236                 i = i + 1 
    237              
     165        self.env.upgrade()             
    238166 
    239167    ## help 
     
    334262                                'ftp_password' : None } 
    335263 
    336             collected_infos['home_dir'] = os.path.join(self.getConfig('clients_root', 'general'), client_name) 
     264            collected_infos['home_dir'] = os.path.join(self.env.config.get('general', 'clients_root'), client_name) 
    337265 
    338266            # A few checks before effectively creating client 
     
    376304""" % { 'client_name' : client_name, 
    377305        'home_dir'    : collected_infos['home_dir'], 
    378         'env_dir'     : self.envname } 
     306        'env_dir'     : self.env.path } 
    379307 
    380308            # -- Write conf to filesystem 
    381             apache_conf_filepath = os.path.join( self.envname, 'clients-available', client_name ) 
     309            apache_conf_filepath = os.path.join( self.env.path, 'clients-available', client_name ) 
    382310            f = file(apache_conf_filepath, 'w+') 
    383311            f.write(apache_conf) 
     
    394322            chmod g+w /$CLIENTSROOT/$CLIENTNAME/uploads 
    395323            """ 
    396             self._rchown( collected_infos['home_dir'], 
    397                          int(self.getConfig('ssh_user', 'general')), 
    398                          int(self.getConfig('ssh_group', 'general')) ) 
    399             os.chown( os.path.join(collected_infos['home_dir'], 'logs'), 
    400                      int(self.getConfig('ssh_user', 'general')), int(self.getConfig('apache_group', 'general')) ) 
    401             os.chmod( os.path.join(collected_infos['home_dir'], 'logs'), 0775 ) 
    402             os.chown( os.path.join(collected_infos['home_dir'], 'uploads'), 
    403                      int(self.getConfig('ssh_user', 'general')), int(self.getConfig('apache_group', 'general')) ) 
    404             os.chmod( os.path.join(collected_infos['home_dir'], 'uploads'), 0775 ) 
     324            self._rchown(collected_infos['home_dir'], 
     325                         self.get_uid_from_name(username)(self.env.config.get('general', 'ssh_user')), 
     326                         self.get_gid_from_name(self.env.config.get('general', 'ssh_group'))) 
     327             
     328            os.chown(os.path.join(collected_infos['home_dir'], 'logs'), 
     329                     get_uid_from_name(self.env.config.get('general', 'ssh_user')),  
     330                     get_gid_from_name(self.env.config.get('general', 'apache_group')) ) 
     331             
     332            os.chmod(os.path.join(collected_infos['home_dir'], 'logs'), 0775) 
     333             
     334            os.chown(os.path.join(collected_infos['home_dir'], 'uploads'), 
     335                     get_uid_from_name(self.env.config.get('general', 'ssh_user')), 
     336                     get_gid_from_name(self.env.config.get('general', 'apache_group'))) 
     337             
     338            os.chmod(os.path.join(collected_infos['home_dir'], 'uploads'), 0775) 
    405339 
    406340            print "  Fixed permissions in %s\n" % collected_infos['home_dir'] 
     
    458392 
    459393            # Disable client 
    460             client_apacheconf = os.path.join( self.envname, 'clients-available', client_name ) 
     394            client_apacheconf = os.path.join( self.env.path, 'clients-available', client_name ) 
    461395            os.unlink(client_apacheconf) 
    462396            print "Client '%s' has been removed." % client_name 
     
    476410 
    477411        if enable_client: 
    478             target = os.path.join( self.envname, 'clients-available', client_name ) 
    479             linkname = os.path.join( self.envname, 'clients-enabled', client_name ) 
     412            target = os.path.join( self.env.path, 'clients-available', client_name ) 
     413            linkname = os.path.join( self.env.path, 'clients-enabled', client_name ) 
    480414            os.symlink( target, linkname ) 
    481415            print "Client '%s' has been enabled" % client_name 
     
    499433 
    500434        if disable_client: 
    501             linkname = os.path.join( self.envname, 'clients-enabled', client_name ) 
     435            linkname = os.path.join( self.env.path, 'clients-enabled', client_name ) 
    502436            os.unlink( linkname ) 
    503437            print "Client '%s' has been disabled" % client_name 
     
    534468        # Each client 
    535469        if not only: 
    536             list_clients = os.listdir(os.path.join(self.envname, 'clients-available')) 
     470            list_clients = os.listdir(os.path.join(self.env.path, 'clients-available')) 
    537471 
    538472        # Only enabled clients 
    539473        elif only == 'enabled': 
    540             list_clients = os.listdir(os.path.join(self.envname, 'clients-enabled')) 
     474            list_clients = os.listdir(os.path.join(self.env.path, 'clients-enabled')) 
    541475 
    542476        # Only disabled clients (ie. not enabled) 
     
    544478 
    545479            disabled_clients = [] 
    546             available_clients = os.listdir(os.path.join(self.envname, 'clients-available')) 
    547             enabled_clients = os.listdir(os.path.join(self.envname, 'clients-enabled')) 
     480            available_clients = os.listdir(os.path.join(self.env.path, 'clients-available')) 
     481            enabled_clients = os.listdir(os.path.join(self.env.path, 'clients-enabled')) 
    548482 
    549483            # Expect poor performances for this intersection algorithm 
     
    611545        all_projects_dir     = 'projects-available' 
    612546 
    613         list_enabled_projects = os.listdir(os.path.join(self.envname, enabled_projects_dir)) 
    614         list_all_projects = os.listdir(os.path.join(self.envname, all_projects_dir)) 
     547        list_enabled_projects = os.listdir(os.path.join(self.env.path, enabled_projects_dir)) 
     548        list_all_projects = os.listdir(os.path.join(self.env.path, all_projects_dir)) 
    615549 
    616550        list_projects = [] 
     
    641575            if (self._project_exists(client_name, project_name)): 
    642576                try: 
    643                     os.unlink( os.path.join(self.envname, 'projects-enabled', '%s-%s' % (client_name, project_name)) ) 
     577                    os.unlink( os.path.join(self.env.path, 'projects-enabled', '%s-%s' % (client_name, project_name)) ) 
    644578                    print "Project '%s' has been disabled. Apache needs to be reloaded." % project_name 
    645579                except (IOError, os.error), exception: 
     
    657591            if self._project_exists(client_name, project_name): 
    658592                try: 
    659                     target = os.path.join( self.envname, 
     593                    target = os.path.join( self.env.path, 
    660594                                          'projects-available', 
    661595                                          '%s-%s' % (client_name, project_name) ) 
    662                     linkname = os.path.join( self.envname, 
     596                    linkname = os.path.join( self.env.path, 
    663597                                          'projects-enabled', 
    664598                                          '%s-%s' % (client_name, project_name) ) 
     
    697631        # Delete apache config file 
    698632        try: 
    699             linkname = os.path.join( self.envname, 'projects-available', '%s-%s'% (client_name, project_name) ) 
     633            linkname = os.path.join( self.env.path, 'projects-available', '%s-%s'% (client_name, project_name) ) 
    700634            os.unlink( linkname ) 
    701635            print "Project '%s' has been removed" % project_name 
     
    739673            print 
    740674            print "  What configuration profile should be used ?" 
    741             print "  Those reside in %s/profiles/" % self.envname 
    742             print 
    743  
    744             dp = self.getConfig('default_profile', 'general') 
     675            print "  Those reside in %s/profiles/" % self.env.path 
     676            print 
     677 
     678            dp = self.env.config.get('general', 'default_profile') 
    745679            collected_infos['profile'] = raw_input('Configuration profile [%s]> ' % dp).strip() or dp 
    746680 
     
    790724 
    791725    def _project_create_dirs(self, infos): 
    792         os.makedirs(os.path.join(self.getConfig('clients_root', 'general'), 
     726        os.makedirs(os.path.join(self.self.env.config.get('general', 'clients_root'), 
    793727                                 infos['client'], 
    794728                                 'htdocs', 
     
    801735        TODO : clients may not be stored in 'clients_root', be careful with that. 
    802736        """ 
    803         conf_template = open(os.path.join(self.envname, 'profiles', infos['profile'], 'project.apache.conf')) 
     737        conf_template = open(os.path.join(self.env.path, 'profiles', infos['profile'], 'project.apache.conf')) 
    804738        conf_data = conf_template.read() % {'client_name'      : infos['client'], 
    805739                                            'project_name'     : infos['short_name'], 
    806                                             'clients_root'     : self.getConfig('clients_root', 'general'), 
    807                                             'authbackend_pass' : self.getConfig('authbackend_pass', 'general'), 
    808                                             'trac_install_dir' : self.getConfig('lib_dir', 'trac'), 
    809                                             'domain_name'      : self.getConfig('domain', 'general')} 
    810  
    811         apache_conf_filepath = os.path.join( self.envname, 'projects-available', '%s-%s' % (infos['client'], infos['short_name']) ) 
     740                                            'clients_root'     : self.env.config.get('general', 'clients_root'), 
     741                                            'authbackend_pass' : self.env.config.get('general', 'authbackend_pass'), 
     742                                            'trac_install_dir' : self.env.config.get('trac', 'lib_dir'), 
     743                                            'domain_name'      : self.env.config.get('general', 'domain')} 
     744 
     745        apache_conf_filepath = os.path.join( self.env.path, 'projects-available', '%s-%s' % (infos['client'], infos['short_name']) ) 
    812746        f = file(apache_conf_filepath, 'w+') 
    813747        f.write(conf_data) 
     
    817751 
    818752    def _project_create_svn_repos(self, infos): 
    819         repos_path = os.path.join( self.getConfig('clients_root', 'general'), infos['client'], 'var/svn', infos['short_name'] ) 
     753        repos_path = os.path.join( self.env.config.get('general', 'clients_root'), infos['client'], 'var/svn', infos['short_name'] ) 
    820754        create_cmd = 'svnadmin create %s' % repos_path 
    821755        (stdin, stdout, stderr) = os.popen3( create_cmd ) 
     
    829763    def _project_trac_initenv(self, infos): 
    830764 
    831         trac_env_path = os.path.join( self.getConfig('clients_root', 'general'), 
     765        trac_env_path = os.path.join( self.env.config.get('general', 'clients_root'), 
    832766                                     infos['client'], 
    833767                                     'var/trac', 
    834768                                     infos['short_name'] ) 
    835769 
    836         svn_path = os.path.join( self.getConfig('clients_root', 'general'), 
     770        svn_path = os.path.join( self.env.config.get('general', 'clients_root'), 
    837771                                infos['client'], 
    838772                                'var/svn', 
     
    843777                     'db_dsn'           : 'sqlite:db/trac.db', 
    844778                     'svn_path'         : svn_path, 
    845                      'templates_path'   : '%s/templates' % self.getConfig('assets_dir', 'trac'), 
    846                      'trac_install_dir' : self.getConfig('lib_dir', 'trac')} 
     779                     'templates_path'   : '%s/templates' % self.env.config.get('trac', 'assets_dir'), 
     780                     'trac_install_dir' : self.env.config.get('trac', 'lib_dir')} 
    847781 
    848782        trac_cmd = '/usr/bin/trac-admin %(env_path)s initenv %(title)s %(db_dsn)s svn %(svn_path)s %(templates_path)s' % cmd_data 
     
    858792 
    859793    def _project_trac_setperms(self, infos): 
    860         trac_env_path = os.path.join( self.getConfig('clients_root', 'general'), 
     794        trac_env_path = os.path.join( self.env.config.get('general', 'clients_root'), 
    861795                                     infos['client'], 
    862796                                     'var/trac', 
     
    891825        # Grant default permissions 
    892826        perms_config = ConfigParser.SafeConfigParser() 
    893         perms_config.read(os.path.join(self.envname, 'profiles', infos['profile'], 'permissions.ini')) 
     827        perms_config.read(os.path.join(self.env.path, 'profiles', infos['profile'], 'permissions.ini')) 
    894828        for profile in perms_config.options('trac'): 
    895829            os.system( trac_perms_cmd % {'env_path'   : trac_env_path, 
     
    923857 
    924858        # Trac DB 
    925         trac_db_path   = os.path.join( self.getConfig('clients_root', 'general'), 
     859        trac_db_path   = os.path.join(self.env.config.get('general', 'clients_root'), 
    926860                                      infos['client'], 
    927861                                      'var/trac', 
    928862                                      infos['short_name'], 
    929                                       'db' ) 
    930         self._rchown( trac_db_path , int(self.getConfig('apache_user', 'general')), int(self.getConfig('ssh_group', 'general')) ) 
     863                                      'db') 
     864        self._rchown(trac_db_path,  
     865                     get_uid_from_name(self.env.config.get('general', 'apache_user')), 
     866                     get_gid_from_name(self.env.config.get('general', 'ssh_group'))) 
    931867 
    932868        # Trac attachments 
    933         trac_attachments_path = os.path.join( self.getConfig('clients_root', 'general'), 
     869        trac_attachments_path = os.path.join( self.env.config.get('general', 'clients_root'), 
    934870                                             infos['client'], 
    935871                                             'var/trac', 
     
    937873                                             'attachments' ) 
    938874 
    939         self._rchown( trac_attachments_path , int(self.getConfig('apache_user', 'general')), int(self.getConfig('ssh_group', 'general')) ) 
     875        self._rchown(trac_attachments_path , 
     876                     get_uid_from_name(self.env.config.get('general', 'apache_user')), 
     877                     get_gid_from_name(self.env.config.get('general', 'ssh_group'))) 
    940878 
    941879        # Trac conf 
    942         trac_ini_path   = os.path.join( self.getConfig('clients_root', 'general'), 
     880        trac_ini_path   = os.path.join( self.env.config.get('general', 'clients_root'), 
    943881                                       infos['client'], 
    944882                                       'var','trac', 
     
    948886 
    949887        # Subversion repository 
    950         svn_repos_path = os.path.join( self.getConfig('clients_root', 'general'), 
     888        svn_repos_path = os.path.join( self.env.config.get('general', 'clients_root'), 
    951889                                      infos['client'], 
    952890                                      'var/svn', 
    953891                                      infos['short_name'] ) 
    954892 
    955         self._rchown( svn_repos_path, int(self.getConfig('apache_user', 'general')), int(self.getConfig('ssh_group', 'general')) ) 
     893        self._rchown(svn_repos_path,  
     894                     get_uid_from_name(self.env.config.get('general', 'apache_user')),  
     895                     get_gid_from_name(self.env.config.get('general', 'ssh_group'))) 
     896         
    956897        os.chmod( svn_repos_path, 0775 ) 
    957898 
     
    965906        # New defaults 
    966907        tracdefaults_config = ConfigParser.SafeConfigParser() 
    967         tracdefaults_config.read(os.path.join(self.envname, 'profiles', infos['profile'], 'trac-defaults.ini')) 
     908        tracdefaults_config.read(os.path.join(self.env.path, 'profiles', infos['profile'], 'trac-defaults.ini')) 
    968909         
    969910        # Trac base config file 
    970         project_config_path = os.path.join(self.getConfig('clients_root', 'general', infos['client'], 'var', 'trac', infos['short_name'], 'conf', 'trac.ini')) 
     911        project_config_path = os.path.join(self.env.config.get('general', 'clients_root', infos['client'], 'var', 'trac', infos['short_name'], 'conf', 'trac.ini')) 
    971912        tracproject_config = ConfigParser.SafeConfigParser() 
    972913        tracproject_config.read(project_config_path) 
     
    981922                default_option = tracdefaults_config.get(section, option) % {'client_name'      : infos['client'], 
    982923                                                                             'project_name'     : infos['short_name'], 
    983                                                                              'clients_root'     : self.getConfig('clients_root', 'general'), 
    984                                                                              'authbackend_pass' : self.getConfig('authbackend_pass', 'general'), 
    985                                                                              'trac_install_dir' : self.getConfig('lib_dir', 'trac'), 
    986                                                                              'domain_name'      : self.getConfig('domain', 'general')} 
     924                                                                             'clients_root'     : self.env.config.get('general', 'clients_root'), 
     925                                                                             'authbackend_pass' : self.env.config.get('general', 'authbackend_pass'), 
     926                                                                             'trac_install_dir' : self.env.config.get('trac', 'lib_dir'), 
     927                                                                             'domain_name'      : self.env.config.get('general', 'domain')} 
    987928                tracproject_config.set(section, option, default_option) 
    988929 
     
    10951036        argstr = util.to_utf8(argstr, sys.stdin.encoding) 
    10961037        return shlex.split(argstr) or [''] 
     1038 
     1039    def get_uid_from_name(self, username): 
     1040        return posix.pwd.getpwnam(username)['pw_uid'] 
     1041         
     1042    def get_gid_from_name(self, groupname): 
     1043        return posix.grp.getgrnam(groupname)['gr_gid'] 
    10971044 
    10981045def run(args):