changeset 378:a1e8912a89bc demo

Merge with 76f8bef61098228cc92ccc24283777de95837a26
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 16 Jul 2010 14:51:24 +0200
parents 12bdf5496788 (current diff) 76f8bef61098 (diff)
children 78ad5c98e476
files pylons_app/tests/configparser_test.py
diffstat 4 files changed, 31 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/controllers/error.py	Wed Jul 14 18:32:51 2010 +0200
+++ b/pylons_app/controllers/error.py	Fri Jul 16 14:51:24 2010 +0200
@@ -38,10 +38,14 @@
 
         if resp.status_int == 404:
             org_e = request.environ.get('pylons.original_request').environ
-            c.repo_name = repo_name = org_e['PATH_INFO'].split('/')[1]
+            try:
+                c.repo_name = org_e['PATH_INFO'].split('/')[1]
+            except IndexError:
+                c.repo_name = ''
+            
             c.hg_app_version = __version__
             c.repo_name_cleaned = h.repo_name_slug(c.repo_name)
-            if check_repo(repo_name, g.base_path):
+            if check_repo(c.repo_name, g.base_path):
                 return render('/errors/error_404.html')
                 
         c.error_message = cgi.escape(request.GET.get('code', str(resp.status)))
--- a/pylons_app/lib/db_manage.py	Wed Jul 14 18:32:51 2010 +0200
+++ b/pylons_app/lib/db_manage.py	Fri Jul 16 14:51:24 2010 +0200
@@ -2,7 +2,7 @@
 # encoding: utf-8
 # database managment for hg app
 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
- 
+#
 # 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')
--- a/pylons_app/lib/utils.py	Wed Jul 14 18:32:51 2010 +0200
+++ b/pylons_app/lib/utils.py	Fri Jul 16 14:51:24 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
--- a/pylons_app/tests/configparser_test.py	Wed Jul 14 18:32:51 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', '/')