##// END OF EJS Templates
new setup-rhodecode command with optional defaults
marcink -
r2284:e285aa09 beta
parent child Browse files
Show More
@@ -0,0 +1,87 b''
1 import os
2 from paste.script.appinstall import AbstractInstallCommand
3 from paste.script.command import BadCommand
4 from paste.deploy import appconfig
5
6
7 class SetupCommand(AbstractInstallCommand):
8
9 default_verbosity = 1
10 max_args = 1
11 min_args = 1
12 summary = "Setup an application, given a config file"
13 usage = "CONFIG_FILE"
14
15 description = """\
16 Note: this is an experimental command, and it will probably change
17 in several ways by the next release.
18
19 Setup an application according to its configuration file. This is
20 the second part of a two-phase web application installation
21 process (the first phase is prepare-app). The setup process may
22 consist of things like creating directories and setting up
23 databases.
24 """
25
26 parser = AbstractInstallCommand.standard_parser(
27 simulate=True, quiet=True, interactive=True)
28 parser.add_option('--user',
29 action='store',
30 dest='username',
31 default=None,
32 help='Admin Username')
33 parser.add_option('--email',
34 action='store',
35 dest='email',
36 default=None,
37 help='Admin Email')
38 parser.add_option('--password',
39 action='store',
40 dest='password',
41 default=None,
42 help='Admin password min 6 chars')
43 parser.add_option('--repos',
44 action='store',
45 dest='repos_location',
46 default=None,
47 help='Absolute path to repositories location')
48 parser.add_option('--name',
49 action='store',
50 dest='section_name',
51 default=None,
52 help='The name of the section to set up (default: app:main)')
53
54 def command(self):
55 config_spec = self.args[0]
56 section = self.options.section_name
57 if section is None:
58 if '#' in config_spec:
59 config_spec, section = config_spec.split('#', 1)
60 else:
61 section = 'main'
62 if not ':' in section:
63 plain_section = section
64 section = 'app:'+section
65 else:
66 plain_section = section.split(':', 1)[0]
67 if not config_spec.startswith('config:'):
68 config_spec = 'config:' + config_spec
69 if plain_section != 'main':
70 config_spec += '#' + plain_section
71 config_file = config_spec[len('config:'):].split('#', 1)[0]
72 config_file = os.path.join(os.getcwd(), config_file)
73 self.logging_file_config(config_file)
74 conf = appconfig(config_spec, relative_to=os.getcwd())
75 ep_name = conf.context.entry_point_name
76 ep_group = conf.context.protocol
77 dist = conf.context.distribution
78 if dist is None:
79 raise BadCommand(
80 "The section %r is not the application (probably a filter). "
81 "You should add #section_name, where section_name is the "
82 "section that configures your application" % plain_section)
83 installer = self.get_installer(dist, ep_group, ep_name)
84 installer.setup_config(
85 self, config_file, section, self.sysconfig_install_vars(installer))
86 self.call_sysconfig_functions(
87 'post_setup_hook', installer, config_file) No newline at end of file
@@ -13,6 +13,9 b' 1.4.0 (**2012-XX-XX**)'
13 news
13 news
14 ++++
14 ++++
15
15
16 - new codereview system
17 - changed setup-app into setup-rhodecode and added default options to it.
18
16 fixes
19 fixes
17 +++++
20 +++++
18
21
@@ -26,19 +26,20 b' configuration file to use this other dat'
26 postgresql, sqlite and mysql databases. Create the database by running
26 postgresql, sqlite and mysql databases. Create the database by running
27 the following command::
27 the following command::
28
28
29 paster setup-app production.ini
29 paster setup-rhodecode production.ini
30
30
31 This will prompt you for a "root" path. This "root" path is the location where
31 This will prompt you for a "root" path. This "root" path is the location where
32 RhodeCode will store all of its repositories on the current machine. After
32 RhodeCode will store all of its repositories on the current machine. After
33 entering this "root" path ``setup-app`` will also prompt you for a username
33 entering this "root" path ``setup-rhodecode`` will also prompt you for a username
34 and password for the initial admin account which ``setup-app`` sets up for you.
34 and password for the initial admin account which ``setup-rhodecode`` sets
35 up for you.
35
36
36 - The ``setup-app`` command will create all of the needed tables and an admin
37 - The ``setup-rhodecode`` command will create all of the needed tables and an
37 account. When choosing a root path you can either use a new empty location,
38 admin account. When choosing a root path you can either use a new empty
38 or a location which already contains existing repositories. If you choose a
39 location, or a location which already contains existing repositories. If you
39 location which contains existing repositories RhodeCode will simply add all
40 choose a location which contains existing repositories RhodeCode will simply
40 of the repositories at the chosen location to it's database. (Note: make
41 add all of the repositories at the chosen location to it's database.
41 sure you specify the correct path to the root).
42 (Note: make sure you specify the correct path to the root).
42 - Note: the given path for mercurial_ repositories **must** be write accessible
43 - Note: the given path for mercurial_ repositories **must** be write accessible
43 for the application. It's very important since the RhodeCode web interface
44 for the application. It's very important since the RhodeCode web interface
44 will work without write access, but when trying to do a push it will
45 will work without write access, but when trying to do a push it will
@@ -51,8 +52,8 b' You are now ready to use RhodeCode, to r'
51 - This command runs the RhodeCode server. The web app should be available at the
52 - This command runs the RhodeCode server. The web app should be available at the
52 127.0.0.1:5000. This ip and port is configurable via the production.ini
53 127.0.0.1:5000. This ip and port is configurable via the production.ini
53 file created in previous step
54 file created in previous step
54 - Use the admin account you created above when running ``setup-app`` to login
55 - Use the admin account you created above when running ``setup-rhodecode``
55 to the web app.
56 to login to the web app.
56 - The default permissions on each repository is read, and the owner is admin.
57 - The default permissions on each repository is read, and the owner is admin.
57 Remember to update these if needed.
58 Remember to update these if needed.
58 - In the admin panel you can toggle ldap, anonymous, permissions settings. As
59 - In the admin panel you can toggle ldap, anonymous, permissions settings. As
@@ -238,10 +238,15 b' class DbManage(object):'
238 self.sa.rollback()
238 self.sa.rollback()
239 raise
239 raise
240
240
241 def admin_prompt(self, second=False):
241 def admin_prompt(self, second=False, defaults={}):
242 if not self.tests:
242 if not self.tests:
243 import getpass
243 import getpass
244
244
245 # defaults
246 username = defaults.get('username')
247 password = defaults.get('password')
248 email = defaults.get('email')
249
245 def get_password():
250 def get_password():
246 password = getpass.getpass('Specify admin password '
251 password = getpass.getpass('Specify admin password '
247 '(min 6 chars):')
252 '(min 6 chars):')
@@ -255,16 +260,16 b' class DbManage(object):'
255 return False
260 return False
256
261
257 return password
262 return password
258
263 if username is None:
259 username = raw_input('Specify admin username:')
264 username = raw_input('Specify admin username:')
260
265 if password is None:
261 password = get_password()
266 password = get_password()
262 if not password:
267 if not password:
263 #second try
268 #second try
264 password = get_password()
269 password = get_password()
265 if not password:
270 if not password:
266 sys.exit()
271 sys.exit()
267
272 if email is None:
268 email = raw_input('Specify admin email:')
273 email = raw_input('Specify admin email:')
269 self.create_user(username, password, email, True)
274 self.create_user(username, password, email, True)
270 else:
275 else:
@@ -370,11 +375,14 b' class DbManage(object):'
370 log.debug('missing default permission for group %s adding' % g)
375 log.debug('missing default permission for group %s adding' % g)
371 ReposGroupModel()._create_default_perms(g)
376 ReposGroupModel()._create_default_perms(g)
372
377
373 def config_prompt(self, test_repo_path='', retries=3):
378 def config_prompt(self, test_repo_path='', retries=3, defaults={}):
379 _path = defaults.get('repos_location')
374 if retries == 3:
380 if retries == 3:
375 log.info('Setting up repositories config')
381 log.info('Setting up repositories config')
376
382
377 if not self.tests and not test_repo_path:
383 if _path is not None:
384 path = _path
385 elif not self.tests and not test_repo_path:
378 path = raw_input(
386 path = raw_input(
379 'Enter a valid absolute path to store repositories. '
387 'Enter a valid absolute path to store repositories. '
380 'All repositories in that path will be added automatically:'
388 'All repositories in that path will be added automatically:'
@@ -40,9 +40,10 b' def setup_app(command, conf, vars):'
40 tests=False)
40 tests=False)
41 dbmanage.create_tables(override=True)
41 dbmanage.create_tables(override=True)
42 dbmanage.set_db_version()
42 dbmanage.set_db_version()
43 dbmanage.create_settings(dbmanage.config_prompt(None))
43 opts = dbmanage.config_prompt(None, defaults=command.options.__dict__)
44 dbmanage.create_settings(opts)
44 dbmanage.create_default_user()
45 dbmanage.create_default_user()
45 dbmanage.admin_prompt()
46 dbmanage.admin_prompt(defaults=command.options.__dict__)
46 dbmanage.create_permissions()
47 dbmanage.create_permissions()
47 dbmanage.populate_default_permissions()
48 dbmanage.populate_default_permissions()
48 Session.commit()
49 Session.commit()
@@ -94,6 +94,7 b' setup('
94 main = pylons.util:PylonsInstaller
94 main = pylons.util:PylonsInstaller
95
95
96 [paste.global_paster_command]
96 [paste.global_paster_command]
97 setup-rhodecode=rhodecode.config.setup:SetupCommand
97 make-index=rhodecode.lib.indexers:MakeIndex
98 make-index=rhodecode.lib.indexers:MakeIndex
98 make-rcext=rhodecode.config.rcextensions.make_rcextensions:MakeRcExt
99 make-rcext=rhodecode.config.rcextensions.make_rcextensions:MakeRcExt
99 upgrade-db=rhodecode.lib.dbmigrate:UpgradeDb
100 upgrade-db=rhodecode.lib.dbmigrate:UpgradeDb
General Comments 0
You need to be logged in to leave comments. Login now