diff --git a/rhodecode/lib/__init__.py b/rhodecode/lib/__init__.py --- a/rhodecode/lib/__init__.py +++ b/rhodecode/lib/__init__.py @@ -25,19 +25,21 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. -def str2bool(v): - if isinstance(v, (str, unicode)): - obj = v.strip().lower() - if obj in ['true', 'yes', 'on', 'y', 't', '1']: - return True - elif obj in ['false', 'no', 'off', 'n', 'f', '0']: - return False - else: - if not safe: - raise ValueError("String is not true/false: %r" % obj) - return bool(obj) +def str2bool(s): + if s is None: + return False + if s in (True, False): + return s + s = str(s).strip().lower() + return s in ('t', 'true', 'y', 'yes', 'on', '1') def generate_api_key(username, salt=None): + """ + Generates uniq API key for given username + + :param username: username as string + :param salt: salt to hash generate KEY + """ from tempfile import _RandomNameSequence import hashlib @@ -45,3 +47,21 @@ def generate_api_key(username, salt=None salt = _RandomNameSequence().next() return hashlib.sha1(username + salt).hexdigest() + +def safe_unicode(str): + """ + safe unicode function. In case of UnicodeDecode error we try to return + unicode with errors replace, if this fails we return unicode with + string_escape decoding + """ + + try: + u_str = unicode(str) + except UnicodeDecodeError: + try: + u_str = unicode(str, 'utf-8', 'replace') + except UnicodeDecodeError: + #incase we have a decode error just represent as byte string + u_str = unicode(str(str).encode('string_escape')) + + return u_str diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -8,6 +8,7 @@ import hashlib import StringIO import urllib +from datetime import datetime from pygments.formatters import HtmlFormatter from pygments import highlight as code_highlight from pylons import url, request, config @@ -38,7 +39,8 @@ from rhodecode.lib.utils import repo_nam from rhodecode.lib import str2bool def _reset(name, value=None, id=NotGiven, type="reset", **attrs): - """Reset button + """ + Reset button """ _set_input_attrs(attrs, type, name, value) _set_id_attr(attrs, id, name) @@ -380,8 +382,6 @@ def _age(curdate): if not curdate: return '' - from datetime import timedelta, datetime - agescales = [("year", 3600 * 24 * 365), ("month", 3600 * 24 * 30), ("day", 3600 * 24), @@ -671,22 +671,6 @@ class RepoPage(Page): list.__init__(self, self.items) -def safe_unicode(str): - """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: - try: - u_str = unicode(str, 'utf-8', 'replace') - except UnicodeDecodeError: - #incase we have a decode error just represent as byte string - u_str = unicode(str(str).encode('string_escape')) - - return u_str - def changed_tooltip(nodes): if nodes: pref = ':
' diff --git a/rhodecode/lib/indexers/daemon.py b/rhodecode/lib/indexers/daemon.py --- a/rhodecode/lib/indexers/daemon.py +++ b/rhodecode/lib/indexers/daemon.py @@ -25,9 +25,14 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. +import os import sys -import os +import logging import traceback + +from shutil import rmtree +from time import mktime + from os.path import dirname as dn from os.path import join as jn @@ -37,15 +42,14 @@ sys.path.append(project_path) from rhodecode.model.scm import ScmModel -from rhodecode.lib.helpers import safe_unicode -from whoosh.index import create_in, open_dir -from shutil import rmtree +from rhodecode.lib import safe_unicode from rhodecode.lib.indexers import INDEX_EXTENSIONS, SCHEMA, IDX_NAME -from time import mktime from vcs.exceptions import ChangesetError, RepositoryError -import logging +from whoosh.index import create_in, open_dir + + log = logging.getLogger('whooshIndexer') # create logger