Mercurial > kallithea
annotate rhodecode/lib/__init__.py @ 1514:87ec80c280bb beta
fixed issues with python2.5
added compat module to rhodecode to have one point of fetching backward incompatible libs.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 07 Oct 2011 02:51:18 +0200 |
parents | a2efbfe84067 |
children | da8f1d1b22de 70e646b2806a |
rev | line source |
---|---|
914
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
1 # -*- coding: utf-8 -*- |
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
2 """ |
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
3 rhodecode.lib.__init__ |
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
5 |
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
6 Some simple helper functions |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1199
diff
changeset
|
7 |
914
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
8 :created_on: Jan 5, 2011 |
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
9 :author: marcink |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1199
diff
changeset
|
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
914
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
12 """ |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
16 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1199
diff
changeset
|
17 # |
914
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
21 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1199
diff
changeset
|
22 # |
914
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
914
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
25 |
1302
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
26 def __get_lem(): |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
27 from pygments import lexers |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
28 from string import lower |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
29 from collections import defaultdict |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
30 |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
31 d = defaultdict(lambda: []) |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
32 |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
33 def __clean(s): |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
34 s = s.lstrip('*') |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
35 s = s.lstrip('.') |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
36 |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
37 if s.find('[') != -1: |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
38 exts = [] |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
39 start, stop = s.find('['), s.find(']') |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
40 |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
41 for suffix in s[start + 1:stop]: |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
42 exts.append(s[:s.find('[')] + suffix) |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
43 return map(lower, exts) |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
44 else: |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
45 return map(lower, [s]) |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
46 |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
47 for lx, t in sorted(lexers.LEXERS.items()): |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
48 m = map(__clean, t[-2]) |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
49 if m: |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
50 m = reduce(lambda x, y: x + y, m) |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
51 for ext in m: |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
52 desc = lx.replace('Lexer', '') |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
53 d[ext].append(desc) |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
54 |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
55 return dict(d) |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
56 |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
57 # language map is also used by whoosh indexer, which for those specified |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
58 # extensions will index it's content |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
59 LANGUAGES_EXTENSIONS_MAP = __get_lem() |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
60 |
1307 | 61 # Additional mappings that are not present in the pygments lexers |
1302
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
62 # NOTE: that this will overide any mappings in LANGUAGES_EXTENSIONS_MAP |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
63 ADDITIONAL_MAPPINGS = {'xaml': 'XAML'} |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
64 |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
65 LANGUAGES_EXTENSIONS_MAP.update(ADDITIONAL_MAPPINGS) |
f0e904651f21
moved LANGUAGE_EXTENSION_MAP to lib, and made whoosh indexer use the same map
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
66 |
1307 | 67 |
1223
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
68 def str2bool(_str): |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
69 """ |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
70 returs True/False value from given string, it tries to translate the |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
71 string into boolean |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
72 |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
73 :param _str: string value to translate into boolean |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
74 :rtype: boolean |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
75 :returns: boolean from given string |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
76 """ |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
77 if _str is None: |
1154
36fe593dfe4b
simplified str2bool, and moved safe_unicode out of helpers since it was not html specific function
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
78 return False |
1223
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
79 if _str in (True, False): |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
80 return _str |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
81 _str = str(_str).strip().lower() |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
82 return _str in ('t', 'true', 'y', 'yes', 'on', '1') |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
83 |
1307 | 84 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
85 def convert_line_endings(line, mode): |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
86 """ |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
87 Converts a given line "line end" accordingly to given mode |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
88 |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
89 Available modes are:: |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
90 0 - Unix |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
91 1 - Mac |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
92 2 - DOS |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
93 |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
94 :param line: given line to convert |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
95 :param mode: mode to convert to |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
96 :rtype: str |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
97 :return: converted line according to mode |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
98 """ |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
99 from string import replace |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
100 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
101 if mode == 0: |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
102 line = replace(line, '\r\n', '\n') |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
103 line = replace(line, '\r', '\n') |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
104 elif mode == 1: |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
105 line = replace(line, '\r\n', '\r') |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
106 line = replace(line, '\n', '\r') |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
107 elif mode == 2: |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
108 import re |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
109 line = re.sub("\r(?!\n)|(?<!\r)\n", "\r\n", line) |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
110 return line |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
111 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
112 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
113 def detect_mode(line, default): |
1307 | 114 """ |
115 Detects line break for given line, if line break couldn't be found | |
116 given default value is returned | |
117 | |
118 :param line: str line | |
119 :param default: default | |
120 :rtype: int | |
121 :return: value of line end on of 0 - Unix, 1 - Mac, 2 - DOS | |
122 """ | |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
123 if line.endswith('\r\n'): |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
124 return 2 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
125 elif line.endswith('\n'): |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
126 return 0 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
127 elif line.endswith('\r'): |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
128 return 1 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
129 else: |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
130 return default |
1116
716911af91e1
Added api_key into user, api key get's generated again after password change
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
131 |
1307 | 132 |
1116
716911af91e1
Added api_key into user, api key get's generated again after password change
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
133 def generate_api_key(username, salt=None): |
1154
36fe593dfe4b
simplified str2bool, and moved safe_unicode out of helpers since it was not html specific function
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
134 """ |
1466 | 135 Generates unique API key for given username, if salt is not given |
1223
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
136 it'll be generated from some random string |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1199
diff
changeset
|
137 |
1154
36fe593dfe4b
simplified str2bool, and moved safe_unicode out of helpers since it was not html specific function
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
138 :param username: username as string |
36fe593dfe4b
simplified str2bool, and moved safe_unicode out of helpers since it was not html specific function
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
139 :param salt: salt to hash generate KEY |
1223
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
140 :rtype: str |
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
141 :returns: sha1 hash from username+salt |
1154
36fe593dfe4b
simplified str2bool, and moved safe_unicode out of helpers since it was not html specific function
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
142 """ |
1116
716911af91e1
Added api_key into user, api key get's generated again after password change
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
143 from tempfile import _RandomNameSequence |
716911af91e1
Added api_key into user, api key get's generated again after password change
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
144 import hashlib |
716911af91e1
Added api_key into user, api key get's generated again after password change
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
145 |
716911af91e1
Added api_key into user, api key get's generated again after password change
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
146 if salt is None: |
716911af91e1
Added api_key into user, api key get's generated again after password change
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
147 salt = _RandomNameSequence().next() |
716911af91e1
Added api_key into user, api key get's generated again after password change
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
148 |
716911af91e1
Added api_key into user, api key get's generated again after password change
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
149 return hashlib.sha1(username + salt).hexdigest() |
1154
36fe593dfe4b
simplified str2bool, and moved safe_unicode out of helpers since it was not html specific function
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
150 |
1223
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
151 |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
152 def safe_unicode(str_, from_encoding='utf8'): |
1154
36fe593dfe4b
simplified str2bool, and moved safe_unicode out of helpers since it was not html specific function
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
153 """ |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
154 safe unicode function. Does few trick to turn str_ into unicode |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
155 |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
156 In case of UnicodeDecode error we try to return it with encoding detected |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
157 by chardet library if it fails fallback to unicode with errors replaced |
1223
f7b24987d5fb
fixed setup.py file to use same platform as defined in main rhodecode PLATFORM_OTHERS,
Marcin Kuzminski <marcin@python-works.com>
parents:
1222
diff
changeset
|
158 |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
159 :param str_: string to decode |
1222
2c246d24eb90
simplified safe_unicode function
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
160 :rtype: unicode |
2c246d24eb90
simplified safe_unicode function
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
161 :returns: unicode object |
1154
36fe593dfe4b
simplified str2bool, and moved safe_unicode out of helpers since it was not html specific function
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
162 """ |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
163 if isinstance(str_, unicode): |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
164 return str_ |
1199
268fa0b6b2ef
Added os.sep in models for better win support
Marcin Kuzminski <marcin@python-works.com>
parents:
1154
diff
changeset
|
165 |
1154
36fe593dfe4b
simplified str2bool, and moved safe_unicode out of helpers since it was not html specific function
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
166 try: |
1502
a2efbfe84067
fixes safe_unicode raise UnicodeDecodeError without any parameters
Marcin Kuzminski <marcin@python-works.com>
parents:
1494
diff
changeset
|
167 return unicode(str_) |
a2efbfe84067
fixes safe_unicode raise UnicodeDecodeError without any parameters
Marcin Kuzminski <marcin@python-works.com>
parents:
1494
diff
changeset
|
168 except UnicodeDecodeError: |
a2efbfe84067
fixes safe_unicode raise UnicodeDecodeError without any parameters
Marcin Kuzminski <marcin@python-works.com>
parents:
1494
diff
changeset
|
169 pass |
a2efbfe84067
fixes safe_unicode raise UnicodeDecodeError without any parameters
Marcin Kuzminski <marcin@python-works.com>
parents:
1494
diff
changeset
|
170 |
a2efbfe84067
fixes safe_unicode raise UnicodeDecodeError without any parameters
Marcin Kuzminski <marcin@python-works.com>
parents:
1494
diff
changeset
|
171 try: |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
172 return unicode(str_, from_encoding) |
1154
36fe593dfe4b
simplified str2bool, and moved safe_unicode out of helpers since it was not html specific function
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
173 except UnicodeDecodeError: |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
174 pass |
1502
a2efbfe84067
fixes safe_unicode raise UnicodeDecodeError without any parameters
Marcin Kuzminski <marcin@python-works.com>
parents:
1494
diff
changeset
|
175 |
a2efbfe84067
fixes safe_unicode raise UnicodeDecodeError without any parameters
Marcin Kuzminski <marcin@python-works.com>
parents:
1494
diff
changeset
|
176 try: |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
177 import chardet |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
178 encoding = chardet.detect(str_)['encoding'] |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
179 if encoding is None: |
1502
a2efbfe84067
fixes safe_unicode raise UnicodeDecodeError without any parameters
Marcin Kuzminski <marcin@python-works.com>
parents:
1494
diff
changeset
|
180 raise Exception() |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
181 return str_.decode(encoding) |
1502
a2efbfe84067
fixes safe_unicode raise UnicodeDecodeError without any parameters
Marcin Kuzminski <marcin@python-works.com>
parents:
1494
diff
changeset
|
182 except (ImportError, UnicodeDecodeError, Exception): |
a2efbfe84067
fixes safe_unicode raise UnicodeDecodeError without any parameters
Marcin Kuzminski <marcin@python-works.com>
parents:
1494
diff
changeset
|
183 return unicode(str_, from_encoding, 'replace') |
1300
882ac77dc709
fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
Marcin Kuzminski <marcin@python-works.com>
parents:
1223
diff
changeset
|
184 |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
185 def safe_str(unicode_, to_encoding='utf8'): |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
186 """ |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
187 safe str function. Does few trick to turn unicode_ into string |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
188 |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
189 In case of UnicodeEncodeError we try to return it with encoding detected |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
190 by chardet library if it fails fallback to string with errors replaced |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
191 |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
192 :param unicode_: unicode to encode |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
193 :rtype: str |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
194 :returns: str object |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
195 """ |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
196 |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
197 if isinstance(unicode_, str): |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
198 return unicode_ |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
199 |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
200 try: |
1494
8e76649f11ad
fixes safe_str method
Marcin Kuzminski <marcin@python-works.com>
parents:
1490
diff
changeset
|
201 return unicode_.encode(to_encoding) |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
202 except UnicodeEncodeError: |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
203 pass |
1514
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
1502
diff
changeset
|
204 |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
205 try: |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
206 import chardet |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
207 encoding = chardet.detect(unicode_)['encoding'] |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
208 print encoding |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
209 if encoding is None: |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
210 raise UnicodeEncodeError() |
1514
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
1502
diff
changeset
|
211 |
1490
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
212 return unicode_.encode(encoding) |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
213 except (ImportError, UnicodeEncodeError): |
76b358f81926
extended safe_str and safe_unicode with chardet fallback.
Marcin Kuzminski <marcin@python-works.com>
parents:
1466
diff
changeset
|
214 return unicode_.encode(to_encoding, 'replace') |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
215 |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
216 return safe_str |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
217 |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
218 |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1387
diff
changeset
|
219 |
1300
882ac77dc709
fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
Marcin Kuzminski <marcin@python-works.com>
parents:
1223
diff
changeset
|
220 def engine_from_config(configuration, prefix='sqlalchemy.', **kwargs): |
882ac77dc709
fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
Marcin Kuzminski <marcin@python-works.com>
parents:
1223
diff
changeset
|
221 """ |
882ac77dc709
fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
Marcin Kuzminski <marcin@python-works.com>
parents:
1223
diff
changeset
|
222 Custom engine_from_config functions that makes sure we use NullPool for |
1360
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
223 file based sqlite databases. This prevents errors on sqlite. This only |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
224 applies to sqlalchemy versions < 0.7.0 |
1307 | 225 |
1300
882ac77dc709
fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
Marcin Kuzminski <marcin@python-works.com>
parents:
1223
diff
changeset
|
226 """ |
1360
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
227 import sqlalchemy |
1300
882ac77dc709
fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
Marcin Kuzminski <marcin@python-works.com>
parents:
1223
diff
changeset
|
228 from sqlalchemy import engine_from_config as efc |
1360
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
229 import logging |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
230 |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
231 if int(sqlalchemy.__version__.split('.')[1]) < 7: |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
232 |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
233 # This solution should work for sqlalchemy < 0.7.0, and should use |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
234 # proxy=TimerProxy() for execution time profiling |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
235 |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
236 from sqlalchemy.pool import NullPool |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
237 url = configuration[prefix + 'url'] |
1300
882ac77dc709
fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
Marcin Kuzminski <marcin@python-works.com>
parents:
1223
diff
changeset
|
238 |
1360
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
239 if url.startswith('sqlite'): |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
240 kwargs.update({'poolclass': NullPool}) |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
241 return efc(configuration, prefix, **kwargs) |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
242 else: |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
243 import time |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
244 from sqlalchemy import event |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
245 from sqlalchemy.engine import Engine |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
246 |
1362
4c9bd42f82f9
timerproxy will use the same logger as sqlalchemy, in order to be controlled by sqlalchemy logger settings
Marcin Kuzminski <marcin@python-works.com>
parents:
1360
diff
changeset
|
247 log = logging.getLogger('sqlalchemy.engine') |
1360
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
248 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38) |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
249 engine = efc(configuration, prefix, **kwargs) |
1300
882ac77dc709
fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
Marcin Kuzminski <marcin@python-works.com>
parents:
1223
diff
changeset
|
250 |
1360
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
251 def color_sql(sql): |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
252 COLOR_SEQ = "\033[1;%dm" |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
253 COLOR_SQL = YELLOW |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
254 normal = '\x1b[0m' |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
255 return ''.join([COLOR_SEQ % COLOR_SQL, sql, normal]) |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
256 |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
257 if configuration['debug']: |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
258 #attach events only for debug configuration |
1300
882ac77dc709
fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
Marcin Kuzminski <marcin@python-works.com>
parents:
1223
diff
changeset
|
259 |
1360
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
260 def before_cursor_execute(conn, cursor, statement, |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
261 parameters, context, executemany): |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
262 context._query_start_time = time.time() |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
263 log.info(color_sql(">>>>> STARTING QUERY >>>>>")) |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
264 |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
265 |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
266 def after_cursor_execute(conn, cursor, statement, |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
267 parameters, context, executemany): |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
268 total = time.time() - context._query_start_time |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
269 log.info(color_sql("<<<<< TOTAL TIME: %f <<<<<" % total)) |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
270 |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
271 event.listen(engine, "before_cursor_execute", |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
272 before_cursor_execute) |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
273 event.listen(engine, "after_cursor_execute", |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
274 after_cursor_execute) |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
275 |
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1342
diff
changeset
|
276 return engine |
1342
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
277 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
278 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
279 def age(curdate): |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
280 """ |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
281 turns a datetime into an age string. |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
282 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
283 :param curdate: datetime object |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
284 :rtype: unicode |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
285 :returns: unicode words describing age |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
286 """ |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
287 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
288 from datetime import datetime |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
289 from webhelpers.date import time_ago_in_words |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
290 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
291 _ = lambda s:s |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
292 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
293 if not curdate: |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
294 return '' |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
295 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
296 agescales = [(_(u"year"), 3600 * 24 * 365), |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
297 (_(u"month"), 3600 * 24 * 30), |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
298 (_(u"day"), 3600 * 24), |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
299 (_(u"hour"), 3600), |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
300 (_(u"minute"), 60), |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
301 (_(u"second"), 1), ] |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
302 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
303 age = datetime.now() - curdate |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
304 age_seconds = (age.days * agescales[2][1]) + age.seconds |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
305 pos = 1 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
306 for scale in agescales: |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
307 if scale[1] <= age_seconds: |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
308 if pos == 6:pos = 5 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
309 return '%s %s' % (time_ago_in_words(curdate, |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
310 agescales[pos][0]), _('ago')) |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
311 pos += 1 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
312 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
313 return _(u'just now') |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
314 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
315 |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
316 def uri_filter(uri): |
1342
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
317 """ |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
318 Removes user:password from given url string |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
319 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
320 :param uri: |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
321 :rtype: unicode |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
322 :returns: filtered list of strings |
1342
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
323 """ |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
324 if not uri: |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
325 return '' |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
326 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
327 proto = '' |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
328 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
329 for pat in ('https://', 'http://'): |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
330 if uri.startswith(pat): |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
331 uri = uri[len(pat):] |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
332 proto = pat |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
333 break |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
334 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
335 # remove passwords and username |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
336 uri = uri[uri.find('@') + 1:] |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
337 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
338 # get the port |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
339 cred_pos = uri.find(':') |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
340 if cred_pos == -1: |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
341 host, port = uri, None |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
342 else: |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
343 host, port = uri[:cred_pos], uri[cred_pos + 1:] |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
344 |
9dacacc5b7c2
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
345 return filter(None, [proto, host, port]) |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
346 |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
347 |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
348 def credentials_filter(uri): |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
349 """ |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
350 Returns a url with removed credentials |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
351 |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
352 :param uri: |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
353 """ |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
354 |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
355 uri = uri_filter(uri) |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
356 #check if we have port |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
357 if len(uri) > 2 and uri[2]: |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
358 uri[2] = ':' + uri[2] |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
359 |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
360 return ''.join(uri) |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1362
diff
changeset
|
361 |
1466 | 362 def get_changeset_safe(repo, rev): |
363 """ | |
364 Safe version of get_changeset if this changeset doesn't exists for a | |
365 repo it returns a Dummy one instead | |
366 | |
367 :param repo: | |
368 :param rev: | |
369 """ | |
370 from vcs.backends.base import BaseRepository | |
371 from vcs.exceptions import RepositoryError | |
372 if not isinstance(repo, BaseRepository): | |
373 raise Exception('You must pass an Repository ' | |
374 'object as first argument got %s', type(repo)) | |
375 | |
376 try: | |
377 cs = repo.get_changeset(rev) | |
378 except RepositoryError: | |
379 from rhodecode.lib.utils import EmptyChangeset | |
380 cs = EmptyChangeset(requested_revision=rev) | |
1514
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
1502
diff
changeset
|
381 return cs |