# HG changeset patch # User Marcin Kuzminski # Date 1279167943 -7200 # Node ID d09381593b123634e1ed96581224d49cf57e987b # Parent 664a5b8c551a11115fcec79978f684f2253ad792 updated db manage script, and remove broken test diff -r 664a5b8c551a -r d09381593b12 pylons_app/lib/db_manage.py --- a/pylons_app/lib/db_manage.py Wed Jul 14 18:31:06 2010 +0200 +++ b/pylons_app/lib/db_manage.py Thu Jul 15 06:25:43 2010 +0200 @@ -2,7 +2,7 @@ # encoding: utf-8 # database managment for hg app # Copyright (C) 2009-2010 Marcin Kuzminski - +# # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; version 2 @@ -32,18 +32,14 @@ sys.path.append(ROOT) from pylons_app.lib.auth import get_crypt_password +from pylons_app.lib.utils import ask_ok from pylons_app.model import init_model from pylons_app.model.db import User, Permission, HgAppUi, HgAppSettings from pylons_app.model import meta from sqlalchemy.engine import create_engine import logging -log = logging.getLogger('db manage') -log.setLevel(logging.DEBUG) -console_handler = logging.StreamHandler() -console_handler.setFormatter(logging.Formatter("%(asctime)s.%(msecs)03d" - " %(levelname)-5.5s [%(name)s] %(message)s")) -log.addHandler(console_handler) +log = logging.getLogger(__name__) class DbManage(object): def __init__(self, log_sql): @@ -69,9 +65,13 @@ self.check_for_db(override) if override: log.info("database exisist and it's going to be destroyed") - if self.db_exists: + destroy = ask_ok('Are you sure to destroy old database ? [y/n]') + if not destroy: + sys.exit() + if self.db_exists and destroy: os.remove(jn(ROOT, self.dbname)) - meta.Base.metadata.create_all(checkfirst=override) + checkfirst = not override + meta.Base.metadata.create_all(checkfirst=checkfirst) log.info('Created tables for %s', self.dbname) def admin_prompt(self): @@ -83,9 +83,8 @@ def config_prompt(self): log.info('Setting up repositories config') - path = raw_input('Specify valid full path to your repositories' - ' you can change this later application settings:') + ' you can change this later in application settings:') if not os.path.isdir(path): log.error('You entered wrong path') diff -r 664a5b8c551a -r d09381593b12 pylons_app/lib/utils.py --- a/pylons_app/lib/utils.py Wed Jul 14 18:31:06 2010 +0200 +++ b/pylons_app/lib/utils.py Thu Jul 15 06:25:43 2010 +0200 @@ -16,20 +16,21 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. -from beaker.cache import cache_region """ Created on April 18, 2010 Utilities for hg app @author: marcink """ - -import os -import logging +from beaker.cache import cache_region from mercurial import ui, config, hg from mercurial.error import RepoError +from pylons_app.model import meta from pylons_app.model.db import Repository, User, HgAppUi, HgAppSettings -from pylons_app.model import meta +from vcs.backends.base import BaseChangeset +from vcs.utils.lazy import LazyProperty +import logging +import os log = logging.getLogger(__name__) @@ -77,7 +78,15 @@ log.info('%s repo is free for creation', repo_name) return True - +def ask_ok(prompt, retries=4, complaint='Yes or no, please!'): + while True: + ok = raw_input(prompt) + if ok in ('y', 'ye', 'yes'): return True + if ok in ('n', 'no', 'nop', 'nope'): return False + retries = retries - 1 + if retries < 0: raise IOError + print complaint + @cache_region('super_short_term', 'cached_hg_ui') def get_hg_ui_cached(): try: @@ -170,8 +179,6 @@ from pylons_app.model.hg_model import _full_changelog_cached region_invalidate(_full_changelog_cached, None, *args) -from vcs.backends.base import BaseChangeset -from vcs.utils.lazy import LazyProperty class EmptyChangeset(BaseChangeset): revision = -1 diff -r 664a5b8c551a -r d09381593b12 pylons_app/tests/configparser_test.py --- a/pylons_app/tests/configparser_test.py Wed Jul 14 18:31:06 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -import os -p = os.path.dirname(__file__) -repos = os.path.join(p, '../..', 'hgwebdir.config') -#repos = "/home/marcink/python_workspace/hg_app/hgwebdir.config" -print repos -from ConfigParser import ConfigParser - -cp = ConfigParser() - -cp.read(repos) -print cp.get('paths', '/')