comparison rhodecode/lib/paster_commands/make_rcextensions.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/rcextensions/make_rcextensions.py@5019f7798733
children a42bfe8a9335
comparison
equal deleted inserted replaced
3339:b76a595b7a5e 3340:f1491bad8339
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.lib.paster_commands.make_rcextensions
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 make-rcext paster command for RhodeCode
7
8 :created_on: Mar 6, 2012
9 :author: marcink
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 from __future__ import with_statement
26
27 import os
28 import sys
29 import pkg_resources
30 import traceback
31 import logging
32
33 from os.path import dirname as dn, join as jn
34 #to get the rhodecode import
35 rc_path = dn(dn(dn(os.path.realpath(__file__))))
36 sys.path.append(rc_path)
37
38 from rhodecode.lib.utils import BasePasterCommand, ask_ok
39
40 log = logging.getLogger(__name__)
41
42
43 class Command(BasePasterCommand):
44
45 max_args = 1
46 min_args = 1
47
48 usage = "CONFIG_FILE"
49 group_name = "RhodeCode"
50 takes_config_file = -1
51 parser = BasePasterCommand.standard_parser(verbose=True)
52 summary = "Creates additional extensions for rhodecode"
53
54 def command(self):
55 logging.config.fileConfig(self.path_to_ini_file)
56 from pylons import config
57
58 def _make_file(ext_file, tmpl):
59 bdir = os.path.split(ext_file)[0]
60 if not os.path.isdir(bdir):
61 os.makedirs(bdir)
62 with open(ext_file, 'wb') as f:
63 f.write(tmpl)
64 log.info('Writen new extensions file to %s' % ext_file)
65
66 here = config['here']
67 tmpl = pkg_resources.resource_string(
68 'rhodecode', jn('config', 'rcextensions', '__init__.py')
69 )
70 ext_file = jn(here, 'rcextensions', '__init__.py')
71 if os.path.exists(ext_file):
72 msg = ('Extension file already exists, do you want '
73 'to overwrite it ? [y/n]')
74 if ask_ok(msg):
75 _make_file(ext_file, tmpl)
76 else:
77 log.info('nothing done...')
78 else:
79 _make_file(ext_file, tmpl)
80
81 def update_parser(self):
82 pass