Changeset - 3d1dd13887f9
[Not reviewed]
default
0 4 0
Marcin Kuzminski - 15 years ago 2010-05-22 02:20:26
marcin@python-works.com
invalidate the repo list also for online changes. Small fixes in LoginRequired decorator.
Cleaned hgwebdir config.
4 files changed with 6 insertions and 7 deletions:
0 comments (0 inline, 0 general)
hgwebdir.config
Show inline comments
 
[hooks]
 
#to do push with autoupdate
 
changegroup = hg update >&2
 

	
 
[extensions]
 
hgext.highlight=
 
#hgk=
 

	
 
[web]
 
push_ssl = false
 
allow_archive = gz zip bz2
 
allow_push = *
 
templates=/home/marcink/python_workspace/hg_app/pylons_app/templates/
 
style = monoblue_custom
 
pygments_style = trac
 
staticurl = /hg_static/
 
baseurl = /
 

	
 
[paths]
 
/ = /home/marcink/python_workspace/**
pylons_app/lib/auth.py
Show inline comments
 
@@ -62,37 +62,37 @@ def authfunc(environ, username, password
 
class  AuthUser(object):
 
    """
 
    A simple object that handles a mercurial username for authentication
 
    """
 
    username = 'Empty'
 
    is_authenticated = False
 
    is_admin = False
 
    permissions = set()
 
    group = set()
 
    
 
    def __init__(self):
 
        pass
 
    
 
#===============================================================================
 
# DECORATORS
 
#===============================================================================
 
class LoginRequired(object):
 
    """
 
    Must be logged in to execute this function else redirect to login page
 
    """
 
    def __init__(self):
 
        pass
 
    
 
    def __call__(self, func):
 
        log.info('Checking login required')
 
        user = session.get('hg_app_user', AuthUser())
 
        log.info('Checking login required for %s', user.username)
 
        
 
        @wraps(func)
 
        def _wrapper(*fargs, **fkwargs):
 
            user = session.get('hg_app_user', AuthUser())
 
            if user.is_authenticated:
 
                    log.info('user %s is authenticated', user.username)
 
                    func(*fargs)
 
            else:
 
                logging.info('user %s not authenticated', user.username)
 
                return redirect(url('login_home'))
 

	
 
        return _wrapper
pylons_app/lib/simplehg.py
Show inline comments
 
@@ -44,43 +44,44 @@ class SimpleHg(object):
 
                    AUTH_TYPE.update(environ, 'basic')
 
                    REMOTE_USER.update(environ, result)
 
                else:
 
                    return result.wsgi_application(environ, start_response)
 
            
 
            try:
 
                repo_name = environ['PATH_INFO'].split('/')[1]
 
            except:
 
                return HTTPNotFound()(environ, start_response)
 
            
 
            #since we wrap into hgweb, just reset the path
 
            environ['PATH_INFO'] = '/'
 
            self.baseui = make_ui()
 
            self.basepath = self.baseui.configitems('paths')[0][1]\
 
                                                            .replace('*', '')
 
            self.repo_path = os.path.join(self.basepath, repo_name)
 
            try:
 
                app = wsgiapplication(self._make_app)
 
            except Exception as e:
 
                return HTTPNotFound()(environ, start_response)
 
            
 
            """we know that some change was made to repositories and we should
 
            invalidate the cache to see the changes right away"""
 
            invalidate_cache('full_changelog', repo_name)
 
            invalidate_cache('cached_repo_list')
 
            return app(environ, start_response)            
 

	
 
    def _make_app(self):
 
        hgserve = hgweb(self.repo_path)
 
        return  self.load_web_settings(hgserve)
 
        
 
                
 
    def load_web_settings(self, hgserve):
 
        repoui = make_ui(os.path.join(self.repo_path, '.hg', 'hgrc'), False)
 
        #set the global ui for hgserve
 
        hgserve.repo.ui = self.baseui
 
        
 
        if repoui:
 
            #set the repository based config
 
            hgserve.repo.ui = repoui
 
            
 
        return hgserve
 

	
 

	
pylons_app/lib/utils.py
Show inline comments
 
@@ -70,52 +70,54 @@ def make_ui(path='hgwebdir.config', chec
 
                'hooks',
 
                'http_proxy',
 
                'smtp',
 
                'patch',
 
                'paths',
 
                'profiling',
 
                'server',
 
                'trusted',
 
                'ui',
 
                'web',
 
                ]
 

	
 
    baseui = ui.ui()
 
    cfg = config.config()
 
    cfg.read(path)
 
    if checkpaths:check_repo_dir(cfg.items('paths'))
 

	
 
    for section in sections:
 
        for k, v in cfg.items(section):
 
            baseui.setconfig(section, k, v)
 
    
 
    return baseui
 

	
 
def invalidate_cache(name, *args):
 
    """Invalidates given name cache"""
 
    
 
    from beaker.cache import region_invalidate
 
    log.info('INVALIDATING CACHE FOR %s', name)
 
    
 
    """propaget our arguments to make sure invalidation works. First
 
    """propagate our arguments to make sure invalidation works. First
 
    argument has to be the name of cached func name give to cache decorator
 
    without that the invalidation would not work"""
 
    tmp = [name]
 
    tmp.extend(args)
 
    args = tuple(tmp)
 
    
 
    if name == 'cached_repo_list':
 
        from pylons_app.lib.base import _get_repos_cached
 
        region_invalidate(_get_repos_cached, None, *args)
 
        
 
    if name == 'full_changelog':
 
        from pylons_app.controllers.changelog 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
 

	
 
    @LazyProperty
 
    def raw_id(self):
 
        """
 
        Returns raw string identifing this changeset, useful for web
0 comments (0 inline, 0 general)