diff rhodecode/lib/utils.py @ 1231:9f6560667743

fixes for stable
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 09 Apr 2011 17:13:15 +0200
parents 3d9da7893fdb
children bf263968da47
line wrap: on
line diff
--- a/rhodecode/lib/utils.py	Sat Apr 09 11:22:32 2011 +0200
+++ b/rhodecode/lib/utils.py	Sat Apr 09 17:13:15 2011 +0200
@@ -50,6 +50,7 @@
 
 log = logging.getLogger(__name__)
 
+
 def recursive_replace(str, replace=' '):
     """Recursive replace of given sign to just one instance
 
@@ -67,6 +68,7 @@
         str = str.replace(replace * 2, replace)
         return recursive_replace(str, replace)
 
+
 def repo_name_slug(value):
     """Return slug of name of repository
     This function is called on each creation/modification
@@ -86,10 +88,11 @@
 def get_repo_slug(request):
     return request.environ['pylons.routes_dict'].get('repo_name')
 
+
 def action_logger(user, action, repo, ipaddr='', sa=None):
     """
     Action logger for various actions made by users
-    
+
     :param user: user that made this action, can be a unique username string or
         object containing user_id attribute
     :param action: action to log, should be on of predefined unique actions for
@@ -98,7 +101,7 @@
         that action was made on
     :param ipaddr: optional ip address from what the action was made
     :param sa: optional sqlalchemy session
-    
+
     """
 
     if not sa:
@@ -113,7 +116,6 @@
         else:
             raise Exception('You have to provide user object or username')
 
-
         rm = RepoModel()
         if hasattr(repo, 'repo_id'):
             repo_obj = rm.get(repo.repo_id, cache=False)
@@ -124,7 +126,6 @@
         else:
             raise Exception('You have to provide repository to action logger')
 
-
         user_log = UserLog()
         user_log.user_id = user_obj.user_id
         user_log.action = action
@@ -142,6 +143,7 @@
         log.error(traceback.format_exc())
         sa.rollback()
 
+
 def get_repos(path, recursive=False, initial=False):
     """
     Scans given path for repos and return (name,(type,path)) tuple 
@@ -173,12 +175,14 @@
     Check given path for existence of directory
     :param repo_name:
     :param base_path:
-    
+
     :return False: if this directory is present
     """
-    if os.path.isdir(os.path.join(base_path, repo_name)):return False
+    if os.path.isdir(os.path.join(base_path, repo_name)):
+        return False
     return True
 
+
 def check_repo(repo_name, base_path, verify=True):
 
     repo_path = os.path.join(base_path, repo_name)
@@ -197,13 +201,17 @@
         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
+        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
+        if retries < 0:
+            raise IOError
         print complaint
 
 #propagated from mercurial documentation
@@ -218,11 +226,11 @@
                 'server', 'trusted',
                 'ui', 'web', ]
 
+
 def make_ui(read_from='file', path=None, checkpaths=True):
-    """
-    A function that will read python rc files or database
+    """A function that will read python rc files or database
     and make an mercurial ui object from read options
-    
+
     :param path: path to mercurial config file
     :param checkpaths: check the path
     :param read_from: read from 'file' or 'db'
@@ -247,7 +255,6 @@
                 log.debug('settings ui from file[%s]%s:%s', section, k, v)
                 baseui.setconfig(section, k, v)
 
-
     elif read_from == 'db':
         sa = meta.Session()
         ret = sa.query(RhodeCodeUi)\
@@ -276,6 +283,7 @@
     for k, v in hgsettings.items():
         config[k] = v
 
+
 def invalidate_cache(cache_key, *args):
     """Puts cache invalidation task into db for
     further global cache invalidation
@@ -287,18 +295,20 @@
         name = cache_key.split('get_repo_cached_')[-1]
         ScmModel().mark_for_invalidation(name)
 
+
 class EmptyChangeset(BaseChangeset):
     """
     An dummy empty changeset. It's possible to pass hash when creating
     an EmptyChangeset
     """
 
-    def __init__(self, cs='0' * 40):
+    def __init__(self, cs='0' * 40, repo=None):
         self._empty_cs = cs
         self.revision = -1
         self.message = ''
         self.author = ''
         self.date = ''
+        self.repository = repo
 
     @LazyProperty
     def raw_id(self):
@@ -350,6 +360,7 @@
                 sa.delete(repo)
                 sa.commit()
 
+
 class OrderedDict(dict, DictMixin):
 
     def __init__(self, *args, **kwds):
@@ -452,7 +463,7 @@
 
 #set cache regions for beaker so celery can utilise it
 def add_cache(settings):
-    cache_settings = {'regions':None}
+    cache_settings = {'regions': None}
     for key in settings.keys():
         for prefix in ['beaker.cache.', 'cache.']:
             if key.startswith(prefix):
@@ -477,6 +488,7 @@
                                                              'memory')
             beaker.cache.cache_regions[region] = region_settings
 
+
 def get_current_revision():
     """Returns tuple of (number, id) from repository containing this package
     or None if repository could not be found.
@@ -496,9 +508,10 @@
                       "was: %s" % err)
         return None
 
-#===============================================================================
+
+#==============================================================================
 # TEST FUNCTIONS AND CREATORS
-#===============================================================================
+#==============================================================================
 def create_test_index(repo_location, full_index):
     """Makes default test index
     :param repo_location:
@@ -521,6 +534,7 @@
     except LockHeld:
         pass
 
+
 def create_test_env(repos_test_path, config):
     """Makes a fresh database and
     install test repository into tmp dir
@@ -541,7 +555,8 @@
     ch.setLevel(logging.DEBUG)
 
     # create formatter
-    formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
+    formatter = logging.Formatter("%(asctime)s - %(name)s -"
+                                  " %(levelname)s - %(message)s")
 
     # add formatter to ch
     ch.setFormatter(formatter)
@@ -582,7 +597,6 @@
 #==============================================================================
 # PASTER COMMANDS
 #==============================================================================
-
 class BasePasterCommand(Command):
     """
     Abstract Base Class for paster commands.
@@ -609,7 +623,6 @@
         if log and isinstance(log, logging):
             log(msg)
 
-
     def run(self, args):
         """
         Overrides Command.run