Changeset 213 for cleverbox/trunk

Show
Ignore:
Timestamp:
01/10/08 12:43:41 (4 years ago)
Author:
trivoallan
Message:

cleverbox : started implementation of a generic input collection framework.

Location:
cleverbox/trunk
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • cleverbox/trunk/cleverbox/model/project.py

    r211 r213  
    8787    """ 
    8888     
     89    # Parameters required for project creation 
     90    required = ('client', 'short_name', 'full_name', 'profile', 'enable') 
     91 
     92    # Merging for consistency 
     93    parameters['client'] = client_name 
     94    parameters['short_name'] = project_name 
     95 
     96    # Sanity checks before project creation 
     97    for required_param in required: 
     98        # This will raise a KeyError if a parameter is missing 
     99        # TODO : it could be better to raise a more specific exception 
     100        parameters[required_param] 
     101     
    89102    # Make sure client exists 
    90103    from cleverbox.model import client 
     
    97110 
    98111    # Information collection 
    99     collected_infos = { 
    100         'client'     : client_name, 
    101         'short_name' : project_name, 
    102         'full_name'  : None 
    103     } 
    104  
    105     try: 
    106         collected_infos['full_name'] = parameters['full_name'] 
    107     except KeyError: 
    108         print 
    109         print "Creating a new project for client '%s'" % client_name 
    110         print "Let's collect some informations about the project :" 
    111         print 
    112         print "  Please enter project's full name." 
    113         print "  This will be displayed in various places and emails." 
    114         print 
    115      
    116         dfn = project_name.capitalize() 
    117         collected_infos['full_name'] = raw_input('Full Name [%s]> ' % dfn).strip() or dfn 
    118  
    119     try: 
    120         collected_infos['profile'] = parameters['profile'] 
    121     except KeyError: 
    122         print 
    123         print "  What configuration profile should be used ?" 
    124         print "  Those reside in %s/profiles/" % environment.path 
    125         print 
    126      
    127         dp = environment.config.get('general', 'default_profile') 
    128         collected_infos['profile'] = raw_input('Configuration profile [%s]> ' % dp).strip() or dp 
    129  
    130     # Project creation 
    131     print 
    132     print "Supplied informations verified." 
    133     print "Let's proceed with project creation :" 
    134     print 
     112    collected_infos = parameters 
    135113 
    136114    try: 
    137115        # -- Apache configuration file 
    138         _write_apache_conf(environment, collected_infos, parameters) 
     116        _write_apache_conf(environment, parameters) 
    139117 
    140118        # -- Create required dirs 
    141         _create_dirs(environment, collected_infos, parameters) 
     119        _create_dirs(environment, parameters) 
    142120 
    143121        # -- SVN repository creation 
    144         _create_svn_repos(environment, collected_infos, parameters) 
     122        _create_svn_repos(environment, parameters) 
    145123 
    146124        # -- Trac environment initialisation 
    147         _trac_initenv(environment, collected_infos, parameters) 
     125        _trac_initenv(environment, parameters) 
    148126 
    149127        # -- Trac initial permissions 
    150         _trac_setperms(environment, collected_infos, parameters) 
     128        _trac_setperms(environment, parameters) 
    151129 
    152130        # -- Modifies Trac default conf 
    153         _trac_defaultconf(environment, collected_infos, parameters) 
     131        _trac_defaultconf(environment, parameters) 
    154132         
    155133        # -- Fix perms 
    156         _fix_perms(environment, collected_infos, parameters) 
    157  
    158         try: 
    159             enable_project = parameters['enable'] 
    160         except KeyError: 
    161             # -- Enable client ? 
    162             print "Project has been created. Do you want to enable it ?" 
    163             print 
    164             enable_project = raw_input('Enable project ? [y/N]> ').strip() or 'n' 
    165  
    166         if str(enable_project).find('y') == 0: 
     134        _fix_perms(environment, parameters) 
     135 
     136        if str(parameters['enable']).find('y') == 0: 
    167137            enable(environment, client_name, project_name) 
    168138 
     
    174144 
    175145 
    176 def _create_dirs(environment, infos, parameters): 
     146def _create_dirs(environment, infos): 
    177147    os.makedirs(os.path.join(environment.config.get('general', 'clients_root'), 
    178148                             infos['client'], 
     
    182152    print "  Creating project's directory layout\n" 
    183153 
    184 def _write_apache_conf(environment, infos, parameters): 
     154def _write_apache_conf(environment, infos): 
    185155    """ 
    186156    TODO : clients may not be stored in 'clients_root', be careful with that. 
     
    201171    print "  Apache configuration written to %s\n" % apache_conf_filepath 
    202172 
    203 def _create_svn_repos(environment, infos, parameters): 
     173def _create_svn_repos(environment, infos): 
    204174    repos_path = os.path.join( environment.config.get('general', 'clients_root'), infos['client'], 'var/svn', infos['short_name'] ) 
    205175    create_cmd = 'svnadmin create %s' % repos_path 
     
    212182    print "  Subversion repository created in %s\n" % repos_path 
    213183 
    214 def _trac_initenv(environment, infos, parameters): 
     184def _trac_initenv(environment, infos): 
    215185 
    216186    trac_env_path = os.path.join( environment.config.get('general', 'clients_root'), 
     
    242212    print "  Trac project initialized in %s\n" % trac_env_path 
    243213 
    244 def _trac_setperms(environment, infos, parameters): 
     214def _trac_setperms(environment, infos): 
    245215    trac_env_path = os.path.join( environment.config.get('general', 'clients_root'), 
    246216                                 infos['client'], 
     
    269239 
    270240    # Remove all anonymous permissions 
     241    # TODO : instead of using the default_perms array, we should list all anonymous using the permissions list cmd  
    271242    os.system( trac_perms_cmd % {'env_path'   : trac_env_path, 
    272243                                 'subcommand' : 'remove', 
     
    283254                                     'perms'      : perms_config.get('trac', profile)} ) 
    284255 
    285     try: 
    286         admin_login = parameters['profile'] 
    287     except KeyError: 
    288         # Let user choose who gets admin rights 
    289         print "  Please enter trac administrator username." 
    290         print "  This user will be granted full privileges on project's Trac instance." 
    291         print 
    292      
    293         dan = infos['short_name'] + '-admin' 
    294         admin_login = raw_input('Admin Login [%s]> ' % dan).strip() or dan 
     256    admin_login = infos['tracadmin'] 
    295257 
    296258    os.system( trac_perms_cmd % {'env_path'   : trac_env_path, 
     
    301263    print "  Trac initial permissions set (admin rights given to '%s')\n" % admin_login 
    302264 
    303 def _fix_perms(environment, infos, parameters): 
     265def _fix_perms(environment, infos): 
    304266 
    305267    clients_root = environment.config.get('general', 'clients_root') 
     
    323285    print "  Perms fixed\n" 
    324286 
    325 def _trac_defaultconf(environment, infos, parameters): 
     287def _trac_defaultconf(environment, infos): 
    326288    """ 
    327289    Overrides project's default trac.ini with values provided in configuration profile. 
  • cleverbox/trunk/cleverbox/scripts/admin.py

    r212 r213  
    44from trac import util 
    55from trac.scripts.admin import TracAdmin 
    6 from cleverbox.utils import termcolors, styles 
     6from cleverbox.utils import termcolors, styles, inputcollector 
    77from cleverbox.model.environment import Environment 
    88from cleverbox.model import client, project 
     
    4545        # Check if environment needs an upgrade 
    4646        try: 
    47             # TODO : would be better to throw an exception here 
    4847            if check_upgrade and self.env.needs_upgrade(cleverbox.version): 
    4948                print 
    50                 logging.warn("  Cleverbox environment needs to be upgraded.\n" \ 
    51                              "  Please run : cleverbox-admin %s upgrade" % self.env.path) 
     49                logging.error("  Cleverbox environment needs to be upgraded.\n" \ 
     50                              "  Please run : cleverbox-admin %s upgrade" % self.env.path) 
    5251                print 
    5352                sys.exit(1) 
     
    5857        except IOError, e: 
    5958            # no VERSION file means user wants to create an environment 
    60             pass 
     59            print 
     60            logging.warn("  Environment at %s has not been initialized yet.\n" \ 
     61                         "  Please run the 'initenv' command." % self.env.path) 
     62            print 
    6163 
    6264        # Set shell prompt 
     
    313315            raise Exception, 'Invalid syntax' 
    314316 
     317        # Extract parameters from command parameters 
    315318        (client_name, project_name) = args 
    316         project.add(self.env, client_name, project_name) 
     319         
     320        # Create input specification 
     321        input_spec = {'full_name' : ('Full name', 'This variable is not used anywhere !', project_name.capitalize()), 
     322                      'profile'   : ('Configuration profile', 'What configuration profile should be used ?', self.env.config.get('general', 'default_profile')), 
     323                      'enable'    : ('Enable project ?', 'This will make project available on the web.', 'n'), 
     324                      'tracadmin' : ('Trac administrator', "This user will be granted full privileges on project's Trac instance", project_name + '-admin')} 
     325         
     326        # Collect input 
     327        collected_input = inputcollector.collect(input_spec) 
     328         
     329        # Create project 
     330        project.add(self.env, client_name, project_name, collected_input) 
    317331 
    318332    def complete_project(self, text, line, begidx, endidx): 
  • cleverbox/trunk/cleverbox/tests/project_test.py

    r211 r213  
    1111default_parameters = project_parameters = {'full_name'   : 'Test Project', 
    1212                                           'profile'     : 'default', 
    13                                            'admin_login' : 'admin', 
     13                                           'tracadmin'  : 'admin', 
    1414                                           'enable'      : 'y'} 
    1515class ProjectTestCase(unittest.TestCase): 
  • cleverbox/trunk/docs/TODO

    r212 r213  
    1111 * apachectl integration (for configtest + reload) 
    1212 * by default, files should be owned bu current user, not root : 2.0 ! 
     13 * make code for collecting user input more generic  
     14 (and btw, models should not be responsible for collecting data) 
     15 * normalize exceptions usage 
     16 * trac permissions definitions could be better. Foreach subject listed in permissions.ini 
     17   * revoke all permissions (list obtained with 'permissions list' 
     18   * add permissions listed in permissions.ini