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