##// END OF EJS Templates
cleanup: minimize use of lambda expressions - we have 'def' for that purpose...
Mads Kiilerich -
r8139:5725fa4c default
parent child Browse files
Show More
@@ -104,15 +104,14 b' class RepoGroupsController(BaseControlle'
104 _tmpl_lookup = app_globals.mako_lookup
104 _tmpl_lookup = app_globals.mako_lookup
105 template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
105 template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
106
106
107 repo_group_name = lambda repo_group_name, children_groups: (
107 def repo_group_name(repo_group_name, children_groups):
108 template.get_def("repo_group_name")
108 return template.get_def("repo_group_name") \
109 .render_unicode(repo_group_name, children_groups, _=_, h=h, c=c)
109 .render_unicode(repo_group_name, children_groups, _=_, h=h, c=c)
110 )
110
111 repo_group_actions = lambda repo_group_id, repo_group_name, gr_count: (
111 def repo_group_actions(repo_group_id, repo_group_name, gr_count):
112 template.get_def("repo_group_actions")
112 return template.get_def("repo_group_actions") \
113 .render_unicode(repo_group_id, repo_group_name, gr_count, _=_, h=h, c=c,
113 .render_unicode(repo_group_id, repo_group_name, gr_count, _=_, h=h, c=c,
114 ungettext=ungettext)
114 ungettext=ungettext)
115 )
116
115
117 for repo_gr in group_iter:
116 for repo_gr in group_iter:
118 children_groups = [g.name for g in repo_gr.parents] + [repo_gr.name]
117 children_groups = [g.name for g in repo_gr.parents] + [repo_gr.name]
@@ -89,16 +89,15 b' class UserGroupsController(BaseControlle'
89 _tmpl_lookup = app_globals.mako_lookup
89 _tmpl_lookup = app_globals.mako_lookup
90 template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
90 template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
91
91
92 user_group_name = lambda user_group_id, user_group_name: (
92 def user_group_name(user_group_id, user_group_name):
93 template.get_def("user_group_name")
93 return template.get_def("user_group_name") \
94 .render_unicode(user_group_id, user_group_name, _=_, h=h, c=c)
94 .render_unicode(user_group_id, user_group_name, _=_, h=h, c=c)
95 )
95
96 user_group_actions = lambda user_group_id, user_group_name: (
96 def user_group_actions(user_group_id, user_group_name):
97 template.get_def("user_group_actions")
97 return template.get_def("user_group_actions") \
98 .render_unicode(user_group_id, user_group_name, _=_, h=h, c=c)
98 .render_unicode(user_group_id, user_group_name, _=_, h=h, c=c)
99 )
99
100 for user_gr in group_iter:
100 for user_gr in group_iter:
101
102 user_groups_data.append({
101 user_groups_data.append({
103 "raw_name": user_gr.users_group_name,
102 "raw_name": user_gr.users_group_name,
104 "group_name": user_group_name(user_gr.users_group_id,
103 "group_name": user_group_name(user_gr.users_group_id,
@@ -75,13 +75,13 b' class UsersController(BaseController):'
75
75
76 grav_tmpl = '<div class="gravatar">%s</div>'
76 grav_tmpl = '<div class="gravatar">%s</div>'
77
77
78 username = lambda user_id, username: (
78 def username(user_id, username):
79 template.get_def("user_name")
79 return template.get_def("user_name") \
80 .render_unicode(user_id, username, _=_, h=h, c=c))
80 .render_unicode(user_id, username, _=_, h=h, c=c)
81
81
82 user_actions = lambda user_id, username: (
82 def user_actions(user_id, username):
83 template.get_def("user_actions")
83 return template.get_def("user_actions") \
84 .render_unicode(user_id, username, _=_, h=h, c=c))
84 .render_unicode(user_id, username, _=_, h=h, c=c)
85
85
86 for user in c.users_list:
86 for user in c.users_list:
87 users_data.append({
87 users_data.append({
@@ -327,7 +327,8 b' class KallitheaAuthPlugin(auth_modules.K'
327 (user_dn, ldap_attrs) = aldap.authenticate_ldap(username, password)
327 (user_dn, ldap_attrs) = aldap.authenticate_ldap(username, password)
328 log.debug('Got ldap DN response %s', user_dn)
328 log.debug('Got ldap DN response %s', user_dn)
329
329
330 get_ldap_attr = lambda k: ldap_attrs.get(settings.get(k), [''])[0]
330 def get_ldap_attr(k):
331 return ldap_attrs.get(settings.get(k), [''])[0]
331
332
332 # old attrs fetched from Kallithea database
333 # old attrs fetched from Kallithea database
333 admin = getattr(userobj, 'admin', False)
334 admin = getattr(userobj, 'admin', False)
@@ -66,6 +66,11 b' def whoosh_index(repo_location, full_ind'
66 .run(full_index=full_index)
66 .run(full_index=full_index)
67
67
68
68
69 # for js data compatibility cleans the key for person from '
70 def akc(k):
71 return person(k).replace('"', '')
72
73
69 @celerylib.task
74 @celerylib.task
70 @celerylib.dbsession
75 @celerylib.dbsession
71 def get_commits_stats(repo_name, ts_min_y, ts_max_y, recurse_limit=100):
76 def get_commits_stats(repo_name, ts_min_y, ts_max_y, recurse_limit=100):
@@ -79,9 +84,6 b' def get_commits_stats(repo_name, ts_min_'
79 try:
84 try:
80 lock = celerylib.DaemonLock(os.path.join(lockkey_path, lockkey))
85 lock = celerylib.DaemonLock(os.path.join(lockkey_path, lockkey))
81
86
82 # for js data compatibility cleans the key for person from '
83 akc = lambda k: person(k).replace('"', "")
84
85 co_day_auth_aggr = {}
87 co_day_auth_aggr = {}
86 commits_by_day_aggregate = {}
88 commits_by_day_aggregate = {}
87 repo = Repository.get_by_repo_name(repo_name)
89 repo = Repository.get_by_repo_name(repo_name)
@@ -502,11 +502,19 b' def pop_flash_messages():'
502 return [_Message(category, message) for category, message in _session_flash_messages(clear=True)]
502 return [_Message(category, message) for category, message in _session_flash_messages(clear=True)]
503
503
504
504
505 age = lambda x, y=False: _age(x, y)
505 def age(x, y=False):
506 capitalize = lambda x: x.capitalize()
506 return _age(x, y)
507
508 def capitalize(x):
509 return x.capitalize()
510
507 email = author_email
511 email = author_email
508 short_id = lambda x: x[:12]
512
509 hide_credentials = lambda x: ''.join(credentials_filter(x))
513 def short_id(x):
514 return x[:12]
515
516 def hide_credentials(x):
517 return ''.join(credentials_filter(x))
510
518
511
519
512 def show_id(cs):
520 def show_id(cs):
@@ -602,15 +610,12 b' def person(author, show_attr="username")'
602
610
603 def person_by_id(id_, show_attr="username"):
611 def person_by_id(id_, show_attr="username"):
604 from kallithea.model.db import User
612 from kallithea.model.db import User
605 # attr to return from fetched user
606 person_getter = lambda usr: getattr(usr, show_attr)
607
608 # maybe it's an ID ?
613 # maybe it's an ID ?
609 if str(id_).isdigit() or isinstance(id_, int):
614 if str(id_).isdigit() or isinstance(id_, int):
610 id_ = int(id_)
615 id_ = int(id_)
611 user = User.get(id_)
616 user = User.get(id_)
612 if user is not None:
617 if user is not None:
613 return person_getter(user)
618 return getattr(user, show_attr)
614 return id_
619 return id_
615
620
616
621
@@ -862,10 +867,7 b' def action_parser(user_log, feed=False, '
862 .replace('[', '<b>') \
867 .replace('[', '<b>') \
863 .replace(']', '</b>')
868 .replace(']', '</b>')
864
869
865 action_params_func = lambda: ""
870 action_params_func = action_str[1] if callable(action_str[1]) else (lambda: "")
866
867 if callable(action_str[1]):
868 action_params_func = action_str[1]
869
871
870 def action_parser_icon():
872 def action_parser_icon():
871 action = user_log.action
873 action = user_log.action
@@ -1176,7 +1178,8 b' def urlify_issues(newtext, repo_name):'
1176 assert CONFIG['sqlalchemy.url'] # make sure config has been loaded
1178 assert CONFIG['sqlalchemy.url'] # make sure config has been loaded
1177
1179
1178 # Build chain of urlify functions, starting with not doing any transformation
1180 # Build chain of urlify functions, starting with not doing any transformation
1179 tmp_urlify_issues_f = lambda s: s
1181 def tmp_urlify_issues_f(s):
1182 return s
1180
1183
1181 issue_pat_re = re.compile(r'issue_pat(.*)')
1184 issue_pat_re = re.compile(r'issue_pat(.*)')
1182 for k in CONFIG:
1185 for k in CONFIG:
@@ -1228,9 +1231,9 b' def urlify_issues(newtext, repo_name):'
1228 'url': issue_url,
1231 'url': issue_url,
1229 'text': issue_text,
1232 'text': issue_text,
1230 }
1233 }
1231 tmp_urlify_issues_f = (lambda s,
1234
1232 issue_re=issue_re, issues_replace=issues_replace, chain_f=tmp_urlify_issues_f:
1235 def tmp_urlify_issues_f(s, issue_re=issue_re, issues_replace=issues_replace, chain_f=tmp_urlify_issues_f):
1233 issue_re.sub(issues_replace, chain_f(s)))
1236 return issue_re.sub(issues_replace, chain_f(s))
1234
1237
1235 # Set tmp function globally - atomically
1238 # Set tmp function globally - atomically
1236 _urlify_issues_f = tmp_urlify_issues_f
1239 _urlify_issues_f = tmp_urlify_issues_f
@@ -44,7 +44,9 b' from email.utils import parseaddr'
44
44
45 ADDRESS_HEADERS_WHITELIST = ['From', 'To', 'Delivered-To', 'Cc']
45 ADDRESS_HEADERS_WHITELIST = ['From', 'To', 'Delivered-To', 'Cc']
46 DEFAULT_ENCODING = "utf-8"
46 DEFAULT_ENCODING = "utf-8"
47 VALUE_IS_EMAIL_ADDRESS = lambda v: '@' in v
47
48 def VALUE_IS_EMAIL_ADDRESS(v):
49 return '@' in v
48
50
49
51
50 def normalize_header(header):
52 def normalize_header(header):
@@ -435,8 +435,8 b' class GitChangeset(BaseChangeset):'
435 raise NodeDoesNotExistError("Cannot find one of parents' "
435 raise NodeDoesNotExistError("Cannot find one of parents' "
436 "directories for a given path: %s" % path)
436 "directories for a given path: %s" % path)
437
437
438 _GL = lambda m: m and objects.S_ISGITLINK(m)
438 stat = self._stat_modes.get(path)
439 if _GL(self._stat_modes.get(path)):
439 if stat and objects.S_ISGITLINK(stat):
440 tree = self.repository._repo[self._tree_id]
440 tree = self.repository._repo[self._tree_id]
441 cf = ConfigFile.from_file(BytesIO(self.repository._repo.get_object(tree[b'.gitmodules'][1]).data))
441 cf = ConfigFile.from_file(BytesIO(self.repository._repo.get_object(tree[b'.gitmodules'][1]).data))
442 url = ascii_str(cf.get(('submodule', path), 'url'))
442 url = ascii_str(cf.get(('submodule', path), 'url'))
@@ -358,10 +358,9 b' class GitRepository(BaseRepository):'
358 def branches(self):
358 def branches(self):
359 if not self.revisions:
359 if not self.revisions:
360 return {}
360 return {}
361 sortkey = lambda ctx: ctx[0]
362 _branches = [(safe_str(key), ascii_str(sha))
361 _branches = [(safe_str(key), ascii_str(sha))
363 for key, (sha, type_) in self._parsed_refs.items() if type_ == b'H']
362 for key, (sha, type_) in self._parsed_refs.items() if type_ == b'H']
364 return OrderedDict(sorted(_branches, key=sortkey, reverse=False))
363 return OrderedDict(sorted(_branches, key=(lambda ctx: ctx[0]), reverse=False))
365
364
366 @LazyProperty
365 @LazyProperty
367 def closed_branches(self):
366 def closed_branches(self):
@@ -374,11 +373,9 b' class GitRepository(BaseRepository):'
374 def _get_tags(self):
373 def _get_tags(self):
375 if not self.revisions:
374 if not self.revisions:
376 return {}
375 return {}
377
378 sortkey = lambda ctx: ctx[0]
379 _tags = [(safe_str(key), ascii_str(sha))
376 _tags = [(safe_str(key), ascii_str(sha))
380 for key, (sha, type_) in self._parsed_refs.items() if type_ == b'T']
377 for key, (sha, type_) in self._parsed_refs.items() if type_ == b'T']
381 return OrderedDict(sorted(_tags, key=sortkey, reverse=True))
378 return OrderedDict(sorted(_tags, key=(lambda ctx: ctx[0]), reverse=True))
382
379
383 def tag(self, name, user, revision=None, message=None, date=None,
380 def tag(self, name, user, revision=None, message=None, date=None,
384 **kwargs):
381 **kwargs):
@@ -5,7 +5,8 b' from kallithea.lib.vcs.utils import asli'
5 from kallithea.lib.vcs.utils.paths import get_user_home
5 from kallithea.lib.vcs.utils.paths import get_user_home
6
6
7
7
8 abspath = lambda * p: os.path.abspath(os.path.join(*p))
8 def abspath(*p):
9 return os.path.abspath(os.path.join(*p))
9
10
10 VCSRC_PATH = os.environ.get('VCSRC_PATH')
11 VCSRC_PATH = os.environ.get('VCSRC_PATH')
11
12
@@ -1,7 +1,8 b''
1 import os
1 import os
2
2
3
3
4 abspath = lambda * p: os.path.abspath(os.path.join(*p))
4 def abspath(*p):
5 return os.path.abspath(os.path.join(*p))
5
6
6
7
7 def get_dirs_for_path(*paths):
8 def get_dirs_for_path(*paths):
@@ -109,12 +109,11 b' class RepoModel(object):'
109 :param user:
109 :param user:
110 """
110 """
111 from kallithea.lib.auth import AuthUser
111 from kallithea.lib.auth import AuthUser
112 user = User.guess_instance(user)
112 auth_user = AuthUser(dbuser=User.guess_instance(user))
113 repos = AuthUser(dbuser=user).permissions['repositories']
113 repos = [repo_name
114 access_check = lambda r: r[1] in ['repository.read',
114 for repo_name, perm in auth_user.permissions['repositories'].items()
115 'repository.write',
115 if perm in ['repository.read', 'repository.write', 'repository.admin']
116 'repository.admin']
116 ]
117 repos = [x[0] for x in filter(access_check, repos.items())]
118 return Repository.query().filter(Repository.repo_name.in_(repos))
117 return Repository.query().filter(Repository.repo_name.in_(repos))
119
118
120 @classmethod
119 @classmethod
@@ -186,11 +186,7 b' def ValidRepoGroup(edit=False, old_data='
186 slug = repo_name_slug(group_name)
186 slug = repo_name_slug(group_name)
187
187
188 # check for parent of self
188 # check for parent of self
189 parent_of_self = lambda: (
189 if edit and parent_group_id and old_data['group_id'] == parent_group_id:
190 old_data['group_id'] == parent_group_id
191 if parent_group_id else False
192 )
193 if edit and parent_of_self():
194 msg = self.message('parent_group_id', state)
190 msg = self.message('parent_group_id', state)
195 raise formencode.Invalid(msg, value, state,
191 raise formencode.Invalid(msg, value, state,
196 error_dict=dict(parent_group_id=msg)
192 error_dict=dict(parent_group_id=msg)
@@ -20,16 +20,17 b' def _get_meta_var(name, data, callback_h'
20 import re
20 import re
21 matches = re.compile(r'(?:%s)\s*=\s*(.*)' % name).search(data)
21 matches = re.compile(r'(?:%s)\s*=\s*(.*)' % name).search(data)
22 if matches:
22 if matches:
23 if not callable(callback_handler):
23 s = eval(matches.groups()[0])
24 callback_handler = lambda v: v
24 if callable(callback_handler):
25
25 return callback_handler(s)
26 return callback_handler(eval(matches.groups()[0]))
26 return s
27
27
28 _meta = open(os.path.join(here, 'kallithea', '__init__.py'), 'r')
28 _meta = open(os.path.join(here, 'kallithea', '__init__.py'), 'r')
29 _metadata = _meta.read()
29 _metadata = _meta.read()
30 _meta.close()
30 _meta.close()
31
31
32 callback = lambda V: ('.'.join(map(str, V[:3])) + '.'.join(V[3:]))
32 def callback(V):
33 return '.'.join(map(str, V[:3])) + '.'.join(V[3:])
33 __version__ = _get_meta_var('VERSION', _metadata, callback)
34 __version__ = _get_meta_var('VERSION', _metadata, callback)
34 __license__ = _get_meta_var('__license__', _metadata)
35 __license__ = _get_meta_var('__license__', _metadata)
35 __author__ = _get_meta_var('__author__', _metadata)
36 __author__ = _get_meta_var('__author__', _metadata)
General Comments 0
You need to be logged in to leave comments. Login now