changeset 1373:66f03a87141c beta

Fixes issue #201 Fixed bug when repository was deleted on filesystem, and not from rhodecode
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 09 Jun 2011 15:12:12 +0200
parents fced98787f40
children a16f163200b8
files rhodecode/controllers/summary.py rhodecode/lib/__init__.py rhodecode/lib/base.py rhodecode/lib/helpers.py rhodecode/model/scm.py rhodecode/tests/test_models.py test.ini
diffstat 7 files changed, 79 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/summary.py	Thu Jun 09 14:04:55 2011 +0200
+++ b/rhodecode/controllers/summary.py	Thu Jun 09 15:12:12 2011 +0200
@@ -65,7 +65,7 @@
     def index(self, repo_name):
 
         e = request.environ
-        c.dbrepo = dbrepo = Repository.by_repo_name(repo_name)
+        c.dbrepo = dbrepo = c.rhodecode_db_repo
 
         c.following = self.scm_model.is_following_repo(repo_name,
                                                 self.rhodecode_user.user_id)
--- a/rhodecode/lib/__init__.py	Thu Jun 09 14:04:55 2011 +0200
+++ b/rhodecode/lib/__init__.py	Thu Jun 09 15:12:12 2011 +0200
@@ -83,19 +83,32 @@
     return _str in ('t', 'true', 'y', 'yes', 'on', '1')
 
 
-def convert_line_endings(temp, mode):
+def convert_line_endings(line, mode):
+    """
+    Converts a given line  "line end" accordingly to given mode
+    
+    Available modes are::
+        0 - Unix
+        1 - Mac
+        2 - DOS
+    
+    :param line: given line to convert
+    :param mode: mode to convert to
+    :rtype: str
+    :return: converted line according to mode
+    """
     from string import replace
-    #modes:  0 - Unix, 1 - Mac, 2 - DOS
+
     if mode == 0:
-            temp = replace(temp, '\r\n', '\n')
-            temp = replace(temp, '\r', '\n')
+            line = replace(line, '\r\n', '\n')
+            line = replace(line, '\r', '\n')
     elif mode == 1:
-            temp = replace(temp, '\r\n', '\r')
-            temp = replace(temp, '\n', '\r')
+            line = replace(line, '\r\n', '\r')
+            line = replace(line, '\n', '\r')
     elif mode == 2:
             import re
-            temp = re.sub("\r(?!\n)|(?<!\r)\n", "\r\n", temp)
-    return temp
+            line = re.sub("\r(?!\n)|(?<!\r)\n", "\r\n", line)
+    return line
 
 
 def detect_mode(line, default):
@@ -254,13 +267,13 @@
     return _(u'just now')
 
 
-def credentials_hidder(uri):
+def uri_filter(uri):
     """
     Removes user:password from given url string
     
     :param uri:
     :rtype: unicode
-    :returns: filtered list of strings    
+    :returns: filtered list of strings  
     """
     if not uri:
         return ''
@@ -284,3 +297,19 @@
         host, port = uri[:cred_pos], uri[cred_pos + 1:]
 
     return filter(None, [proto, host, port])
+
+
+def credentials_filter(uri):
+    """
+    Returns a url with removed credentials
+    
+    :param uri:
+    """
+
+    uri = uri_filter(uri)
+    #check if we have port
+    if len(uri) > 2 and uri[2]:
+        uri[2] = ':' + uri[2]
+
+    return ''.join(uri)
+
--- a/rhodecode/lib/base.py	Thu Jun 09 14:04:55 2011 +0200
+++ b/rhodecode/lib/base.py	Thu Jun 09 15:12:12 2011 +0200
@@ -2,8 +2,11 @@
 
 Provides the BaseController class for subclassing.
 """
-from pylons import config, tmpl_context as c, request, session
+import logging
+
+from pylons import config, tmpl_context as c, request, session, url
 from pylons.controllers import WSGIController
+from pylons.controllers.util import redirect
 from pylons.templating import render_mako as render
 
 from rhodecode import __version__
@@ -14,6 +17,7 @@
 from rhodecode import BACKENDS
 from rhodecode.model.db import Repository
 
+log = logging.getLogger(__name__)
 
 class BaseController(WSGIController):
 
@@ -63,13 +67,16 @@
         super(BaseRepoController, self).__before__()
         if c.repo_name:
 
-            c.rhodecode_repo = Repository.by_repo_name(c.repo_name).scm_instance
+            c.rhodecode_db_repo = Repository.by_repo_name(c.repo_name)
+            c.rhodecode_repo = c.rhodecode_db_repo.scm_instance
+
+            if c.rhodecode_repo is None:
+                log.error('%s this repository is present in database but it '
+                          'cannot be created as an scm instance', c.repo_name)
 
-            if c.rhodecode_repo is not None:
-                c.repository_followers = \
-                    self.scm_model.get_followers(c.repo_name)
-                c.repository_forks = self.scm_model.get_forks(c.repo_name)
-            else:
-                c.repository_followers = 0
-                c.repository_forks = 0
+                redirect(url('home'))
 
+            c.repository_followers = \
+                self.scm_model.get_followers(c.repo_name)
+            c.repository_forks = self.scm_model.get_forks(c.repo_name)
+
--- a/rhodecode/lib/helpers.py	Thu Jun 09 14:04:55 2011 +0200
+++ b/rhodecode/lib/helpers.py	Thu Jun 09 15:12:12 2011 +0200
@@ -321,7 +321,7 @@
 # SCM FILTERS available via h.
 #==============================================================================
 from vcs.utils import author_name, author_email
-from rhodecode.lib import credentials_hidder, age as _age
+from rhodecode.lib import credentials_filter, age as _age
 
 age = lambda  x:_age(x)
 capitalize = lambda x: x.capitalize()
@@ -329,7 +329,7 @@
 email_or_none = lambda x: email(x) if email(x) != x else None
 person = lambda x: author_name(x)
 short_id = lambda x: x[:12]
-hide_credentials = lambda x: ''.join(credentials_hidder(x))
+hide_credentials = lambda x: ''.join(credentials_filter(x))
 
 def bool2icon(value):
     """Returns True/False values represented as small html image of true/false
--- a/rhodecode/model/scm.py	Thu Jun 09 14:04:55 2011 +0200
+++ b/rhodecode/model/scm.py	Thu Jun 09 15:12:12 2011 +0200
@@ -112,7 +112,11 @@
                 continue
 
 
-
+            if not scmr:
+                log.error('%s this repository is present in database but it '
+                          'cannot be created as an scm instance',
+                          dbr.repo_name)
+                continue
 
 
             last_change = scmr.last_change
--- a/rhodecode/tests/test_models.py	Thu Jun 09 14:04:55 2011 +0200
+++ b/rhodecode/tests/test_models.py	Thu Jun 09 15:12:12 2011 +0200
@@ -0,0 +1,2 @@
+import unittest
+from rhodecode.tests import *
--- a/test.ini	Thu Jun 09 14:04:55 2011 +0200
+++ b/test.ini	Thu Jun 09 15:12:12 2011 +0200
@@ -140,8 +140,8 @@
 #########################################################
 ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG    ###
 #########################################################
-#sqlalchemy.db1.url = sqlite:///%(here)s/test.db
-sqlalchemy.db1.url = postgresql://postgres:qwe@localhost/rhodecode_tests
+sqlalchemy.db1.url = sqlite:///%(here)s/test.db
+#sqlalchemy.db1.url = postgresql://postgres:qwe@localhost/rhodecode_tests
 #sqlalchemy.db1.echo = False
 #sqlalchemy.db1.pool_recycle = 3600
 sqlalchemy.convert_unicode = true
@@ -171,6 +171,18 @@
 qualname = routes.middleware
 # "level = DEBUG" logs the route matched and routing variables.
 
+[logger_beaker]
+level = DEBUG
+handlers = 
+qualname = beaker.container
+propagate = 1
+
+[logger_templates]
+level = INFO
+handlers = 
+qualname = pylons.templating
+propagate = 1
+
 [logger_rhodecode]
 level = ERROR
 handlers = console