Mercurial > kallithea
annotate rhodecode/lib/__init__.py @ 1342:9dacacc5b7c2 beta
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
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 22 May 2011 21:09:02 +0200 |
parents | c1516b35f91d |
children | 1f47adeb67c2 |
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 |
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
|
26 |
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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 |
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 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
|
33 |
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 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
|
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 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
|
37 |
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 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
|
39 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
|
40 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
|
41 |
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 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 |
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 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 |
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 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
|
57 |
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 # 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
|
59 # 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
|
60 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
|
61 |
1307 | 62 # 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
|
63 # 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
|
64 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
|
65 |
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 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
|
67 |
1307 | 68 |
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
|
69 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
|
70 """ |
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 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
|
72 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
|
73 |
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 :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
|
75 :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
|
76 :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
|
77 """ |
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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 _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
|
83 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
|
84 |
1307 | 85 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
86 def convert_line_endings(temp, mode): |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
87 from string import replace |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
88 #modes: 0 - Unix, 1 - Mac, 2 - DOS |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
89 if mode == 0: |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
90 temp = replace(temp, '\r\n', '\n') |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
91 temp = replace(temp, '\r', '\n') |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
92 elif mode == 1: |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
93 temp = replace(temp, '\r\n', '\r') |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
94 temp = replace(temp, '\n', '\r') |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
95 elif mode == 2: |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
96 import re |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
97 temp = re.sub("\r(?!\n)|(?<!\r)\n", "\r\n", temp) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
98 return temp |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
99 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
100 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
101 def detect_mode(line, default): |
1307 | 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 """ | |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
111 if line.endswith('\r\n'): |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
112 return 2 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
113 elif line.endswith('\n'): |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
114 return 0 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
115 elif line.endswith('\r'): |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
116 return 1 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
117 else: |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1302
diff
changeset
|
118 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
|
119 |
1307 | 120 |
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
|
121 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
|
122 """ |
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
|
123 Generates unique API key for given username,if salt is not given |
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
|
124 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
|
125 |
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
|
126 :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
|
127 :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
|
128 :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
|
129 :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
|
130 """ |
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 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
|
132 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
|
133 |
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
|
134 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
|
135 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
|
136 |
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
|
137 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
|
138 |
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
|
139 |
1222
2c246d24eb90
simplified safe_unicode function
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
140 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
|
141 """ |
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 safe unicode function. In case of UnicodeDecode error we try to return |
1222
2c246d24eb90
simplified safe_unicode function
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
143 unicode with errors replace |
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
|
144 |
1222
2c246d24eb90
simplified safe_unicode function
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
145 :param _str: string to decode |
2c246d24eb90
simplified safe_unicode function
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
146 :rtype: unicode |
2c246d24eb90
simplified safe_unicode function
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
147 :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
|
148 """ |
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
|
149 |
1199
268fa0b6b2ef
Added os.sep in models for better win support
Marcin Kuzminski <marcin@python-works.com>
parents:
1154
diff
changeset
|
150 if isinstance(_str, unicode): |
268fa0b6b2ef
Added os.sep in models for better win support
Marcin Kuzminski <marcin@python-works.com>
parents:
1154
diff
changeset
|
151 return _str |
268fa0b6b2ef
Added os.sep in models for better win support
Marcin Kuzminski <marcin@python-works.com>
parents:
1154
diff
changeset
|
152 |
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 try: |
1222
2c246d24eb90
simplified safe_unicode function
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
154 u_str = 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
|
155 except UnicodeDecodeError: |
1222
2c246d24eb90
simplified safe_unicode function
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
156 u_str = unicode(_str, from_encoding, 'replace') |
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
|
157 |
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
|
158 return u_str |
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
|
159 |
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
|
160 |
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
|
161 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
|
162 """ |
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
|
163 Custom engine_from_config functions that makes sure we use NullPool for |
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
|
164 file based sqlite databases. This prevents errors on sqlite. |
1307 | 165 |
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
|
166 """ |
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
|
167 from sqlalchemy import engine_from_config as efc |
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
|
168 from sqlalchemy.pool import NullPool |
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
|
169 |
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
|
170 url = configuration[prefix + 'url'] |
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
|
171 |
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
|
172 if url.startswith('sqlite'): |
1307 | 173 kwargs.update({'poolclass': NullPool}) |
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
|
174 |
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
|
175 return efc(configuration, prefix, **kwargs) |
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
|
176 |
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
|
177 |
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
|
178 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
|
179 """ |
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
|
180 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
|
181 |
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
|
182 :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
|
183 :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
|
184 :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
|
185 """ |
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
|
186 |
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
|
187 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
|
188 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
|
189 |
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
|
190 _ = 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
|
191 |
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
|
192 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
|
193 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
|
194 |
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
|
195 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
|
196 (_(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
|
197 (_(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
|
198 (_(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
|
199 (_(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
|
200 (_(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
|
201 |
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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 |
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
|
212 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
|
213 |
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
|
214 |
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
|
215 def credentials_hidder(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
|
216 """ |
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
|
217 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
|
218 |
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
|
219 :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
|
220 :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
|
221 :returns: filtered list of strings |
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
|
222 """ |
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
|
223 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
|
224 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
|
225 |
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
|
226 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
|
227 |
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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 |
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
|
234 # 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
|
235 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
|
236 |
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
|
237 # 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 |
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
|
244 return filter(None, [proto, host, port]) |