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