diff --git a/rhodecode/controllers/admin/ldap_settings.py b/rhodecode/controllers/admin/ldap_settings.py --- a/rhodecode/controllers/admin/ldap_settings.py +++ b/rhodecode/controllers/admin/ldap_settings.py @@ -123,7 +123,6 @@ class LdapSettingsController(BaseControl except formencode.Invalid, errors: e = errors.error_dict or {} - return htmlfill.render( render('admin/ldap/ldap.html'), defaults=errors.value, diff --git a/rhodecode/controllers/files.py b/rhodecode/controllers/files.py --- a/rhodecode/controllers/files.py +++ b/rhodecode/controllers/files.py @@ -248,6 +248,8 @@ class FilesController(BaseRepoController revision='tip')) try: + # decoding here will force that we have proper encoded values + # in any other case this will throw exceptions and deny commit content = content.encode('utf8') message = message.encode('utf8') path = f_path.encode('utf8') @@ -263,7 +265,6 @@ class FilesController(BaseRepoController except Exception, e: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error') - raise return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) diff --git a/rhodecode/lib/__init__.py b/rhodecode/lib/__init__.py --- a/rhodecode/lib/__init__.py +++ b/rhodecode/lib/__init__.py @@ -24,7 +24,6 @@ # along with this program. If not, see . - def __get_lem(): from pygments import lexers from string import lower @@ -60,12 +59,13 @@ def __get_lem(): # extensions will index it's content LANGUAGES_EXTENSIONS_MAP = __get_lem() -#Additional mappings that are not present in the pygments lexers +# Additional mappings that are not present in the pygments lexers # NOTE: that this will overide any mappings in LANGUAGES_EXTENSIONS_MAP ADDITIONAL_MAPPINGS = {'xaml': 'XAML'} LANGUAGES_EXTENSIONS_MAP.update(ADDITIONAL_MAPPINGS) + def str2bool(_str): """ returs True/False value from given string, it tries to translate the @@ -82,6 +82,7 @@ def str2bool(_str): _str = str(_str).strip().lower() return _str in ('t', 'true', 'y', 'yes', 'on', '1') + def convert_line_endings(temp, mode): from string import replace #modes: 0 - Unix, 1 - Mac, 2 - DOS @@ -98,6 +99,15 @@ def convert_line_endings(temp, mode): def detect_mode(line, default): + """ + Detects line break for given line, if line break couldn't be found + given default value is returned + + :param line: str line + :param default: default + :rtype: int + :return: value of line end on of 0 - Unix, 1 - Mac, 2 - DOS + """ if line.endswith('\r\n'): return 2 elif line.endswith('\n'): @@ -107,6 +117,7 @@ def detect_mode(line, default): else: return default + def generate_api_key(username, salt=None): """ Generates unique API key for given username,if salt is not given @@ -151,7 +162,7 @@ def engine_from_config(configuration, pr """ Custom engine_from_config functions that makes sure we use NullPool for file based sqlite databases. This prevents errors on sqlite. - + """ from sqlalchemy import engine_from_config as efc from sqlalchemy.pool import NullPool @@ -159,8 +170,6 @@ def engine_from_config(configuration, pr url = configuration[prefix + 'url'] if url.startswith('sqlite'): - kwargs.update({'poolclass':NullPool}) + kwargs.update({'poolclass': NullPool}) return efc(configuration, prefix, **kwargs) - - diff --git a/rhodecode/lib/app_globals.py b/rhodecode/lib/app_globals.py --- a/rhodecode/lib/app_globals.py +++ b/rhodecode/lib/app_globals.py @@ -3,6 +3,7 @@ from beaker.cache import CacheManager from beaker.util import parse_cache_config_options + class Globals(object): """Globals acts as a container for objects available throughout the life of the application diff --git a/rhodecode/lib/auth.py b/rhodecode/lib/auth.py --- a/rhodecode/lib/auth.py +++ b/rhodecode/lib/auth.py @@ -203,7 +203,7 @@ def authenticate(username, password): password) log.debug('Got ldap DN response %s', user_dn) - get_ldap_attr = lambda k:ldap_attrs.get(ldap_settings\ + get_ldap_attr = lambda k: ldap_attrs.get(ldap_settings\ .get(k), [''])[0] user_attrs = { diff --git a/rhodecode/lib/backup_manager.py b/rhodecode/lib/backup_manager.py --- a/rhodecode/lib/backup_manager.py +++ b/rhodecode/lib/backup_manager.py @@ -1,8 +1,15 @@ -#!/usr/bin/env python -# encoding: utf-8 -# mercurial repository backup manager -# Copyright (C) 2009-2011 Marcin Kuzminski +# -*- coding: utf-8 -*- +""" + rhodecode.lib.backup_manager + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Mercurial repositories backup manager, it allows to backups all + repositories and send it to backup server using RSA key via ssh. + + :created_on: Feb 28, 2010 + :copyright: (c) 2010 by marcink. + :license: LICENSE_NAME, see LICENSE_FILE for more details. +""" # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -16,22 +23,18 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -""" -Created on Feb 28, 2010 -Mercurial repositories backup manager -@author: marcink -""" - +import os +import sys import logging import tarfile -import os import datetime -import sys import subprocess + logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)-5.5s %(message)s") + class BackupManager(object): def __init__(self, repos_location, rsa_key, backup_server): today = datetime.datetime.now().weekday() + 1 @@ -46,7 +49,6 @@ class BackupManager(object): logging.info('starting backup for %s', self.repos_path) logging.info('backup target %s', self.backup_file_path) - def get_id_rsa(self, rsa_key): if not os.path.isfile(rsa_key): logging.error('Could not load id_rsa key file in %s', rsa_key) @@ -69,14 +71,12 @@ class BackupManager(object): tar.close() logging.info('finished backup of mercurial repositories') - - def transfer_files(self): params = { 'id_rsa_key': self.id_rsa_path, - 'backup_file':os.path.join(self.backup_file_path, + 'backup_file': os.path.join(self.backup_file_path, self.backup_file_name), - 'backup_server':self.backup_server + 'backup_server': self.backup_server } cmd = ['scp', '-l', '40000', '-i', '%(id_rsa_key)s' % params, '%(backup_file)s' % params, @@ -85,13 +85,10 @@ class BackupManager(object): subprocess.call(cmd) logging.info('Transfered file %s to %s', self.backup_file_name, cmd[4]) - def rm_file(self): logging.info('Removing file %s', self.backup_file_name) os.remove(os.path.join(self.backup_file_path, self.backup_file_name)) - - if __name__ == "__main__": repo_location = '/home/repo_path' diff --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py --- a/rhodecode/lib/base.py +++ b/rhodecode/lib/base.py @@ -15,6 +15,7 @@ from rhodecode.model import meta from rhodecode.model.scm import ScmModel from rhodecode import BACKENDS + class BaseController(WSGIController): def __before__(self): @@ -36,7 +37,7 @@ class BaseController(WSGIController): # the request is routed to. This routing information is # available in environ['pylons.routes_dict'] try: - #putting this here makes sure that we update permissions every time + # putting this here makes sure that we update permissions each time api_key = request.GET.get('api_key') user_id = getattr(session.get('rhodecode_user'), 'user_id', None) self.rhodecode_user = c.rhodecode_user = AuthUser(user_id, api_key) @@ -66,7 +67,8 @@ class BaseRepoController(BaseController) r, dbrepo = self.scm_model.get(c.repo_name, retval='repo') if r is not None: - c.repository_followers = self.scm_model.get_followers(c.repo_name) + c.repository_followers = \ + self.scm_model.get_followers(c.repo_name) c.repository_forks = self.scm_model.get_forks(c.repo_name) else: c.repository_followers = 0 @@ -74,6 +76,6 @@ class BaseRepoController(BaseController) # Since RhodeCode uses heavy memory caching we make a deepcopy # of object taken from cache. This way we lose reference to cached - # instance in memory and keep it relatively small even for + # instance in memory and keep it relatively small even for # very large number of changesets c.rhodecode_repo = copy.copy(r) diff --git a/rhodecode/lib/colored_formatter.py b/rhodecode/lib/colored_formatter.py --- a/rhodecode/lib/colored_formatter.py +++ b/rhodecode/lib/colored_formatter.py @@ -9,14 +9,15 @@ COLOR_SEQ = "\033[1;%dm" BOLD_SEQ = "\033[1m" COLORS = { - 'CRITICAL': MAGENTA, # level 50 - 'ERROR': RED, # level 40 - 'WARNING': CYAN, # level 30 - 'INFO': GREEN, # level 20 - 'DEBUG': BLUE, # level 10 - 'SQL' : YELLOW + 'CRITICAL': MAGENTA, + 'ERROR': RED, + 'WARNING': CYAN, + 'INFO': GREEN, + 'DEBUG': BLUE, + 'SQL': YELLOW } + def one_space_trim(s): if s.find(" ") == -1: return s @@ -24,6 +25,7 @@ def one_space_trim(s): s = s.replace(' ', ' ') return one_space_trim(s) + def format_sql(sql): sql = sql.replace('\n', '') sql = one_space_trim(sql) @@ -43,6 +45,7 @@ def format_sql(sql): .replace('DELETE', '\n\tDELETE') return sql + class ColorFormatter(logging.Formatter): def __init__(self, *args, **kwargs): diff --git a/rhodecode/lib/exceptions.py b/rhodecode/lib/exceptions.py --- a/rhodecode/lib/exceptions.py +++ b/rhodecode/lib/exceptions.py @@ -1,8 +1,14 @@ -#!/usr/bin/env python -# encoding: utf-8 -# Custom Exceptions modules -# Copyright (C) 2009-2011 Marcin Kuzminski -# +# -*- coding: utf-8 -*- +""" + rhodecode.lib.exceptions + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Set of custom exceptions used in RhodeCode + + :created_on: Nov 17, 2010 + :copyright: (c) 2010 by marcink. + :license: LICENSE_NAME, see LICENSE_FILE for more details. +""" # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -15,16 +21,27 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -""" -Created on Nov 17, 2010 -Custom Exceptions modules -@author: marcink -""" + + +class LdapUsernameError(Exception): + pass + + +class LdapPasswordError(Exception): + pass + -class LdapUsernameError(Exception):pass -class LdapPasswordError(Exception):pass -class LdapConnectionError(Exception):pass -class LdapImportError(Exception):pass +class LdapConnectionError(Exception): + pass + + +class LdapImportError(Exception): + pass -class DefaultUserException(Exception):pass -class UserOwnsReposException(Exception):pass + +class DefaultUserException(Exception): + pass + + +class UserOwnsReposException(Exception): + pass diff --git a/rhodecode/lib/hooks.py b/rhodecode/lib/hooks.py --- a/rhodecode/lib/hooks.py +++ b/rhodecode/lib/hooks.py @@ -32,6 +32,7 @@ from mercurial.node import nullrev from rhodecode.lib import helpers as h from rhodecode.lib.utils import action_logger + def repo_size(ui, repo, hooktype=None, **kwargs): """Presents size of repository after push @@ -63,6 +64,7 @@ def repo_size(ui, repo, hooktype=None, * sys.stdout.write('Repository size .hg:%s repo:%s total:%s\n' \ % (size_hg_f, size_root_f, size_total_f)) + def log_pull_action(ui, repo, **kwargs): """Logs user last pull action @@ -79,6 +81,7 @@ def log_pull_action(ui, repo, **kwargs): return 0 + def log_push_action(ui, repo, **kwargs): """Maps user last push action to new changeset id, from mercurial diff --git a/rhodecode/lib/pidlock.py b/rhodecode/lib/pidlock.py --- a/rhodecode/lib/pidlock.py +++ b/rhodecode/lib/pidlock.py @@ -1,13 +1,16 @@ -import os, time +import os import sys +import time +import errno + from warnings import warn from multiprocessing.util import Finalize -import errno from rhodecode import __platform__, PLATFORM_WIN if __platform__ in PLATFORM_WIN: import ctypes + def kill(pid): """kill function for Win32""" kernel32 = ctypes.windll.kernel32 @@ -17,7 +20,9 @@ if __platform__ in PLATFORM_WIN: else: kill = os.kill -class LockHeld(Exception):pass + +class LockHeld(Exception): + pass class DaemonLock(object): @@ -34,8 +39,9 @@ class DaemonLock(object): def __init__(self, file=None, callbackfn=None, desc='daemon lock', debug=False): - self.pidfile = file if file else os.path.join(os.path.dirname(__file__), - 'running.lock') + self.pidfile = file if file else os.path.join( + os.path.dirname(__file__), + 'running.lock') self.callbackfn = callbackfn self.desc = desc self.debug = debug @@ -52,9 +58,10 @@ class DaemonLock(object): print 'leck held finilazing and running lock.release()' lock.release() - def lock(self): - """locking function, if lock is present it will raise LockHeld exception + """ + locking function, if lock is present it + will raise LockHeld exception """ lockname = '%s' % (os.getpid()) if self.debug: @@ -75,8 +82,8 @@ class DaemonLock(object): pidfile.close() if self.debug: - print 'lock file present running_pid: %s, checking for execution'\ - % running_pid + print ('lock file present running_pid: %s, ' + 'checking for execution') % running_pid # Now we check the PID from lock file matches to the current # process PID if running_pid: @@ -84,7 +91,8 @@ class DaemonLock(object): kill(running_pid, 0) except OSError, exc: if exc.errno in (errno.ESRCH, errno.EPERM): - print "Lock File is there but the program is not running" + print ("Lock File is there but" + " the program is not running") print "Removing lock file for the: %s" % running_pid self.release() else: @@ -122,6 +130,7 @@ class DaemonLock(object): def makelock(self, lockname, pidfile): """ this function will make an actual lock + :param lockname: acctual pid of file :param pidfile: the file to write the pid in """ diff --git a/rhodecode/lib/profiler.py b/rhodecode/lib/profiler.py --- a/rhodecode/lib/profiler.py +++ b/rhodecode/lib/profiler.py @@ -8,15 +8,16 @@ import threading from StringIO import StringIO + class ProfilingMiddleware(object): def __init__(self, app): self.lock = threading.Lock() self.app = app - def __call__(self, environ, start_response): with self.lock: profiler = cProfile.Profile() + def run_app(*a, **kw): self.response = self.app(environ, start_response) @@ -39,7 +40,8 @@ class ProfilingMiddleware(object): if resp.strip().startswith('<'): ## The profiling info is just appended to the response. ## Browsers don't mind this. - resp += '
'
+                resp += ('
')
                 resp += cgi.escape(out.getvalue(), True)
 
                 output = StringIO()
diff --git a/rhodecode/lib/smtp_mailer.py b/rhodecode/lib/smtp_mailer.py
--- a/rhodecode/lib/smtp_mailer.py
+++ b/rhodecode/lib/smtp_mailer.py
@@ -23,10 +23,12 @@ from email.mime.text import MIMEText
 from email.utils import formatdate
 from email import encoders
 
+
 class SmtpMailer(object):
     """SMTP mailer class
 
-    mailer = SmtpMailer(mail_from, user, passwd, mail_server, mail_port, ssl, tls)
+    mailer = SmtpMailer(mail_from, user, passwd, mail_server,
+                        mail_port, ssl, tls)
     mailer.send(recipients, subject, body, attachment_files)
 
     :param recipients might be a list of string or single string
@@ -70,7 +72,6 @@ class SmtpMailer(object):
         if self.user and self.passwd:
             smtp_serv.login(self.user, self.passwd)
 
-
         date_ = formatdate(localtime=True)
         msg = MIMEMultipart()
         msg['From'] = self.mail_from
@@ -93,16 +94,15 @@ class SmtpMailer(object):
             # sslerror is raised in tls connections on closing sometimes
             pass
 
-
-
     def __atach_files(self, msg, attachment_files):
         if isinstance(attachment_files, dict):
             for f_name, msg_file in attachment_files.items():
                 ctype, encoding = mimetypes.guess_type(f_name)
-                logging.info("guessing file %s type based on %s" , ctype, f_name)
+                logging.info("guessing file %s type based on %s", ctype,
+                             f_name)
                 if ctype is None or encoding is not None:
-                    # No guess could be made, or the file is encoded (compressed), so
-                    # use a generic bag-of-bits type.
+                    # No guess could be made, or the file is encoded
+                    # (compressed), so use a generic bag-of-bits type.
                     ctype = 'application/octet-stream'
                 maintype, subtype = ctype.split('/', 1)
                 if maintype == 'text':
diff --git a/rhodecode/lib/timerproxy.py b/rhodecode/lib/timerproxy.py
--- a/rhodecode/lib/timerproxy.py
+++ b/rhodecode/lib/timerproxy.py
@@ -5,12 +5,14 @@ log = logging.getLogger('timerproxy')
 
 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38)
 
+
 def color_sql(sql):
     COLOR_SEQ = "\033[1;%dm"
     COLOR_SQL = YELLOW
     normal = '\x1b[0m'
     return COLOR_SEQ % COLOR_SQL + sql + normal
 
+
 class TimerProxy(ConnectionProxy):
 
     def __init__(self):