Show More
@@ -1,4 +1,3 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
|||
2 |
|
|
1 | ||
3 | # Copyright (C) 2010-2020 RhodeCode GmbH |
|
2 | # Copyright (C) 2010-2020 RhodeCode GmbH | |
4 | # |
|
3 | # | |
@@ -22,7 +21,8 b' import os' | |||||
22 | import datetime |
|
21 | import datetime | |
23 | import collections |
|
22 | import collections | |
24 |
|
23 | |||
25 |
now = datetime.datetime.now() |
|
24 | now = datetime.datetime.now() | |
|
25 | now = now.strftime("%Y-%m-%d %H:%M:%S") + '.' + "{:03d}".format(int(now.microsecond/1000)) | |||
26 |
|
26 | |||
27 | print(f'{now} Starting RhodeCode imports...') |
|
27 | print(f'{now} Starting RhodeCode imports...') | |
28 |
|
28 | |||
@@ -42,6 +42,35 b' CELERY_EAGER = False' | |||||
42 | # link to config for pyramid |
|
42 | # link to config for pyramid | |
43 | CONFIG = {} |
|
43 | CONFIG = {} | |
44 |
|
44 | |||
|
45 | ||||
|
46 | class ConfigGet: | |||
|
47 | NotGiven = object() | |||
|
48 | ||||
|
49 | def _get_val_or_missing(self, key, missing): | |||
|
50 | if key not in CONFIG: | |||
|
51 | if missing == self.NotGiven: | |||
|
52 | return missing | |||
|
53 | # we don't get key, we don't get missing value, return nothing similar as config.get(key) | |||
|
54 | return None | |||
|
55 | else: | |||
|
56 | val = CONFIG[key] | |||
|
57 | return val | |||
|
58 | ||||
|
59 | def get_str(self, key, missing=NotGiven): | |||
|
60 | from rhodecode.lib.str_utils import safe_str | |||
|
61 | val = self._get_val_or_missing(key, missing) | |||
|
62 | return safe_str(val) | |||
|
63 | ||||
|
64 | def get_int(self, key, missing=NotGiven): | |||
|
65 | from rhodecode.lib.str_utils import safe_int | |||
|
66 | val = self._get_val_or_missing(key, missing) | |||
|
67 | return safe_int(val) | |||
|
68 | ||||
|
69 | def get_bool(self, key, missing=NotGiven): | |||
|
70 | from rhodecode.lib.type_utils import str2bool | |||
|
71 | val = self._get_val_or_missing(key, missing) | |||
|
72 | return str2bool(val) | |||
|
73 | ||||
45 | # Populated with the settings dictionary from application init in |
|
74 | # Populated with the settings dictionary from application init in | |
46 | # rhodecode.conf.environment.load_pyramid_environment |
|
75 | # rhodecode.conf.environment.load_pyramid_environment | |
47 | PYRAMID_SETTINGS = {} |
|
76 | PYRAMID_SETTINGS = {} |
@@ -25,9 +25,10 b' import operator' | |||||
25 | from pyramid.httpexceptions import HTTPFound, HTTPForbidden, HTTPBadRequest |
|
25 | from pyramid.httpexceptions import HTTPFound, HTTPForbidden, HTTPBadRequest | |
26 |
|
26 | |||
27 | from rhodecode.lib import helpers as h, diffs, rc_cache |
|
27 | from rhodecode.lib import helpers as h, diffs, rc_cache | |
|
28 | from rhodecode.lib.str_utils import safe_str | |||
28 | from rhodecode.lib.utils import repo_name_slug |
|
29 | from rhodecode.lib.utils import repo_name_slug | |
29 | from rhodecode.lib.utils2 import ( |
|
30 | from rhodecode.lib.utils2 import ( | |
30 |
StrictAttributeDict, str2bool, safe_int, datetime_to_time |
|
31 | StrictAttributeDict, str2bool, safe_int, datetime_to_time) | |
31 | from rhodecode.lib.markup_renderer import MarkupRenderer, relative_links |
|
32 | from rhodecode.lib.markup_renderer import MarkupRenderer, relative_links | |
32 | from rhodecode.lib.vcs.backends.base import EmptyCommit |
|
33 | from rhodecode.lib.vcs.backends.base import EmptyCommit | |
33 | from rhodecode.lib.vcs.exceptions import RepositoryRequirementError |
|
34 | from rhodecode.lib.vcs.exceptions import RepositoryRequirementError | |
@@ -73,7 +74,7 b' def add_route_requirements(route_path, r' | |||||
73 | add_route_requirements('{repo_name}/settings') |
|
74 | add_route_requirements('{repo_name}/settings') | |
74 | """ |
|
75 | """ | |
75 | requirements = requirements or URL_NAME_REQUIREMENTS |
|
76 | requirements = requirements or URL_NAME_REQUIREMENTS | |
76 | for key, regex in requirements.items(): |
|
77 | for key, regex in list(requirements.items()): | |
77 | route_path = route_path.replace('{%s}' % key, '{%s:%s}' % (key, regex)) |
|
78 | route_path = route_path.replace('{%s}' % key, '{%s:%s}' % (key, regex)) | |
78 | return route_path |
|
79 | return route_path | |
79 |
|
80 | |||
@@ -240,7 +241,7 b' class RepoAppView(BaseAppView):' | |||||
240 | def _handle_missing_requirements(self, error): |
|
241 | def _handle_missing_requirements(self, error): | |
241 | log.error( |
|
242 | log.error( | |
242 | 'Requirements are missing for repository %s: %s', |
|
243 | 'Requirements are missing for repository %s: %s', | |
243 |
self.db_repo_name, safe_ |
|
244 | self.db_repo_name, safe_str(error)) | |
244 |
|
245 | |||
245 | def _prepare_and_set_clone_url(self, c): |
|
246 | def _prepare_and_set_clone_url(self, c): | |
246 | username = '' |
|
247 | username = '' | |
@@ -352,8 +353,8 b' class RepoAppView(BaseAppView):' | |||||
352 | return None, None |
|
353 | return None, None | |
353 | landing_commit_id = landing_commit.raw_id |
|
354 | landing_commit_id = landing_commit.raw_id | |
354 |
|
355 | |||
355 |
cache_namespace_uid = ' |
|
356 | cache_namespace_uid = 'repo.{}'.format(db_repo.repo_id) | |
356 | region = rc_cache.get_or_create_region('cache_repo', cache_namespace_uid) |
|
357 | region = rc_cache.get_or_create_region('cache_repo', cache_namespace_uid, use_async_runner=True) | |
357 | start = time.time() |
|
358 | start = time.time() | |
358 |
|
359 | |||
359 | @region.conditional_cache_on_arguments(namespace=cache_namespace_uid) |
|
360 | @region.conditional_cache_on_arguments(namespace=cache_namespace_uid) | |
@@ -377,7 +378,7 b' class RepoAppView(BaseAppView):' | |||||
377 | } |
|
378 | } | |
378 |
|
379 | |||
379 | readme_data = self._render_readme_or_none(commit, readme_node, relative_urls) |
|
380 | readme_data = self._render_readme_or_none(commit, readme_node, relative_urls) | |
380 |
readme_filename = readme_node. |
|
381 | readme_filename = readme_node.str_path | |
381 |
|
382 | |||
382 | return readme_data, readme_filename |
|
383 | return readme_data, readme_filename | |
383 |
|
384 | |||
@@ -394,13 +395,12 b' class RepoAppView(BaseAppView):' | |||||
394 | renderer = MarkupRenderer() |
|
395 | renderer = MarkupRenderer() | |
395 | try: |
|
396 | try: | |
396 | html_source = renderer.render( |
|
397 | html_source = renderer.render( | |
397 | readme_node.content, filename=readme_node.path) |
|
398 | readme_node.str_content, filename=readme_node.path) | |
398 | if relative_urls: |
|
399 | if relative_urls: | |
399 | return relative_links(html_source, relative_urls) |
|
400 | return relative_links(html_source, relative_urls) | |
400 | return html_source |
|
401 | return html_source | |
401 | except Exception: |
|
402 | except Exception: | |
402 | log.exception( |
|
403 | log.exception("Exception while trying to render the README") | |
403 | "Exception while trying to render the README") |
|
|||
404 |
|
404 | |||
405 | def get_recache_flag(self): |
|
405 | def get_recache_flag(self): | |
406 | for flag_name in ['force_recache', 'force-recache', 'no-cache']: |
|
406 | for flag_name in ['force_recache', 'force-recache', 'no-cache']: | |
@@ -455,6 +455,7 b' class PathFilter(object):' | |||||
455 | return patchset, False |
|
455 | return patchset, False | |
456 |
|
456 | |||
457 | def render_patchset_filtered(self, diffset, patchset, source_ref=None, target_ref=None): |
|
457 | def render_patchset_filtered(self, diffset, patchset, source_ref=None, target_ref=None): | |
|
458 | ||||
458 | filtered_patchset, has_hidden_changes = self.filter_patchset(patchset) |
|
459 | filtered_patchset, has_hidden_changes = self.filter_patchset(patchset) | |
459 | result = diffset.render_patchset( |
|
460 | result = diffset.render_patchset( | |
460 | filtered_patchset, source_ref=source_ref, target_ref=target_ref) |
|
461 | filtered_patchset, source_ref=source_ref, target_ref=target_ref) | |
@@ -488,12 +489,9 b' class RepoGroupAppView(BaseAppView):' | |||||
488 | return c |
|
489 | return c | |
489 |
|
490 | |||
490 | def _revoke_perms_on_yourself(self, form_result): |
|
491 | def _revoke_perms_on_yourself(self, form_result): | |
491 |
_updates = |
|
492 | _updates = [u for u in form_result['perm_updates'] if self._rhodecode_user.user_id == int(u[0])] | |
492 | form_result['perm_updates']) |
|
493 | _additions = [u for u in form_result['perm_additions'] if self._rhodecode_user.user_id == int(u[0])] | |
493 |
_ |
|
494 | _deletions = [u for u in form_result['perm_deletions'] if self._rhodecode_user.user_id == int(u[0])] | |
494 | form_result['perm_additions']) |
|
|||
495 | _deletions = filter(lambda u: self._rhodecode_user.user_id == int(u[0]), |
|
|||
496 | form_result['perm_deletions']) |
|
|||
497 | admin_perm = 'group.admin' |
|
495 | admin_perm = 'group.admin' | |
498 | if _updates and _updates[0][1] != admin_perm or \ |
|
496 | if _updates and _updates[0][1] != admin_perm or \ | |
499 | _additions and _additions[0][1] != admin_perm or \ |
|
497 | _additions and _additions[0][1] != admin_perm or \ | |
@@ -627,7 +625,7 b' class RepoRoutePredicate(object):' | |||||
627 | self.val = val |
|
625 | self.val = val | |
628 |
|
626 | |||
629 | def text(self): |
|
627 | def text(self): | |
630 |
return 'repo_route = |
|
628 | return f'repo_route = {self.val}' | |
631 |
|
629 | |||
632 | phash = text |
|
630 | phash = text | |
633 |
|
631 | |||
@@ -639,7 +637,7 b' class RepoRoutePredicate(object):' | |||||
639 | repo_name = info['match']['repo_name'] |
|
637 | repo_name = info['match']['repo_name'] | |
640 |
|
638 | |||
641 | repo_name_parts = repo_name.split('/') |
|
639 | repo_name_parts = repo_name.split('/') | |
642 |
repo_slugs = [x for x in |
|
640 | repo_slugs = [x for x in (repo_name_slug(x) for x in repo_name_parts)] | |
643 |
|
641 | |||
644 | if repo_name_parts != repo_slugs: |
|
642 | if repo_name_parts != repo_slugs: | |
645 | # short-skip if the repo-name doesn't follow slug rule |
|
643 | # short-skip if the repo-name doesn't follow slug rule | |
@@ -666,12 +664,15 b' class RepoRoutePredicate(object):' | |||||
666 | if by_name_match: |
|
664 | if by_name_match: | |
667 | # register this as request object we can re-use later |
|
665 | # register this as request object we can re-use later | |
668 | request.db_repo = by_name_match |
|
666 | request.db_repo = by_name_match | |
|
667 | request.db_repo_name = request.db_repo.repo_name | |||
|
668 | ||||
669 | redirect_if_creating(info, by_name_match) |
|
669 | redirect_if_creating(info, by_name_match) | |
670 | return True |
|
670 | return True | |
671 |
|
671 | |||
672 | by_id_match = repo_model.get_repo_by_id(repo_name) |
|
672 | by_id_match = repo_model.get_repo_by_id(repo_name) | |
673 | if by_id_match: |
|
673 | if by_id_match: | |
674 | request.db_repo = by_id_match |
|
674 | request.db_repo = by_id_match | |
|
675 | request.db_repo_name = request.db_repo.repo_name | |||
675 | redirect_if_creating(info, by_id_match) |
|
676 | redirect_if_creating(info, by_id_match) | |
676 | return True |
|
677 | return True | |
677 |
|
678 | |||
@@ -683,7 +684,7 b' class RepoForbidArchivedRoutePredicate(o' | |||||
683 | self.val = val |
|
684 | self.val = val | |
684 |
|
685 | |||
685 | def text(self): |
|
686 | def text(self): | |
686 |
return 'repo_forbid_archived = |
|
687 | return f'repo_forbid_archived = {self.val}' | |
687 |
|
688 | |||
688 | phash = text |
|
689 | phash = text | |
689 |
|
690 | |||
@@ -713,7 +714,7 b' class RepoTypeRoutePredicate(object):' | |||||
713 | self.val = val or ['hg', 'git', 'svn'] |
|
714 | self.val = val or ['hg', 'git', 'svn'] | |
714 |
|
715 | |||
715 | def text(self): |
|
716 | def text(self): | |
716 |
return 'repo_accepted_type = |
|
717 | return f'repo_accepted_type = {self.val}' | |
717 |
|
718 | |||
718 | phash = text |
|
719 | phash = text | |
719 |
|
720 | |||
@@ -741,7 +742,7 b' class RepoGroupRoutePredicate(object):' | |||||
741 | self.val = val |
|
742 | self.val = val | |
742 |
|
743 | |||
743 | def text(self): |
|
744 | def text(self): | |
744 |
return 'repo_group_route = |
|
745 | return f'repo_group_route = {self.val}' | |
745 |
|
746 | |||
746 | phash = text |
|
747 | phash = text | |
747 |
|
748 | |||
@@ -753,7 +754,7 b' class RepoGroupRoutePredicate(object):' | |||||
753 | repo_group_name = info['match']['repo_group_name'] |
|
754 | repo_group_name = info['match']['repo_group_name'] | |
754 |
|
755 | |||
755 | repo_group_name_parts = repo_group_name.split('/') |
|
756 | repo_group_name_parts = repo_group_name.split('/') | |
756 |
repo_group_slugs = [x for x in |
|
757 | repo_group_slugs = [x for x in [repo_name_slug(x) for x in repo_group_name_parts]] | |
757 | if repo_group_name_parts != repo_group_slugs: |
|
758 | if repo_group_name_parts != repo_group_slugs: | |
758 | # short-skip if the repo-name doesn't follow slug rule |
|
759 | # short-skip if the repo-name doesn't follow slug rule | |
759 | log.warning('repo_group_name: %s is different than slug %s', repo_group_name_parts, repo_group_slugs) |
|
760 | log.warning('repo_group_name: %s is different than slug %s', repo_group_name_parts, repo_group_slugs) | |
@@ -765,6 +766,7 b' class RepoGroupRoutePredicate(object):' | |||||
765 | if by_name_match: |
|
766 | if by_name_match: | |
766 | # register this as request object we can re-use later |
|
767 | # register this as request object we can re-use later | |
767 | request.db_repo_group = by_name_match |
|
768 | request.db_repo_group = by_name_match | |
|
769 | request.db_repo_group_name = request.db_repo_group.group_name | |||
768 | return True |
|
770 | return True | |
769 |
|
771 | |||
770 | return False |
|
772 | return False | |
@@ -775,7 +777,7 b' class UserGroupRoutePredicate(object):' | |||||
775 | self.val = val |
|
777 | self.val = val | |
776 |
|
778 | |||
777 | def text(self): |
|
779 | def text(self): | |
778 |
return 'user_group_route = |
|
780 | return f'user_group_route = {self.val}' | |
779 |
|
781 | |||
780 | phash = text |
|
782 | phash = text | |
781 |
|
783 | |||
@@ -827,7 +829,7 b' class UserRoutePredicate(UserRoutePredic' | |||||
827 | supports_default = False |
|
829 | supports_default = False | |
828 |
|
830 | |||
829 | def text(self): |
|
831 | def text(self): | |
830 |
return 'user_route = |
|
832 | return f'user_route = {self.val}' | |
831 |
|
833 | |||
832 | phash = text |
|
834 | phash = text | |
833 |
|
835 | |||
@@ -836,7 +838,7 b' class UserRouteWithDefaultPredicate(User' | |||||
836 | supports_default = True |
|
838 | supports_default = True | |
837 |
|
839 | |||
838 | def text(self): |
|
840 | def text(self): | |
839 |
return 'user_with_default_route = |
|
841 | return f'user_with_default_route = {self.val}' | |
840 |
|
842 | |||
841 | phash = text |
|
843 | phash = text | |
842 |
|
844 |
General Comments 0
You need to be logged in to leave comments.
Login now