Mercurial > public > src > rhodecode
comparison pylons_app/lib/db_manage.py @ 376:d09381593b12
updated db manage script, and remove broken test
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 15 Jul 2010 06:25:43 +0200 |
parents | 664a5b8c551a |
children | a26f48ad7a8a |
comparison
equal
deleted
inserted
replaced
374:664a5b8c551a | 376:d09381593b12 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # encoding: utf-8 | 2 # encoding: utf-8 |
3 # database managment for hg app | 3 # database managment for hg app |
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | 4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
5 | 5 # |
6 # This program is free software; you can redistribute it and/or | 6 # This program is free software; you can redistribute it and/or |
7 # modify it under the terms of the GNU General Public License | 7 # modify it under the terms of the GNU General Public License |
8 # as published by the Free Software Foundation; version 2 | 8 # as published by the Free Software Foundation; version 2 |
9 # of the License or (at your opinion) any later version of the license. | 9 # of the License or (at your opinion) any later version of the license. |
10 # | 10 # |
30 import uuid | 30 import uuid |
31 ROOT = dn(dn(dn(os.path.realpath(__file__)))) | 31 ROOT = dn(dn(dn(os.path.realpath(__file__)))) |
32 sys.path.append(ROOT) | 32 sys.path.append(ROOT) |
33 | 33 |
34 from pylons_app.lib.auth import get_crypt_password | 34 from pylons_app.lib.auth import get_crypt_password |
35 from pylons_app.lib.utils import ask_ok | |
35 from pylons_app.model import init_model | 36 from pylons_app.model import init_model |
36 from pylons_app.model.db import User, Permission, HgAppUi, HgAppSettings | 37 from pylons_app.model.db import User, Permission, HgAppUi, HgAppSettings |
37 from pylons_app.model import meta | 38 from pylons_app.model import meta |
38 from sqlalchemy.engine import create_engine | 39 from sqlalchemy.engine import create_engine |
39 import logging | 40 import logging |
40 | 41 |
41 log = logging.getLogger('db manage') | 42 log = logging.getLogger(__name__) |
42 log.setLevel(logging.DEBUG) | |
43 console_handler = logging.StreamHandler() | |
44 console_handler.setFormatter(logging.Formatter("%(asctime)s.%(msecs)03d" | |
45 " %(levelname)-5.5s [%(name)s] %(message)s")) | |
46 log.addHandler(console_handler) | |
47 | 43 |
48 class DbManage(object): | 44 class DbManage(object): |
49 def __init__(self, log_sql): | 45 def __init__(self, log_sql): |
50 self.dbname = 'hg_app.db' | 46 self.dbname = 'hg_app.db' |
51 dburi = 'sqlite:////%s' % jn(ROOT, self.dbname) | 47 dburi = 'sqlite:////%s' % jn(ROOT, self.dbname) |
67 Create a auth database | 63 Create a auth database |
68 """ | 64 """ |
69 self.check_for_db(override) | 65 self.check_for_db(override) |
70 if override: | 66 if override: |
71 log.info("database exisist and it's going to be destroyed") | 67 log.info("database exisist and it's going to be destroyed") |
72 if self.db_exists: | 68 destroy = ask_ok('Are you sure to destroy old database ? [y/n]') |
69 if not destroy: | |
70 sys.exit() | |
71 if self.db_exists and destroy: | |
73 os.remove(jn(ROOT, self.dbname)) | 72 os.remove(jn(ROOT, self.dbname)) |
74 meta.Base.metadata.create_all(checkfirst=override) | 73 checkfirst = not override |
74 meta.Base.metadata.create_all(checkfirst=checkfirst) | |
75 log.info('Created tables for %s', self.dbname) | 75 log.info('Created tables for %s', self.dbname) |
76 | 76 |
77 def admin_prompt(self): | 77 def admin_prompt(self): |
78 import getpass | 78 import getpass |
79 username = raw_input('Specify admin username:') | 79 username = raw_input('Specify admin username:') |
81 self.create_user(username, password, True) | 81 self.create_user(username, password, True) |
82 | 82 |
83 def config_prompt(self): | 83 def config_prompt(self): |
84 log.info('Setting up repositories config') | 84 log.info('Setting up repositories config') |
85 | 85 |
86 | |
87 path = raw_input('Specify valid full path to your repositories' | 86 path = raw_input('Specify valid full path to your repositories' |
88 ' you can change this later application settings:') | 87 ' you can change this later in application settings:') |
89 | 88 |
90 if not os.path.isdir(path): | 89 if not os.path.isdir(path): |
91 log.error('You entered wrong path') | 90 log.error('You entered wrong path') |
92 sys.exit() | 91 sys.exit() |
93 | 92 |