Mercurial > kallithea
comparison rhodecode/config/setup/__init__.py @ 2284:e285aa097a81 beta
new setup-rhodecode command with optional defaults
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 16 May 2012 23:16:04 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2281:1927dcb05178 | 2284:e285aa097a81 |
---|---|
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) |