Changeset 213
- Timestamp:
- 01/10/08 12:43:41 (11 months ago)
- Files:
-
- cleverbox/trunk/cleverbox/model/project.py (modified) (11 diffs)
- cleverbox/trunk/cleverbox/scripts/admin.py (modified) (4 diffs)
- cleverbox/trunk/cleverbox/tests/project_test.py (modified) (1 diff)
- cleverbox/trunk/cleverbox/utils/inputcollector.py (added)
- cleverbox/trunk/docs/TODO (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cleverbox/trunk/cleverbox/model/project.py
r211 r213 87 87 """ 88 88 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 89 102 # Make sure client exists 90 103 from cleverbox.model import client … … 97 110 98 111 # 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 135 113 136 114 try: 137 115 # -- Apache configuration file 138 _write_apache_conf(environment, collected_infos,parameters)116 _write_apache_conf(environment, parameters) 139 117 140 118 # -- Create required dirs 141 _create_dirs(environment, collected_infos,parameters)119 _create_dirs(environment, parameters) 142 120 143 121 # -- SVN repository creation 144 _create_svn_repos(environment, collected_infos,parameters)122 _create_svn_repos(environment, parameters) 145 123 146 124 # -- Trac environment initialisation 147 _trac_initenv(environment, collected_infos,parameters)125 _trac_initenv(environment, parameters) 148 126 149 127 # -- Trac initial permissions 150 _trac_setperms(environment, collected_infos,parameters)128 _trac_setperms(environment, parameters) 151 129 152 130 # -- Modifies Trac default conf 153 _trac_defaultconf(environment, collected_infos,parameters)131 _trac_defaultconf(environment, parameters) 154 132 155 133 # -- 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: 167 137 enable(environment, client_name, project_name) 168 138 … … 174 144 175 145 176 def _create_dirs(environment, infos , parameters):146 def _create_dirs(environment, infos): 177 147 os.makedirs(os.path.join(environment.config.get('general', 'clients_root'), 178 148 infos['client'], … … 182 152 print " Creating project's directory layout\n" 183 153 184 def _write_apache_conf(environment, infos , parameters):154 def _write_apache_conf(environment, infos): 185 155 """ 186 156 TODO : clients may not be stored in 'clients_root', be careful with that. … … 201 171 print " Apache configuration written to %s\n" % apache_conf_filepath 202 172 203 def _create_svn_repos(environment, infos , parameters):173 def _create_svn_repos(environment, infos): 204 174 repos_path = os.path.join( environment.config.get('general', 'clients_root'), infos['client'], 'var/svn', infos['short_name'] ) 205 175 create_cmd = 'svnadmin create %s' % repos_path … … 212 182 print " Subversion repository created in %s\n" % repos_path 213 183 214 def _trac_initenv(environment, infos , parameters):184 def _trac_initenv(environment, infos): 215 185 216 186 trac_env_path = os.path.join( environment.config.get('general', 'clients_root'), … … 242 212 print " Trac project initialized in %s\n" % trac_env_path 243 213 244 def _trac_setperms(environment, infos , parameters):214 def _trac_setperms(environment, infos): 245 215 trac_env_path = os.path.join( environment.config.get('general', 'clients_root'), 246 216 infos['client'], … … 269 239 270 240 # Remove all anonymous permissions 241 # TODO : instead of using the default_perms array, we should list all anonymous using the permissions list cmd 271 242 os.system( trac_perms_cmd % {'env_path' : trac_env_path, 272 243 'subcommand' : 'remove', … … 283 254 'perms' : perms_config.get('trac', profile)} ) 284 255 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'] 295 257 296 258 os.system( trac_perms_cmd % {'env_path' : trac_env_path, … … 301 263 print " Trac initial permissions set (admin rights given to '%s')\n" % admin_login 302 264 303 def _fix_perms(environment, infos , parameters):265 def _fix_perms(environment, infos): 304 266 305 267 clients_root = environment.config.get('general', 'clients_root') … … 323 285 print " Perms fixed\n" 324 286 325 def _trac_defaultconf(environment, infos , parameters):287 def _trac_defaultconf(environment, infos): 326 288 """ 327 289 Overrides project's default trac.ini with values provided in configuration profile. cleverbox/trunk/cleverbox/scripts/admin.py
r212 r213 4 4 from trac import util 5 5 from trac.scripts.admin import TracAdmin 6 from cleverbox.utils import termcolors, styles 6 from cleverbox.utils import termcolors, styles, inputcollector 7 7 from cleverbox.model.environment import Environment 8 8 from cleverbox.model import client, project … … 45 45 # Check if environment needs an upgrade 46 46 try: 47 # TODO : would be better to throw an exception here48 47 if check_upgrade and self.env.needs_upgrade(cleverbox.version): 49 48 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) 52 51 print 53 52 sys.exit(1) … … 58 57 except IOError, e: 59 58 # 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 61 63 62 64 # Set shell prompt … … 313 315 raise Exception, 'Invalid syntax' 314 316 317 # Extract parameters from command parameters 315 318 (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) 317 331 318 332 def complete_project(self, text, line, begidx, endidx): cleverbox/trunk/cleverbox/tests/project_test.py
r211 r213 11 11 default_parameters = project_parameters = {'full_name' : 'Test Project', 12 12 'profile' : 'default', 13 ' admin_login': 'admin',13 'tracadmin' : 'admin', 14 14 'enable' : 'y'} 15 15 class ProjectTestCase(unittest.TestCase): cleverbox/trunk/docs/TODO
r212 r213 11 11 * apachectl integration (for configtest + reload) 12 12 * 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
