Mercurial > kallithea
comparison rhodecode/lib/paster_commands/setup_rhodecode.py @ 3340:f1491bad8339 beta
unified RhodeCode paster commands
- moved them to commont paster_commands package
- re-use sqlalchemy session initializaiton
- some docs updates
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 09 Feb 2013 22:21:31 +0100 |
parents | rhodecode/config/setup_rhodecode.py@29630805893d |
children | a42bfe8a9335 |
comparison
equal
deleted
inserted
replaced
3339:b76a595b7a5e | 3340:f1491bad8339 |
---|---|
1 import os | |
2 import sys | |
3 from paste.script.appinstall import AbstractInstallCommand | |
4 from paste.script.command import BadCommand | |
5 from paste.deploy import appconfig | |
6 | |
7 from os.path import dirname as dn, join as jn | |
8 #to get the rhodecode import | |
9 rc_path = dn(dn(dn(os.path.realpath(__file__)))) | |
10 sys.path.append(rc_path) | |
11 | |
12 | |
13 class Command(AbstractInstallCommand): | |
14 | |
15 default_verbosity = 1 | |
16 max_args = 1 | |
17 min_args = 1 | |
18 summary = "Setup an application, given a config file" | |
19 usage = "CONFIG_FILE" | |
20 group_name = "RhodeCode" | |
21 | |
22 description = """\ | |
23 | |
24 Setup RhodeCode according to its configuration file. This is | |
25 the second part of a two-phase web application installation | |
26 process (the first phase is prepare-app). The setup process | |
27 consist of things like setting up databases, creating super user | |
28 """ | |
29 | |
30 parser = AbstractInstallCommand.standard_parser( | |
31 simulate=True, quiet=True, interactive=True) | |
32 parser.add_option('--user', | |
33 action='store', | |
34 dest='username', | |
35 default=None, | |
36 help='Admin Username') | |
37 parser.add_option('--email', | |
38 action='store', | |
39 dest='email', | |
40 default=None, | |
41 help='Admin Email') | |
42 parser.add_option('--password', | |
43 action='store', | |
44 dest='password', | |
45 default=None, | |
46 help='Admin password min 6 chars') | |
47 parser.add_option('--repos', | |
48 action='store', | |
49 dest='repos_location', | |
50 default=None, | |
51 help='Absolute path to repositories location') | |
52 parser.add_option('--name', | |
53 action='store', | |
54 dest='section_name', | |
55 default=None, | |
56 help='The name of the section to set up (default: app:main)') | |
57 parser.add_option('--force-yes', | |
58 action='store_true', | |
59 dest='force_ask', | |
60 default=None, | |
61 help='Force yes to every question') | |
62 parser.add_option('--force-no', | |
63 action='store_false', | |
64 dest='force_ask', | |
65 default=None, | |
66 help='Force no to every question') | |
67 | |
68 def command(self): | |
69 config_spec = self.args[0] | |
70 section = self.options.section_name | |
71 if section is None: | |
72 if '#' in config_spec: | |
73 config_spec, section = config_spec.split('#', 1) | |
74 else: | |
75 section = 'main' | |
76 if not ':' in section: | |
77 plain_section = section | |
78 section = 'app:' + section | |
79 else: | |
80 plain_section = section.split(':', 1)[0] | |
81 if not config_spec.startswith('config:'): | |
82 config_spec = 'config:' + config_spec | |
83 if plain_section != 'main': | |
84 config_spec += '#' + plain_section | |
85 config_file = config_spec[len('config:'):].split('#', 1)[0] | |
86 config_file = os.path.join(os.getcwd(), config_file) | |
87 self.logging_file_config(config_file) | |
88 conf = appconfig(config_spec, relative_to=os.getcwd()) | |
89 ep_name = conf.context.entry_point_name | |
90 ep_group = conf.context.protocol | |
91 dist = conf.context.distribution | |
92 if dist is None: | |
93 raise BadCommand( | |
94 "The section %r is not the application (probably a filter). " | |
95 "You should add #section_name, where section_name is the " | |
96 "section that configures your application" % plain_section) | |
97 installer = self.get_installer(dist, ep_group, ep_name) | |
98 installer.setup_config( | |
99 self, config_file, section, self.sysconfig_install_vars(installer)) | |
100 self.call_sysconfig_functions( | |
101 'post_setup_hook', installer, config_file) |