Mercurial > kallithea
annotate rhodecode/config/setup_rhodecode.py @ 2729:e9e7c40b4f1a beta
added deque with maxlen for py2.5 compat
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 22 Aug 2012 12:09:49 +0200 |
parents | 5893414dea91 |
children | 29630805893d |
rev | line source |
---|---|
2284
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 import os |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 from paste.script.appinstall import AbstractInstallCommand |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 from paste.script.command import BadCommand |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 from paste.deploy import appconfig |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 class SetupCommand(AbstractInstallCommand): |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 default_verbosity = 1 |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 max_args = 1 |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 min_args = 1 |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 summary = "Setup an application, given a config file" |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 usage = "CONFIG_FILE" |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 description = """\ |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 Note: this is an experimental command, and it will probably change |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 in several ways by the next release. |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 Setup an application according to its configuration file. This is |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 the second part of a two-phase web application installation |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 process (the first phase is prepare-app). The setup process may |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 consist of things like creating directories and setting up |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 databases. |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 """ |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 parser = AbstractInstallCommand.standard_parser( |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 simulate=True, quiet=True, interactive=True) |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 parser.add_option('--user', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 action='store', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 dest='username', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 default=None, |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 help='Admin Username') |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 parser.add_option('--email', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 action='store', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 dest='email', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 default=None, |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 help='Admin Email') |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 parser.add_option('--password', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 action='store', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 dest='password', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 default=None, |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 help='Admin password min 6 chars') |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 parser.add_option('--repos', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 action='store', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 dest='repos_location', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 default=None, |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 help='Absolute path to repositories location') |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 parser.add_option('--name', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 action='store', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 dest='section_name', |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 default=None, |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 help='The name of the section to set up (default: app:main)') |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 def command(self): |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 config_spec = self.args[0] |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 section = self.options.section_name |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 if section is None: |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 if '#' in config_spec: |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 config_spec, section = config_spec.split('#', 1) |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 else: |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 section = 'main' |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 if not ':' in section: |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 plain_section = section |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 section = 'app:'+section |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 else: |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 plain_section = section.split(':', 1)[0] |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 if not config_spec.startswith('config:'): |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 config_spec = 'config:' + config_spec |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 if plain_section != 'main': |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 config_spec += '#' + plain_section |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 config_file = config_spec[len('config:'):].split('#', 1)[0] |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 config_file = os.path.join(os.getcwd(), config_file) |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 self.logging_file_config(config_file) |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 conf = appconfig(config_spec, relative_to=os.getcwd()) |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 ep_name = conf.context.entry_point_name |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 ep_group = conf.context.protocol |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 dist = conf.context.distribution |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 if dist is None: |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 raise BadCommand( |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 "The section %r is not the application (probably a filter). " |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 "You should add #section_name, where section_name is the " |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 "section that configures your application" % plain_section) |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 installer = self.get_installer(dist, ep_group, ep_name) |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 installer.setup_config( |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 self, config_file, section, self.sysconfig_install_vars(installer)) |
e285aa097a81
new setup-rhodecode command with optional defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 self.call_sysconfig_functions( |
2289
5893414dea91
renamed setup module into a setup_rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents:
2284
diff
changeset
|
87 'post_setup_hook', installer, config_file) |