Changeset 200 for cleverbox/trunk/cleverbox
- Timestamp:
- 09/12/07 20:35:55 (5 years ago)
- Location:
- cleverbox/trunk/cleverbox
- Files:
-
- 6 modified
-
client.py (modified) (2 diffs)
-
environment.py (modified) (1 diff)
-
project.py (modified) (11 diffs)
-
tests/__init__.py (modified) (1 diff)
-
tests/client.py (modified) (4 diffs)
-
tests/project.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cleverbox/trunk/cleverbox/client.py
r196 r200 47 47 return list_clients 48 48 49 def add(environment, client_name ):49 def add(environment, client_name, parameters = {}): 50 50 """ 51 51 Creates a new client in supplied environment. … … 118 118 # -- Enable client ? 119 119 print styles.style.RESET('') 120 enable_client = raw_input('Enable client ? [y/N]> ').strip() or False 121 122 if enable_client == 'y': 120 try: 121 enable_client = parameters['enable'] 122 except KeyError: 123 enable_client = raw_input('Enable client ? [y/N]> ').strip() or False 124 125 if str(enable_client).find('y') == 0: 123 126 enable(environment,client_name) 124 127 -
cleverbox/trunk/cleverbox/environment.py
r196 r200 102 102 103 103 except Exception, exception: 104 105 104 logging.error(exception) 106 105 logging.error(" Environment couldn't be initialized in %(env_dir)s" % {'env_dir' : self.path}) -
cleverbox/trunk/cleverbox/project.py
r194 r200 82 82 print styles.style.RESET('') 83 83 84 def add(environment, client_name, project_name ):84 def add(environment, client_name, project_name, parameters = {}): 85 85 """ 86 86 Creates a new project for client in environment. … … 101 101 'short_name' : project_name, 102 102 'full_name' : None 103 } 104 105 print 106 print "Creating a new project for client '%s'" % client_name 107 print "Let's collect some informations about the project :" 108 print 109 print " Please enter project's full name." 110 print " This will be displayed in various places and emails." 111 print 112 113 dfn = project_name.capitalize() 114 collected_infos['full_name'] = raw_input('Full Name [%s]> ' % dfn).strip() or dfn 115 116 print 117 print " What configuration profile should be used ?" 118 print " Those reside in %s/profiles/" % environment.path 119 print 120 121 dp = environment.config.get('general', 'default_profile') 122 collected_infos['profile'] = raw_input('Configuration profile [%s]> ' % dp).strip() or dp 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 123 129 124 130 # Project creation … … 130 136 try: 131 137 # -- Apache configuration file 132 _write_apache_conf(environment, collected_infos )138 _write_apache_conf(environment, collected_infos, parameters) 133 139 134 140 # -- Create required dirs 135 _create_dirs(environment, collected_infos )141 _create_dirs(environment, collected_infos, parameters) 136 142 137 143 # -- SVN repository creation 138 _create_svn_repos(environment, collected_infos )144 _create_svn_repos(environment, collected_infos, parameters) 139 145 140 146 # -- Trac environment initialisation 141 _trac_initenv(environment, collected_infos )147 _trac_initenv(environment, collected_infos, parameters) 142 148 143 149 # -- Trac initial permissions 144 _trac_setperms(environment, collected_infos )150 _trac_setperms(environment, collected_infos, parameters) 145 151 146 152 # -- Modifies Trac default conf 147 _trac_defaultconf(environment, collected_infos )153 _trac_defaultconf(environment, collected_infos, parameters) 148 154 149 155 # -- Fix perms 150 _fix_perms(environment, collected_infos )156 _fix_perms(environment, collected_infos, parameters) 151 157 152 158 except Exception, e: … … 155 161 traceback.print_exc() 156 162 157 # -- Enable client ? 158 print "Project has been created. Do you want to enable it ?" 159 print 160 enable_project = raw_input('Enable project ? [y/N]> ').strip() or 'n' 163 try: 164 enable_project = parameters['enable'] 165 except KeyError: 166 # -- Enable client ? 167 print "Project has been created. Do you want to enable it ?" 168 print 169 enable_project = raw_input('Enable project ? [y/N]> ').strip() or 'n' 161 170 162 171 if str(enable_project).find('y') == 0: 163 172 enable(environment, client_name, project_name) 164 173 165 def _create_dirs(environment, infos ):174 def _create_dirs(environment, infos, parameters): 166 175 os.makedirs(os.path.join(environment.config.get('general', 'clients_root'), 167 176 infos['client'], … … 171 180 print " Creating project's directory layout\n" 172 181 173 def _write_apache_conf(environment, infos ):182 def _write_apache_conf(environment, infos, parameters): 174 183 """ 175 184 TODO : clients may not be stored in 'clients_root', be careful with that. … … 190 199 print " Apache configuration written to %s\n" % apache_conf_filepath 191 200 192 def _create_svn_repos(environment, infos ):201 def _create_svn_repos(environment, infos, parameters): 193 202 repos_path = os.path.join( environment.config.get('general', 'clients_root'), infos['client'], 'var/svn', infos['short_name'] ) 194 203 create_cmd = 'svnadmin create %s' % repos_path … … 201 210 print " Subversion repository created in %s\n" % repos_path 202 211 203 def _trac_initenv(environment, infos ):212 def _trac_initenv(environment, infos, parameters): 204 213 205 214 trac_env_path = os.path.join( environment.config.get('general', 'clients_root'), … … 231 240 print " Trac project initialized in %s\n" % trac_env_path 232 241 233 def _trac_setperms(environment, infos ):242 def _trac_setperms(environment, infos, parameters): 234 243 trac_env_path = os.path.join( environment.config.get('general', 'clients_root'), 235 244 infos['client'], … … 272 281 'perms' : perms_config.get('trac', profile)} ) 273 282 274 # Let user choose who gets admin rights 275 print " Please enter trac administrator username." 276 print " This user will be granted full privileges on project's Trac instance." 277 print 278 279 dan = infos['short_name'] + '-admin' 280 admin_login = raw_input('Admin Login [%s]> ' % dan).strip() or dan 283 try: 284 admin_login = parameters['profile'] 285 except KeyError: 286 # Let user choose who gets admin rights 287 print " Please enter trac administrator username." 288 print " This user will be granted full privileges on project's Trac instance." 289 print 290 291 dan = infos['short_name'] + '-admin' 292 admin_login = raw_input('Admin Login [%s]> ' % dan).strip() or dan 281 293 282 294 os.system( trac_perms_cmd % {'env_path' : trac_env_path, … … 287 299 print " Trac initial permissions set (admin rights given to '%s')\n" % admin_login 288 300 289 def _fix_perms(environment, infos ):301 def _fix_perms(environment, infos, parameters): 290 302 """ 291 303 chown -R dev:www-data /$CLIENTSROOT/$CLIENTNAME/var/svn/$PROJECTNAME … … 339 351 print " Perms fixed\n" 340 352 341 def _trac_defaultconf(environment, infos ):353 def _trac_defaultconf(environment, infos, parameters): 342 354 """ 343 355 Overrides project's default trac.ini with values provided in configuration profile. -
cleverbox/trunk/cleverbox/tests/__init__.py
r195 r200 35 35 env = Environment(env_path) 36 36 parameters = {'general' : 37 {'clients_root' : os.path.join(test_root, 'var', 'cleverbox'), 38 'assets_dir' : os.path.join('/home/trivoallan/workspace/cleverbox-trunk/assets'), 39 'apache_group' : 'www-data', 40 'ssh_user' : 'root', 41 'ssh_group' : 'root'}} 37 {'clients_root' : os.path.join(test_root, 'var', 'cleverbox'), 38 'assets_dir' : os.path.join('/home/trivoallan/workspace/cleverbox-trunk/assets'), 39 'apache_group' : 'www-data', 40 'ssh_user' : 'root', 41 'ssh_group' : 'root', 42 'default_profile' : 'default', 43 'authbackend_pass' : '', 44 'domain' : 'test.domain.tld', 45 'apache_user' : 'www-data', 46 'apache_group' : 'www-data'}, 47 'trac' : 48 {'lib_dir' : '/usr/share/python-support/trac', 49 'assets_dir' : '/usr/share/trac'}} 42 50 env.create(version, parameters) 43 51 -
cleverbox/trunk/cleverbox/tests/client.py
r196 r200 25 25 def test_client_add_generate_expected_layout(self): 26 26 client_name = 'testclient' 27 client.add(self.env, client_name )27 client.add(self.env, client_name, {'enable' : 'y'}) 28 28 clients_root = self.env.config.get('general', 'clients_root') 29 29 expected = {os.path.join(self.env.path, 'clients-available', client_name) : ('S_ISREG', '0640', 'root', 'www-data'), … … 40 40 def test_client_add_generates_expected_apache_configuration(self): 41 41 client_name = 'testclient' 42 client.add(self.env, client_name )42 client.add(self.env, client_name, {'enable' : 'y'}) 43 43 expected = """ 44 44 # -- Include enabled projects configuration files … … 54 54 """ 55 55 client_name = 'testclient' 56 client.add(self.env, client_name )56 client.add(self.env, client_name, {'enable' : 'y'}) 57 57 try: 58 client.add(self.env, client_name + 'f')58 client.add(self.env, client_name, {'enable' : 'y'}) 59 59 except Exception, e: 60 60 pass … … 65 65 client_name = 'test-client' 66 66 try: 67 client.add(self.env, client_name )67 client.add(self.env, client_name, {'enable' : 'y'}) 68 68 except Exception, e: 69 69 pass -
cleverbox/trunk/cleverbox/tests/project.py
r177 r200 1 1 import unittest 2 3 import logging, os, shutil, tempfile 4 from cleverbox.environment import Environment 5 from cleverbox.scripts.admin import CleverboxAdmin 6 from cleverbox import client, project 7 import cleverbox.tests 8 9 logging.basicConfig(stream=open('/dev/null', 'w+')) 2 10 3 11 class ProjectTestCase(unittest.TestCase): … … 5 13 # Fixtures 6 14 def setUp(self): 7 pass15 self.env = cleverbox.tests.create_environment('0.5test') 8 16 9 17 def tearDown(self): 10 pass 18 shutil.rmtree(self.env.path) 19 shutil.rmtree(self.env.config.get('general', 'clients_root')) 20 21 def test_exists_return_true_if_client_exists(self): 22 23 client_name = 'testclient' 24 client.add(self.env, client_name, {'enable' : 'y'}) 25 26 project_name = 'testproject' 27 project_parameters = {'full_name' : 'Test Project', 28 'profile' : 'default', 29 'admin_login' : 'admin', 30 'enable' : 'y'} 31 project.add(self.env, client_name, project_name, project_parameters) 32 assert project.exists(self.env, client_name, project_name), 'project.exists() returns true if project already exists' 33 34 11 35 12 36 def suite(): 13 return unittest.makeSuite(ProjectTestCase, 'test')37 return unittest.makeSuite(ProjectTestCase, 'test') 14 38 15 39 if __name__ == '__main__':
