Show More
@@ -123,7 +123,6 b' class LdapSettingsController(BaseControl' | |||||
123 | except formencode.Invalid, errors: |
|
123 | except formencode.Invalid, errors: | |
124 | e = errors.error_dict or {} |
|
124 | e = errors.error_dict or {} | |
125 |
|
125 | |||
126 |
|
||||
127 | return htmlfill.render( |
|
126 | return htmlfill.render( | |
128 | render('admin/ldap/ldap.html'), |
|
127 | render('admin/ldap/ldap.html'), | |
129 | defaults=errors.value, |
|
128 | defaults=errors.value, |
@@ -248,6 +248,8 b' class FilesController(BaseRepoController' | |||||
248 | revision='tip')) |
|
248 | revision='tip')) | |
249 |
|
249 | |||
250 | try: |
|
250 | try: | |
|
251 | # decoding here will force that we have proper encoded values | |||
|
252 | # in any other case this will throw exceptions and deny commit | |||
251 | content = content.encode('utf8') |
|
253 | content = content.encode('utf8') | |
252 | message = message.encode('utf8') |
|
254 | message = message.encode('utf8') | |
253 | path = f_path.encode('utf8') |
|
255 | path = f_path.encode('utf8') | |
@@ -263,7 +265,6 b' class FilesController(BaseRepoController' | |||||
263 | except Exception, e: |
|
265 | except Exception, e: | |
264 | log.error(traceback.format_exc()) |
|
266 | log.error(traceback.format_exc()) | |
265 | h.flash(_('Error occurred during commit'), category='error') |
|
267 | h.flash(_('Error occurred during commit'), category='error') | |
266 | raise |
|
|||
267 | return redirect(url('changeset_home', |
|
268 | return redirect(url('changeset_home', | |
268 | repo_name=c.repo_name, revision='tip')) |
|
269 | repo_name=c.repo_name, revision='tip')) | |
269 |
|
270 |
@@ -24,7 +24,6 b'' | |||||
24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25 |
|
25 | |||
26 |
|
26 | |||
27 |
|
||||
28 | def __get_lem(): |
|
27 | def __get_lem(): | |
29 | from pygments import lexers |
|
28 | from pygments import lexers | |
30 | from string import lower |
|
29 | from string import lower | |
@@ -66,6 +65,7 b" ADDITIONAL_MAPPINGS = {'xaml': 'XAML'}" | |||||
66 |
|
65 | |||
67 | LANGUAGES_EXTENSIONS_MAP.update(ADDITIONAL_MAPPINGS) |
|
66 | LANGUAGES_EXTENSIONS_MAP.update(ADDITIONAL_MAPPINGS) | |
68 |
|
67 | |||
|
68 | ||||
69 | def str2bool(_str): |
|
69 | def str2bool(_str): | |
70 | """ |
|
70 | """ | |
71 | returs True/False value from given string, it tries to translate the |
|
71 | returs True/False value from given string, it tries to translate the | |
@@ -82,6 +82,7 b' def str2bool(_str):' | |||||
82 | _str = str(_str).strip().lower() |
|
82 | _str = str(_str).strip().lower() | |
83 | return _str in ('t', 'true', 'y', 'yes', 'on', '1') |
|
83 | return _str in ('t', 'true', 'y', 'yes', 'on', '1') | |
84 |
|
84 | |||
|
85 | ||||
85 | def convert_line_endings(temp, mode): |
|
86 | def convert_line_endings(temp, mode): | |
86 | from string import replace |
|
87 | from string import replace | |
87 | #modes: 0 - Unix, 1 - Mac, 2 - DOS |
|
88 | #modes: 0 - Unix, 1 - Mac, 2 - DOS | |
@@ -98,6 +99,15 b' def convert_line_endings(temp, mode):' | |||||
98 |
|
99 | |||
99 |
|
100 | |||
100 | def detect_mode(line, default): |
|
101 | def detect_mode(line, default): | |
|
102 | """ | |||
|
103 | Detects line break for given line, if line break couldn't be found | |||
|
104 | given default value is returned | |||
|
105 | ||||
|
106 | :param line: str line | |||
|
107 | :param default: default | |||
|
108 | :rtype: int | |||
|
109 | :return: value of line end on of 0 - Unix, 1 - Mac, 2 - DOS | |||
|
110 | """ | |||
101 | if line.endswith('\r\n'): |
|
111 | if line.endswith('\r\n'): | |
102 | return 2 |
|
112 | return 2 | |
103 | elif line.endswith('\n'): |
|
113 | elif line.endswith('\n'): | |
@@ -107,6 +117,7 b' def detect_mode(line, default):' | |||||
107 | else: |
|
117 | else: | |
108 | return default |
|
118 | return default | |
109 |
|
119 | |||
|
120 | ||||
110 | def generate_api_key(username, salt=None): |
|
121 | def generate_api_key(username, salt=None): | |
111 | """ |
|
122 | """ | |
112 | Generates unique API key for given username,if salt is not given |
|
123 | Generates unique API key for given username,if salt is not given | |
@@ -162,5 +173,3 b' def engine_from_config(configuration, pr' | |||||
162 | kwargs.update({'poolclass':NullPool}) |
|
173 | kwargs.update({'poolclass': NullPool}) | |
163 |
|
174 | |||
164 | return efc(configuration, prefix, **kwargs) |
|
175 | return efc(configuration, prefix, **kwargs) | |
165 |
|
||||
166 |
|
@@ -3,6 +3,7 b'' | |||||
3 | from beaker.cache import CacheManager |
|
3 | from beaker.cache import CacheManager | |
4 | from beaker.util import parse_cache_config_options |
|
4 | from beaker.util import parse_cache_config_options | |
5 |
|
5 | |||
|
6 | ||||
6 | class Globals(object): |
|
7 | class Globals(object): | |
7 | """Globals acts as a container for objects available throughout the |
|
8 | """Globals acts as a container for objects available throughout the | |
8 | life of the application |
|
9 | life of the application |
@@ -1,8 +1,15 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | # -*- coding: utf-8 -*- | |
2 | # encoding: utf-8 |
|
2 | """ | |
3 | # mercurial repository backup manager |
|
3 | rhodecode.lib.backup_manager | |
4 | # Copyright (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
|
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
5 |
|
|
5 | ||
|
6 | Mercurial repositories backup manager, it allows to backups all | |||
|
7 | repositories and send it to backup server using RSA key via ssh. | |||
|
8 | ||||
|
9 | :created_on: Feb 28, 2010 | |||
|
10 | :copyright: (c) 2010 by marcink. | |||
|
11 | :license: LICENSE_NAME, see LICENSE_FILE for more details. | |||
|
12 | """ | |||
6 | # This program is free software: you can redistribute it and/or modify |
|
13 | # This program is free software: you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by |
|
14 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation, either version 3 of the License, or |
|
15 | # the Free Software Foundation, either version 3 of the License, or | |
@@ -16,22 +23,18 b'' | |||||
16 | # You should have received a copy of the GNU General Public License |
|
23 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 |
|
25 | |||
19 | """ |
|
26 | import os | |
20 | Created on Feb 28, 2010 |
|
27 | import sys | |
21 | Mercurial repositories backup manager |
|
|||
22 | @author: marcink |
|
|||
23 | """ |
|
|||
24 |
|
||||
25 |
|
28 | |||
26 | import logging |
|
29 | import logging | |
27 | import tarfile |
|
30 | import tarfile | |
28 | import os |
|
|||
29 | import datetime |
|
31 | import datetime | |
30 | import sys |
|
|||
31 | import subprocess |
|
32 | import subprocess | |
|
33 | ||||
32 | logging.basicConfig(level=logging.DEBUG, |
|
34 | logging.basicConfig(level=logging.DEBUG, | |
33 | format="%(asctime)s %(levelname)-5.5s %(message)s") |
|
35 | format="%(asctime)s %(levelname)-5.5s %(message)s") | |
34 |
|
36 | |||
|
37 | ||||
35 | class BackupManager(object): |
|
38 | class BackupManager(object): | |
36 | def __init__(self, repos_location, rsa_key, backup_server): |
|
39 | def __init__(self, repos_location, rsa_key, backup_server): | |
37 | today = datetime.datetime.now().weekday() + 1 |
|
40 | today = datetime.datetime.now().weekday() + 1 | |
@@ -46,7 +49,6 b' class BackupManager(object):' | |||||
46 | logging.info('starting backup for %s', self.repos_path) |
|
49 | logging.info('starting backup for %s', self.repos_path) | |
47 | logging.info('backup target %s', self.backup_file_path) |
|
50 | logging.info('backup target %s', self.backup_file_path) | |
48 |
|
51 | |||
49 |
|
||||
50 | def get_id_rsa(self, rsa_key): |
|
52 | def get_id_rsa(self, rsa_key): | |
51 | if not os.path.isfile(rsa_key): |
|
53 | if not os.path.isfile(rsa_key): | |
52 | logging.error('Could not load id_rsa key file in %s', rsa_key) |
|
54 | logging.error('Could not load id_rsa key file in %s', rsa_key) | |
@@ -69,8 +71,6 b' class BackupManager(object):' | |||||
69 | tar.close() |
|
71 | tar.close() | |
70 | logging.info('finished backup of mercurial repositories') |
|
72 | logging.info('finished backup of mercurial repositories') | |
71 |
|
73 | |||
72 |
|
||||
73 |
|
||||
74 | def transfer_files(self): |
|
74 | def transfer_files(self): | |
75 | params = { |
|
75 | params = { | |
76 | 'id_rsa_key': self.id_rsa_path, |
|
76 | 'id_rsa_key': self.id_rsa_path, | |
@@ -85,13 +85,10 b' class BackupManager(object):' | |||||
85 | subprocess.call(cmd) |
|
85 | subprocess.call(cmd) | |
86 | logging.info('Transfered file %s to %s', self.backup_file_name, cmd[4]) |
|
86 | logging.info('Transfered file %s to %s', self.backup_file_name, cmd[4]) | |
87 |
|
87 | |||
88 |
|
||||
89 | def rm_file(self): |
|
88 | def rm_file(self): | |
90 | logging.info('Removing file %s', self.backup_file_name) |
|
89 | logging.info('Removing file %s', self.backup_file_name) | |
91 | os.remove(os.path.join(self.backup_file_path, self.backup_file_name)) |
|
90 | os.remove(os.path.join(self.backup_file_path, self.backup_file_name)) | |
92 |
|
91 | |||
93 |
|
||||
94 |
|
||||
95 | if __name__ == "__main__": |
|
92 | if __name__ == "__main__": | |
96 |
|
93 | |||
97 | repo_location = '/home/repo_path' |
|
94 | repo_location = '/home/repo_path' |
@@ -15,6 +15,7 b' from rhodecode.model import meta' | |||||
15 | from rhodecode.model.scm import ScmModel |
|
15 | from rhodecode.model.scm import ScmModel | |
16 | from rhodecode import BACKENDS |
|
16 | from rhodecode import BACKENDS | |
17 |
|
17 | |||
|
18 | ||||
18 | class BaseController(WSGIController): |
|
19 | class BaseController(WSGIController): | |
19 |
|
20 | |||
20 | def __before__(self): |
|
21 | def __before__(self): | |
@@ -36,7 +37,7 b' class BaseController(WSGIController):' | |||||
36 | # the request is routed to. This routing information is |
|
37 | # the request is routed to. This routing information is | |
37 | # available in environ['pylons.routes_dict'] |
|
38 | # available in environ['pylons.routes_dict'] | |
38 | try: |
|
39 | try: | |
39 |
#putting this here makes sure that we update permissions e |
|
40 | # putting this here makes sure that we update permissions each time | |
40 | api_key = request.GET.get('api_key') |
|
41 | api_key = request.GET.get('api_key') | |
41 | user_id = getattr(session.get('rhodecode_user'), 'user_id', None) |
|
42 | user_id = getattr(session.get('rhodecode_user'), 'user_id', None) | |
42 | self.rhodecode_user = c.rhodecode_user = AuthUser(user_id, api_key) |
|
43 | self.rhodecode_user = c.rhodecode_user = AuthUser(user_id, api_key) | |
@@ -66,7 +67,8 b' class BaseRepoController(BaseController)' | |||||
66 | r, dbrepo = self.scm_model.get(c.repo_name, retval='repo') |
|
67 | r, dbrepo = self.scm_model.get(c.repo_name, retval='repo') | |
67 |
|
68 | |||
68 | if r is not None: |
|
69 | if r is not None: | |
69 |
c.repository_followers = |
|
70 | c.repository_followers = \ | |
|
71 | self.scm_model.get_followers(c.repo_name) | |||
70 | c.repository_forks = self.scm_model.get_forks(c.repo_name) |
|
72 | c.repository_forks = self.scm_model.get_forks(c.repo_name) | |
71 | else: |
|
73 | else: | |
72 | c.repository_followers = 0 |
|
74 | c.repository_followers = 0 |
@@ -9,14 +9,15 b' COLOR_SEQ = "\\033[1;%dm"' | |||||
9 | BOLD_SEQ = "\033[1m" |
|
9 | BOLD_SEQ = "\033[1m" | |
10 |
|
10 | |||
11 | COLORS = { |
|
11 | COLORS = { | |
12 |
'CRITICAL': MAGENTA, |
|
12 | 'CRITICAL': MAGENTA, | |
13 |
'ERROR': RED, |
|
13 | 'ERROR': RED, | |
14 |
'WARNING': CYAN, |
|
14 | 'WARNING': CYAN, | |
15 |
'INFO': GREEN, |
|
15 | 'INFO': GREEN, | |
16 |
'DEBUG': BLUE, |
|
16 | 'DEBUG': BLUE, | |
17 |
'SQL' |
|
17 | 'SQL': YELLOW | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
|
20 | ||||
20 | def one_space_trim(s): |
|
21 | def one_space_trim(s): | |
21 | if s.find(" ") == -1: |
|
22 | if s.find(" ") == -1: | |
22 | return s |
|
23 | return s | |
@@ -24,6 +25,7 b' def one_space_trim(s):' | |||||
24 | s = s.replace(' ', ' ') |
|
25 | s = s.replace(' ', ' ') | |
25 | return one_space_trim(s) |
|
26 | return one_space_trim(s) | |
26 |
|
27 | |||
|
28 | ||||
27 | def format_sql(sql): |
|
29 | def format_sql(sql): | |
28 | sql = sql.replace('\n', '') |
|
30 | sql = sql.replace('\n', '') | |
29 | sql = one_space_trim(sql) |
|
31 | sql = one_space_trim(sql) | |
@@ -43,6 +45,7 b' def format_sql(sql):' | |||||
43 | .replace('DELETE', '\n\tDELETE') |
|
45 | .replace('DELETE', '\n\tDELETE') | |
44 | return sql |
|
46 | return sql | |
45 |
|
47 | |||
|
48 | ||||
46 | class ColorFormatter(logging.Formatter): |
|
49 | class ColorFormatter(logging.Formatter): | |
47 |
|
50 | |||
48 | def __init__(self, *args, **kwargs): |
|
51 | def __init__(self, *args, **kwargs): |
@@ -1,8 +1,14 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | # -*- coding: utf-8 -*- | |
2 | # encoding: utf-8 |
|
2 | """ | |
3 | # Custom Exceptions modules |
|
3 | rhodecode.lib.exceptions | |
4 | # Copyright (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
|
4 | ~~~~~~~~~~~~~~~~~~~~~~~~ | |
5 | # |
|
5 | ||
|
6 | Set of custom exceptions used in RhodeCode | |||
|
7 | ||||
|
8 | :created_on: Nov 17, 2010 | |||
|
9 | :copyright: (c) 2010 by marcink. | |||
|
10 | :license: LICENSE_NAME, see LICENSE_FILE for more details. | |||
|
11 | """ | |||
6 | # This program is free software: you can redistribute it and/or modify |
|
12 | # This program is free software: you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by |
|
13 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation, either version 3 of the License, or |
|
14 | # the Free Software Foundation, either version 3 of the License, or | |
@@ -15,16 +21,27 b'' | |||||
15 | # |
|
21 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
22 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | """ |
|
24 | ||
19 | Created on Nov 17, 2010 |
|
25 | ||
20 | Custom Exceptions modules |
|
26 | class LdapUsernameError(Exception): | |
21 | @author: marcink |
|
27 | pass | |
22 | """ |
|
28 | ||
|
29 | ||||
|
30 | class LdapPasswordError(Exception): | |||
|
31 | pass | |||
|
32 | ||||
23 |
|
33 | |||
24 |
class Ldap |
|
34 | class LdapConnectionError(Exception): | |
25 | class LdapPasswordError(Exception):pass |
|
35 | pass | |
26 | class LdapConnectionError(Exception):pass |
|
36 | ||
27 | class LdapImportError(Exception):pass |
|
37 | ||
|
38 | class LdapImportError(Exception): | |||
|
39 | pass | |||
28 |
|
40 | |||
29 | class DefaultUserException(Exception):pass |
|
41 | ||
30 |
class User |
|
42 | class DefaultUserException(Exception): | |
|
43 | pass | |||
|
44 | ||||
|
45 | ||||
|
46 | class UserOwnsReposException(Exception): | |||
|
47 | pass |
@@ -32,6 +32,7 b' from mercurial.node import nullrev' | |||||
32 | from rhodecode.lib import helpers as h |
|
32 | from rhodecode.lib import helpers as h | |
33 | from rhodecode.lib.utils import action_logger |
|
33 | from rhodecode.lib.utils import action_logger | |
34 |
|
34 | |||
|
35 | ||||
35 | def repo_size(ui, repo, hooktype=None, **kwargs): |
|
36 | def repo_size(ui, repo, hooktype=None, **kwargs): | |
36 | """Presents size of repository after push |
|
37 | """Presents size of repository after push | |
37 |
|
38 | |||
@@ -63,6 +64,7 b' def repo_size(ui, repo, hooktype=None, *' | |||||
63 | sys.stdout.write('Repository size .hg:%s repo:%s total:%s\n' \ |
|
64 | sys.stdout.write('Repository size .hg:%s repo:%s total:%s\n' \ | |
64 | % (size_hg_f, size_root_f, size_total_f)) |
|
65 | % (size_hg_f, size_root_f, size_total_f)) | |
65 |
|
66 | |||
|
67 | ||||
66 | def log_pull_action(ui, repo, **kwargs): |
|
68 | def log_pull_action(ui, repo, **kwargs): | |
67 | """Logs user last pull action |
|
69 | """Logs user last pull action | |
68 |
|
70 | |||
@@ -79,6 +81,7 b' def log_pull_action(ui, repo, **kwargs):' | |||||
79 |
|
81 | |||
80 | return 0 |
|
82 | return 0 | |
81 |
|
83 | |||
|
84 | ||||
82 | def log_push_action(ui, repo, **kwargs): |
|
85 | def log_push_action(ui, repo, **kwargs): | |
83 | """Maps user last push action to new changeset id, from mercurial |
|
86 | """Maps user last push action to new changeset id, from mercurial | |
84 |
|
87 |
@@ -1,13 +1,16 b'' | |||||
1 |
import os |
|
1 | import os | |
2 | import sys |
|
2 | import sys | |
|
3 | import time | |||
|
4 | import errno | |||
|
5 | ||||
3 | from warnings import warn |
|
6 | from warnings import warn | |
4 | from multiprocessing.util import Finalize |
|
7 | from multiprocessing.util import Finalize | |
5 | import errno |
|
|||
6 |
|
8 | |||
7 | from rhodecode import __platform__, PLATFORM_WIN |
|
9 | from rhodecode import __platform__, PLATFORM_WIN | |
8 |
|
10 | |||
9 | if __platform__ in PLATFORM_WIN: |
|
11 | if __platform__ in PLATFORM_WIN: | |
10 | import ctypes |
|
12 | import ctypes | |
|
13 | ||||
11 | def kill(pid): |
|
14 | def kill(pid): | |
12 | """kill function for Win32""" |
|
15 | """kill function for Win32""" | |
13 | kernel32 = ctypes.windll.kernel32 |
|
16 | kernel32 = ctypes.windll.kernel32 | |
@@ -17,7 +20,9 b' if __platform__ in PLATFORM_WIN:' | |||||
17 | else: |
|
20 | else: | |
18 | kill = os.kill |
|
21 | kill = os.kill | |
19 |
|
22 | |||
20 | class LockHeld(Exception):pass |
|
23 | ||
|
24 | class LockHeld(Exception): | |||
|
25 | pass | |||
21 |
|
26 | |||
22 |
|
27 | |||
23 | class DaemonLock(object): |
|
28 | class DaemonLock(object): | |
@@ -34,7 +39,8 b' class DaemonLock(object):' | |||||
34 | def __init__(self, file=None, callbackfn=None, |
|
39 | def __init__(self, file=None, callbackfn=None, | |
35 | desc='daemon lock', debug=False): |
|
40 | desc='daemon lock', debug=False): | |
36 |
|
41 | |||
37 |
self.pidfile = file if file else os.path.join( |
|
42 | self.pidfile = file if file else os.path.join( | |
|
43 | os.path.dirname(__file__), | |||
38 |
|
|
44 | 'running.lock') | |
39 | self.callbackfn = callbackfn |
|
45 | self.callbackfn = callbackfn | |
40 | self.desc = desc |
|
46 | self.desc = desc | |
@@ -52,9 +58,10 b' class DaemonLock(object):' | |||||
52 | print 'leck held finilazing and running lock.release()' |
|
58 | print 'leck held finilazing and running lock.release()' | |
53 | lock.release() |
|
59 | lock.release() | |
54 |
|
60 | |||
55 |
|
||||
56 | def lock(self): |
|
61 | def lock(self): | |
57 | """locking function, if lock is present it will raise LockHeld exception |
|
62 | """ | |
|
63 | locking function, if lock is present it | |||
|
64 | will raise LockHeld exception | |||
58 | """ |
|
65 | """ | |
59 | lockname = '%s' % (os.getpid()) |
|
66 | lockname = '%s' % (os.getpid()) | |
60 | if self.debug: |
|
67 | if self.debug: | |
@@ -75,8 +82,8 b' class DaemonLock(object):' | |||||
75 | pidfile.close() |
|
82 | pidfile.close() | |
76 |
|
83 | |||
77 | if self.debug: |
|
84 | if self.debug: | |
78 |
print 'lock file present running_pid: %s, |
|
85 | print ('lock file present running_pid: %s, ' | |
79 | % running_pid |
|
86 | 'checking for execution') % running_pid | |
80 | # Now we check the PID from lock file matches to the current |
|
87 | # Now we check the PID from lock file matches to the current | |
81 | # process PID |
|
88 | # process PID | |
82 | if running_pid: |
|
89 | if running_pid: | |
@@ -84,7 +91,8 b' class DaemonLock(object):' | |||||
84 | kill(running_pid, 0) |
|
91 | kill(running_pid, 0) | |
85 | except OSError, exc: |
|
92 | except OSError, exc: | |
86 | if exc.errno in (errno.ESRCH, errno.EPERM): |
|
93 | if exc.errno in (errno.ESRCH, errno.EPERM): | |
87 |
print "Lock File is there but |
|
94 | print ("Lock File is there but" | |
|
95 | " the program is not running") | |||
88 | print "Removing lock file for the: %s" % running_pid |
|
96 | print "Removing lock file for the: %s" % running_pid | |
89 | self.release() |
|
97 | self.release() | |
90 | else: |
|
98 | else: | |
@@ -122,6 +130,7 b' class DaemonLock(object):' | |||||
122 | def makelock(self, lockname, pidfile): |
|
130 | def makelock(self, lockname, pidfile): | |
123 | """ |
|
131 | """ | |
124 | this function will make an actual lock |
|
132 | this function will make an actual lock | |
|
133 | ||||
125 | :param lockname: acctual pid of file |
|
134 | :param lockname: acctual pid of file | |
126 | :param pidfile: the file to write the pid in |
|
135 | :param pidfile: the file to write the pid in | |
127 | """ |
|
136 | """ |
@@ -8,15 +8,16 b' import threading' | |||||
8 |
|
8 | |||
9 | from StringIO import StringIO |
|
9 | from StringIO import StringIO | |
10 |
|
10 | |||
|
11 | ||||
11 | class ProfilingMiddleware(object): |
|
12 | class ProfilingMiddleware(object): | |
12 | def __init__(self, app): |
|
13 | def __init__(self, app): | |
13 | self.lock = threading.Lock() |
|
14 | self.lock = threading.Lock() | |
14 | self.app = app |
|
15 | self.app = app | |
15 |
|
16 | |||
16 |
|
||||
17 | def __call__(self, environ, start_response): |
|
17 | def __call__(self, environ, start_response): | |
18 | with self.lock: |
|
18 | with self.lock: | |
19 | profiler = cProfile.Profile() |
|
19 | profiler = cProfile.Profile() | |
|
20 | ||||
20 | def run_app(*a, **kw): |
|
21 | def run_app(*a, **kw): | |
21 | self.response = self.app(environ, start_response) |
|
22 | self.response = self.app(environ, start_response) | |
22 |
|
23 | |||
@@ -39,7 +40,8 b' class ProfilingMiddleware(object):' | |||||
39 | if resp.strip().startswith('<'): |
|
40 | if resp.strip().startswith('<'): | |
40 | ## The profiling info is just appended to the response. |
|
41 | ## The profiling info is just appended to the response. | |
41 | ## Browsers don't mind this. |
|
42 | ## Browsers don't mind this. | |
42 |
resp += '<pre style="text-align:left; |
|
43 | resp += ('<pre style="text-align:left; ' | |
|
44 | 'border-top: 4px dashed red; padding: 1em;">') | |||
43 | resp += cgi.escape(out.getvalue(), True) |
|
45 | resp += cgi.escape(out.getvalue(), True) | |
44 |
|
46 | |||
45 | output = StringIO() |
|
47 | output = StringIO() |
@@ -23,10 +23,12 b' from email.mime.text import MIMEText' | |||||
23 | from email.utils import formatdate |
|
23 | from email.utils import formatdate | |
24 | from email import encoders |
|
24 | from email import encoders | |
25 |
|
25 | |||
|
26 | ||||
26 | class SmtpMailer(object): |
|
27 | class SmtpMailer(object): | |
27 | """SMTP mailer class |
|
28 | """SMTP mailer class | |
28 |
|
29 | |||
29 |
mailer = SmtpMailer(mail_from, user, passwd, mail_server, |
|
30 | mailer = SmtpMailer(mail_from, user, passwd, mail_server, | |
|
31 | mail_port, ssl, tls) | |||
30 | mailer.send(recipients, subject, body, attachment_files) |
|
32 | mailer.send(recipients, subject, body, attachment_files) | |
31 |
|
33 | |||
32 | :param recipients might be a list of string or single string |
|
34 | :param recipients might be a list of string or single string | |
@@ -70,7 +72,6 b' class SmtpMailer(object):' | |||||
70 | if self.user and self.passwd: |
|
72 | if self.user and self.passwd: | |
71 | smtp_serv.login(self.user, self.passwd) |
|
73 | smtp_serv.login(self.user, self.passwd) | |
72 |
|
74 | |||
73 |
|
||||
74 | date_ = formatdate(localtime=True) |
|
75 | date_ = formatdate(localtime=True) | |
75 | msg = MIMEMultipart() |
|
76 | msg = MIMEMultipart() | |
76 | msg['From'] = self.mail_from |
|
77 | msg['From'] = self.mail_from | |
@@ -93,16 +94,15 b' class SmtpMailer(object):' | |||||
93 | # sslerror is raised in tls connections on closing sometimes |
|
94 | # sslerror is raised in tls connections on closing sometimes | |
94 | pass |
|
95 | pass | |
95 |
|
96 | |||
96 |
|
||||
97 |
|
||||
98 | def __atach_files(self, msg, attachment_files): |
|
97 | def __atach_files(self, msg, attachment_files): | |
99 | if isinstance(attachment_files, dict): |
|
98 | if isinstance(attachment_files, dict): | |
100 | for f_name, msg_file in attachment_files.items(): |
|
99 | for f_name, msg_file in attachment_files.items(): | |
101 | ctype, encoding = mimetypes.guess_type(f_name) |
|
100 | ctype, encoding = mimetypes.guess_type(f_name) | |
102 |
logging.info("guessing file %s type based on %s" |
|
101 | logging.info("guessing file %s type based on %s", ctype, | |
|
102 | f_name) | |||
103 | if ctype is None or encoding is not None: |
|
103 | if ctype is None or encoding is not None: | |
104 |
# No guess could be made, or the file is encoded |
|
104 | # No guess could be made, or the file is encoded | |
105 | # use a generic bag-of-bits type. |
|
105 | # (compressed), so use a generic bag-of-bits type. | |
106 | ctype = 'application/octet-stream' |
|
106 | ctype = 'application/octet-stream' | |
107 | maintype, subtype = ctype.split('/', 1) |
|
107 | maintype, subtype = ctype.split('/', 1) | |
108 | if maintype == 'text': |
|
108 | if maintype == 'text': |
@@ -5,12 +5,14 b" log = logging.getLogger('timerproxy')" | |||||
5 |
|
5 | |||
6 | BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38) |
|
6 | BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38) | |
7 |
|
7 | |||
|
8 | ||||
8 | def color_sql(sql): |
|
9 | def color_sql(sql): | |
9 | COLOR_SEQ = "\033[1;%dm" |
|
10 | COLOR_SEQ = "\033[1;%dm" | |
10 | COLOR_SQL = YELLOW |
|
11 | COLOR_SQL = YELLOW | |
11 | normal = '\x1b[0m' |
|
12 | normal = '\x1b[0m' | |
12 | return COLOR_SEQ % COLOR_SQL + sql + normal |
|
13 | return COLOR_SEQ % COLOR_SQL + sql + normal | |
13 |
|
14 | |||
|
15 | ||||
14 | class TimerProxy(ConnectionProxy): |
|
16 | class TimerProxy(ConnectionProxy): | |
15 |
|
17 | |||
16 | def __init__(self): |
|
18 | def __init__(self): |
General Comments 0
You need to be logged in to leave comments.
Login now