# HG changeset patch # User Marcin Kuzminski # Date 1304434483 -7200 # Node ID c1516b35f91da452d8784c382570531012559a11 # Parent 6e1d24503383d5ef544f58c058adbbe01f170331 pep8ify diff -r 6e1d24503383 -r c1516b35f91d rhodecode/controllers/admin/ldap_settings.py --- a/rhodecode/controllers/admin/ldap_settings.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/controllers/admin/ldap_settings.py Tue May 03 16:54:43 2011 +0200 @@ -123,7 +123,6 @@ except formencode.Invalid, errors: e = errors.error_dict or {} - return htmlfill.render( render('admin/ldap/ldap.html'), defaults=errors.value, diff -r 6e1d24503383 -r c1516b35f91d rhodecode/controllers/files.py --- a/rhodecode/controllers/files.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/controllers/files.py Tue May 03 16:54:43 2011 +0200 @@ -248,6 +248,8 @@ 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 @@ 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 -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/__init__.py --- a/rhodecode/lib/__init__.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/lib/__init__.py Tue May 03 16:54:43 2011 +0200 @@ -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 @@ # 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 @@ _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 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 @@ 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 @@ """ 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 @@ url = configuration[prefix + 'url'] if url.startswith('sqlite'): - kwargs.update({'poolclass':NullPool}) + kwargs.update({'poolclass': NullPool}) return efc(configuration, prefix, **kwargs) - - diff -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/app_globals.py --- a/rhodecode/lib/app_globals.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/lib/app_globals.py Tue May 03 16:54:43 2011 +0200 @@ -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 -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/auth.py --- a/rhodecode/lib/auth.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/lib/auth.py Tue May 03 16:54:43 2011 +0200 @@ -203,7 +203,7 @@ 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 -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/backup_manager.py --- a/rhodecode/lib/backup_manager.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/lib/backup_manager.py Tue May 03 16:54:43 2011 +0200 @@ -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 @@ 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 @@ 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 @@ 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 -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/base.py --- a/rhodecode/lib/base.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/lib/base.py Tue May 03 16:54:43 2011 +0200 @@ -15,6 +15,7 @@ from rhodecode.model.scm import ScmModel from rhodecode import BACKENDS + class BaseController(WSGIController): def __before__(self): @@ -36,7 +37,7 @@ # 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 @@ 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 @@ # 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 -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/colored_formatter.py --- a/rhodecode/lib/colored_formatter.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/lib/colored_formatter.py Tue May 03 16:54:43 2011 +0200 @@ -9,14 +9,15 @@ 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 @@ 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 @@ .replace('DELETE', '\n\tDELETE') return sql + class ColorFormatter(logging.Formatter): def __init__(self, *args, **kwargs): diff -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/exceptions.py --- a/rhodecode/lib/exceptions.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/lib/exceptions.py Tue May 03 16:54:43 2011 +0200 @@ -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 -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/hooks.py --- a/rhodecode/lib/hooks.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/lib/hooks.py Tue May 03 16:54:43 2011 +0200 @@ -32,6 +32,7 @@ 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 @@ 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 @@ return 0 + def log_push_action(ui, repo, **kwargs): """Maps user last push action to new changeset id, from mercurial diff -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/pidlock.py --- a/rhodecode/lib/pidlock.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/lib/pidlock.py Tue May 03 16:54:43 2011 +0200 @@ -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 @@ else: kill = os.kill -class LockHeld(Exception):pass + +class LockHeld(Exception): + pass class DaemonLock(object): @@ -34,8 +39,9 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/profiler.py --- a/rhodecode/lib/profiler.py Tue May 03 16:20:06 2011 +0200 +++ b/rhodecode/lib/profiler.py Tue May 03 16:54:43 2011 +0200 @@ -8,15 +8,16 @@ 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 @@ 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 -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/smtp_mailer.py
--- a/rhodecode/lib/smtp_mailer.py	Tue May 03 16:20:06 2011 +0200
+++ b/rhodecode/lib/smtp_mailer.py	Tue May 03 16:54:43 2011 +0200
@@ -23,10 +23,12 @@
 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 @@
         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 @@
             # 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 -r 6e1d24503383 -r c1516b35f91d rhodecode/lib/timerproxy.py
--- a/rhodecode/lib/timerproxy.py	Tue May 03 16:20:06 2011 +0200
+++ b/rhodecode/lib/timerproxy.py	Tue May 03 16:54:43 2011 +0200
@@ -5,12 +5,14 @@
 
 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):