Changeset - fd63782c4426
[Not reviewed]
beta
0 10 0
Marcin Kuzminski - 15 years ago 2010-10-25 03:19:01
marcin@python-works.com
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Added simplegit middleware.
fixed deps
added scm type icon to main page
10 files changed with 66 insertions and 43 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/middleware.py
Show inline comments
 
@@ -5,12 +5,13 @@ from paste.registry import RegistryManag
 
from paste.urlparser import StaticURLParser
 
from paste.deploy.converters import asbool
 
from pylons.middleware import ErrorHandler, StatusCodeRedirect
 
from pylons.wsgiapp import PylonsApp
 
from routes.middleware import RoutesMiddleware
 
from rhodecode.lib.middleware.simplehg import SimpleHg
 
from rhodecode.lib.middleware.simplegit import SimpleGit
 
from rhodecode.lib.middleware.https_fixup import HttpsFixup
 
from rhodecode.config.environment import load_environment
 

	
 
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
 
    """Create a Pylons WSGI application and return it
 

	
 
@@ -40,12 +41,13 @@ def make_app(global_conf, full_stack=Tru
 
    app = RoutesMiddleware(app, config['routes.map'])
 
    app = SessionMiddleware(app, config)
 
    
 
    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
 
    
 
    app = SimpleHg(app, config)
 
    app = SimpleGit(app, config)
 
    
 
    if asbool(full_stack):
 
        # Handle Python exceptions
 
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
 

	
 
        # Display error documents for 401, 403, 404 status codes (and
rhodecode/lib/celerylib/tasks.py
Show inline comments
 
@@ -98,13 +98,13 @@ def get_commits_stats(repo_name, ts_min_
 
    author_key_cleaner = lambda k: person(k).replace('"', "") #for js data compatibilty
 

	
 
    commits_by_day_author_aggregate = {}
 
    commits_by_day_aggregate = {}
 
    repos_path = get_hg_ui_settings()['paths_root_path']
 
    p = os.path.join(repos_path, repo_name)
 
    repo = get_repo(get_scm(p)[0], p)
 
    repo = get_repo(p)
 

	
 
    skip_date_limit = True
 
    parse_limit = 250 #limit for single task changeset parsing optimal for
 
    last_rev = 0
 
    last_cs = None
 
    timegetter = itemgetter('time')
 
@@ -309,16 +309,14 @@ def __get_codes_stats(repo_name):
 
    'pas', 'patch', 'php', 'php3', 'php4', 'phtml', 'pm', 'py', 'rb', 'rst',
 
    's', 'sh', 'tpl', 'txt', 'vim', 'wss', 'xhtml', 'xml', 'xsl', 'xslt', 'yaws']
 

	
 

	
 
    repos_path = get_hg_ui_settings()['paths_root_path']
 
    p = os.path.join(repos_path, repo_name)
 
    repo = get_repo(get_scm(p)[0], p)
 

	
 
    repo = get_repo(p)
 
    tip = repo.get_changeset()
 

	
 
    code_stats = {}
 

	
 
    def aggregate(cs):
 
        for f in cs[2]:
 
            k = f.mimetype
 
            if f.extension in LANGUAGES_EXTENSIONS:
rhodecode/lib/helpers.py
Show inline comments
 
@@ -20,12 +20,13 @@ from webhelpers.html.tools import auto_l
 
from webhelpers.number import format_byte_size, format_bit_size
 
from webhelpers.pylonslib import Flash as _Flash
 
from webhelpers.pylonslib.secure_form import secure_form
 
from webhelpers.text import chop_at, collapse, convert_accented_entities, \
 
    convert_misc_entities, lchop, plural, rchop, remove_formatting, \
 
    replace_whitespace, urlify, truncate, wrap_paragraphs
 
from webhelpers.date import time_ago_in_words
 

	
 
#Custom helpers here :)
 
class _Link(object):
 
    '''
 
    Make a url based on label and url with help of url_for
 
    :param label:name of link    if not defined url is used
 
@@ -314,43 +315,56 @@ def get_changeset_safe(repo, rev):
 
    return cs
 

	
 

	
 
flash = _Flash()
 

	
 

	
 
#===============================================================================
 
#==============================================================================
 
# MERCURIAL FILTERS available via h.
 
#===============================================================================
 
#==============================================================================
 
from mercurial import util
 
from mercurial.templatefilters import age as _age, person as _person
 
from mercurial.templatefilters import person as _person
 

	
 

	
 

	
 
def _age(curdate):
 
    """turns a datetime into an age string."""
 

	
 
age = lambda  x:x
 
    from datetime import timedelta, datetime
 
    agescales = [("year", 3600 * 24 * 365),
 
             ("month", 3600 * 24 * 30),
 
             #("week", 3600 * 24 * 7),
 
             ("day", 3600 * 24),
 
             ("hour", 3600),
 
             ("minute", 60),
 
             ("second", 1)]
 

	
 
    age = datetime.now() - curdate
 
    age_seconds = (age.days * agescales[2][1]) + age.seconds
 

	
 
    pos = 1
 
    for scale in agescales:
 
        if scale[1] <= age_seconds:
 
            return time_ago_in_words(curdate, agescales[pos][0])
 
        pos += 1
 

	
 
age = lambda  x:_age(x)
 
capitalize = lambda x: x.capitalize()
 
date = lambda x: util.datestr(x)
 
email = util.email
 
email_or_none = lambda x: util.email(x) if util.email(x) != x else None
 
person = lambda x: _person(x)
 
hgdate = lambda  x: "%d %d" % x
 
isodate = lambda  x: util.datestr(x, '%Y-%m-%d %H:%M %1%2')
 
isodatesec = lambda  x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2')
 
localdate = lambda  x: (x[0], util.makedate()[1])
 
rfc822date = lambda  x: x#util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2")
 
rfc822date_notz = lambda  x: x#util.datestr(x, "%a, %d %b %Y %H:%M:%S")
 
rfc3339date = lambda  x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2")
 
time_ago = lambda x: util.datestr(_age(x), "%a, %d %b %Y %H:%M:%S %1%2")
 

	
 

	
 
#===============================================================================
 
#==============================================================================
 
# PERMS
 
#===============================================================================
 
#==============================================================================
 
from rhodecode.lib.auth import HasPermissionAny, HasPermissionAll, \
 
HasRepoPermissionAny, HasRepoPermissionAll
 

	
 
#===============================================================================
 
#==============================================================================
 
# GRAVATAR URL
 
#===============================================================================
 
#==============================================================================
 
import hashlib
 
import urllib
 
from pylons import request
 

	
 
def gravatar_url(email_address, size=30):
 
    ssl_enabled = 'https' == request.environ.get('HTTP_X_URL_SCHEME')
rhodecode/lib/middleware/simplegit.py
Show inline comments
 
@@ -14,12 +14,20 @@
 
# GNU General Public License for more details.
 
# 
 
# You should have received a copy of the GNU General Public License
 
# along with this program; if not, write to the Free Software
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
# MA  02110-1301, USA.
 
"""
 
Created on 2010-04-28
 

	
 
@author: marcink
 
SimpleGit middleware for handling git protocol request (push/clone etc.)
 
It's implemented with basic auth function
 
"""
 

	
 
from dulwich import server as dulserver
 

	
 
class SimpleGitUploadPackHandler(dulserver.UploadPackHandler):
 

	
 
    def handle(self):
 
        write = lambda x: self.proto.write_sideband(1, x)
 
@@ -51,28 +59,20 @@ dulserver.DEFAULT_HANDLERS = {
 
}
 

	
 
from dulwich.repo import Repo
 
from dulwich.web import HTTPGitApplication
 
from paste.auth.basic import AuthBasicAuthenticator
 
from paste.httpheaders import REMOTE_USER, AUTH_TYPE
 
from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware, \
 
    get_user_cached
 
from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware
 
from rhodecode.lib.utils import action_logger, is_git, invalidate_cache, \
 
    check_repo_fast
 
from rhodecode.model.user import UserModel
 
from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
 
import logging
 
import os
 
import traceback
 
"""
 
Created on 2010-04-28
 

	
 
@author: marcink
 
SimpleGit middleware for handling git protocol request (push/clone etc.)
 
It's implemented with basic auth function
 
"""
 

	
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 
class SimpleGit(object):
 

	
 
@@ -172,13 +172,13 @@ class SimpleGit(object):
 
        return gitserve
 

	
 
    def __get_environ_user(self, environ):
 
        return environ.get('REMOTE_USER')
 

	
 
    def __get_user(self, username):
 
        return get_user_cached(username)
 
        return UserModel().get_by_username(username, cache=True)
 

	
 
    def __get_action(self, environ):
 
        """
 
        Maps git request commands into a pull or push command.
 
        :param environ:
 
        """
rhodecode/public/css/style.css
Show inline comments
 
@@ -1007,13 +1007,13 @@ margin:0;
 
padding:0;
 
}
 
 
#content div.box table th {
 
background:#eee;
 
border-bottom:1px solid #ddd;
 
padding:10px;
 
padding:5px 0px 5px 5px;
 
}
 
 
#content div.box table th.left {
 
text-align:left;
 
}
 
rhodecode/public/images/icons/giticon.png
Show inline comments
 
binary diff not shown
Show images
rhodecode/templates/index.html
Show inline comments
 
@@ -52,12 +52,20 @@
 
            </thead>
 
                        <tbody>
 
					    %for cnt,repo in enumerate(c.repos_list):
 
					        %if h.HasRepoPermissionAny('repository.write','repository.read','repository.admin')(repo['name'],'main page check'):
 
					        <tr class="parity${cnt%2}">
 
					            <td>
 
					             %if repo['repo'].dbrepo.repo_type =='hg':
 
					               <img class="icon" alt="${_('Mercurial repository')}" src="/images/icons/hgicon.png"/>
 
					             %elif repo['repo'].dbrepo.repo_type =='git':
 
					               <img class="icon" alt="${_('Git repository')}" src="/images/icons/giticon.png"/>
 
					             %else:
 
					               
 
					             %endif 
 
					            
 
					             %if repo['repo'].dbrepo.private:
 
					                <img class="icon" alt="${_('private')}" src="/images/icons/lock.png"/>
 
					             %else:
 
					                <img class="icon" alt="${_('public')}" src="/images/icons/lock_open.png"/>
 
					             %endif  
 
					            ${h.link_to(repo['name'],
 
@@ -67,13 +75,14 @@
 
					            	<img class="icon" alt="${_('public')}"
 
					            	title="${_('Fork of')} ${repo['repo'].dbrepo.fork.repo_name}" 
 
					            	src="/images/icons/arrow_divide.png"/></a>
 
					            %endif
 
					            </td>
 
					            <td title="${repo['description']}">${h.truncate(repo['description'],60)}</td>
 
					            <td>${h.age(repo['last_change'])}</td>
 
					            <td><span class="tooltip" tooltip_title="${repo['last_change']}">
 
					                ${h.age(repo['last_change'])} </span></td>
 
					            <td>
 
					            	%if repo['rev']>=0:
 
					            	${h.link_to('r%s:%s' % (repo['rev'],repo['tip']),
 
					                h.url('changeset_home',repo_name=repo['name'],revision=repo['tip']),
 
					                class_="tooltip",
 
					                tooltip_title=h.tooltip(repo['last_msg']))}
rhodecode/templates/shortlog/shortlog_data.html
Show inline comments
 
@@ -10,13 +10,13 @@
 
		<th class="left">${_('tags')}</th>
 
		<th class="left">${_('links')}</th>
 
		
 
	</tr>
 
%for cnt,cs in enumerate(c.repo_changesets):
 
	<tr class="parity${cnt%2}">
 
		<td>${h.age(cs.date)} - ${h.rfc822date_notz(cs.date)} </td>
 
		<td>${h.age(cs.date)} - ${cs.date} </td>
 
		<td title="${cs.author}">${h.person(cs.author)}</td>
 
		<td>r${cs.revision}:${cs.short_id}</td>
 
		<td>
 
			${h.link_to(h.truncate(cs.message,60),
 
			h.url('changeset_home',repo_name=c.repo_name,revision=cs.short_id),
 
			title=cs.message)}
rhodecode/templates/summary/summary.html
Show inline comments
 
@@ -89,13 +89,13 @@ E.onDOMReady(function(e){
 
			
 
			 <div class="field">
 
			  <div class="label">
 
			      <label>${_('Last change')}:</label>
 
			  </div>
 
			  <div class="input-short">
 
			      ${h.age(c.repo_info.last_change)} - ${h.rfc822date_notz(c.repo_info.last_change)} 
 
			      ${h.age(c.repo_info.last_change)} - ${c.repo_info.last_change} 
 
			      ${_('by')} ${h.get_changeset_safe(c.repo_info,'tip').author} 
 
			      
 
			  </div>
 
			 </div>
 
			
 
			 <div class="field">
setup.py
Show inline comments
 
from rhodecode import get_version
 
import sys
 
py_version = sys.version_info
 

	
 
requirements = [
 
        "Pylons>=1.0.0",
 
        "SQLAlchemy>=0.6",
 
        "Mako>=0.3.2",
 
        "vcs==0.1.8",
 
        "SQLAlchemy>=0.6.4",
 
        "Mako>=0.3.5",
 
        "vcs==0.1.10",
 
        "pygments>=1.3.0",
 
        "mercurial>=1.6",
 
        "whoosh==1.0.0",
 
        "celery>=2.0.0",
 
        "mercurial==1.6.4",
 
        "whoosh==1.1.0",
 
        "celery==2.1.1",
 
        "py-bcrypt",
 
        "babel",
 
    ]
 

	
 
classifiers = ['Development Status :: 4 - Beta',
 
                   'Environment :: Web Environment',
0 comments (0 inline, 0 general)