-#
+# -*- 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):