Mercurial > kallithea
diff rhodecode/lib/helpers.py @ 631:05528ad948c4 beta
Hacking for git support,and new faster repo scan
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 24 Oct 2010 16:15:40 +0200 |
parents | 5cc96df705b9 |
children | fd63782c4426 |
line wrap: on
line diff
--- a/rhodecode/lib/helpers.py Fri Oct 22 02:58:17 2010 +0200 +++ b/rhodecode/lib/helpers.py Sun Oct 24 16:15:40 2010 +0200 @@ -64,20 +64,20 @@ return str else: str = str.replace(replace * 2, replace) - return recursive_replace(str, replace) + return recursive_replace(str, replace) class _ToolTip(object): - + def __call__(self, tooltip_title, trim_at=50): """ Special function just to wrap our text into nice formatted autowrapped text :param tooltip_title: """ - + return wrap_paragraphs(escape(tooltip_title), trim_at)\ .replace('\n', '<br/>') - + def activate(self): """ Adds tooltip mechanism to the given Html all tooltips have to have @@ -85,7 +85,7 @@ Then a tooltip will be generated based on that All with yui js tooltip """ - + js = ''' YAHOO.util.Event.onDOMReady(function(){ function toolTipsId(){ @@ -190,19 +190,19 @@ }); }); - ''' + ''' return literal(js) tooltip = _ToolTip() class _FilesBreadCrumbs(object): - + def __call__(self, repo_name, rev, paths): url_l = [link_to(repo_name, url('files_home', repo_name=repo_name, revision=rev, f_path=''))] paths_l = paths.split('/') - + for cnt, p in enumerate(paths_l, 1): if p != '': url_l.append(link_to(p, url('files_home', @@ -236,12 +236,12 @@ pygmentize function for annotation :param filenode: """ - + color_dict = {} def gen_color(): """generator for getting 10k of evenly distibuted colors using hsv color and golden ratio. - """ + """ import colorsys n = 10000 golden_ratio = 0.618033988749895 @@ -252,21 +252,21 @@ h %= 1 HSV_tuple = [h, 0.95, 0.95] RGB_tuple = colorsys.hsv_to_rgb(*HSV_tuple) - yield map(lambda x:str(int(x * 256)), RGB_tuple) + yield map(lambda x:str(int(x * 256)), RGB_tuple) cgenerator = gen_color() - + def get_color_string(cs): if color_dict.has_key(cs): col = color_dict[cs] else: col = color_dict[cs] = cgenerator.next() return "color: rgb(%s)! important;" % (', '.join(col)) - + def url_func(changeset): tooltip_html = "<div style='font-size:0.8em'><b>Author:</b>" + \ - " %s<br/><b>Date:</b> %s</b><br/><b>Message:</b> %s<br/></div>" - + " %s<br/><b>Date:</b> %s</b><br/><b>Message:</b> %s<br/></div>" + tooltip_html = tooltip_html % (changeset.author, changeset.date, tooltip(changeset.message)) @@ -280,11 +280,11 @@ class_='tooltip', tooltip_title=tooltip_html ) - + uri += '\n' - return uri + return uri return literal(annotate_highlight(filenode, url_func, **kwargs)) - + def repo_name_slug(value): """Return slug of name of repository This function is called on each creation/modification @@ -292,7 +292,7 @@ """ slug = remove_formatting(value) slug = strip_tags(slug) - + for c in """=[]\;'"<>,/~!@#$%^&*()+{}|: """: slug = slug.replace(c, '-') slug = recursive_replace(slug, '-') @@ -305,7 +305,7 @@ if not isinstance(repo, BaseRepository): raise Exception('You must pass an Repository ' 'object as first argument got %s', type(repo)) - + try: cs = repo.get_changeset(rev) except RepositoryError: @@ -323,7 +323,7 @@ from mercurial import util from mercurial.templatefilters import age as _age, person as _person -age = lambda x:_age(x) +age = lambda x:x capitalize = lambda x: x.capitalize() date = lambda x: util.datestr(x) email = util.email @@ -333,8 +333,8 @@ 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: util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2") -rfc822date_notz = lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S") +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") @@ -358,8 +358,8 @@ baseurl_nossl = "http://www.gravatar.com/avatar/" baseurl_ssl = "https://secure.gravatar.com/avatar/" baseurl = baseurl_ssl if ssl_enabled else baseurl_nossl - - + + # construct the url gravatar_url = baseurl + hashlib.md5(email_address.lower()).hexdigest() + "?" gravatar_url += urllib.urlencode({'d':default, 's':str(size)}) @@ -370,7 +370,7 @@ """safe unicode function. In case of UnicodeDecode error we try to return unicode with errors replace, if this failes we return unicode with string_escape decoding """ - + try: u_str = unicode(str) except UnicodeDecodeError: @@ -379,5 +379,5 @@ except UnicodeDecodeError: #incase we have a decode error just represent as byte string u_str = unicode(str(str).encode('string_escape')) - + return u_str