##// END OF EJS Templates
summary: Move logic to find a readme out...
johbo -
r768:95f8a91c default
parent child Browse files
Show More
@@ -44,6 +44,8 b' from rhodecode.lib.vcs.backends.base imp'
44 from rhodecode.lib.vcs.exceptions import (
44 from rhodecode.lib.vcs.exceptions import (
45 CommitError, EmptyRepositoryError, NodeDoesNotExistError)
45 CommitError, EmptyRepositoryError, NodeDoesNotExistError)
46 from rhodecode.model.db import Statistics, CacheKey, User
46 from rhodecode.model.db import Statistics, CacheKey, User
47 from rhodecode.model.repo import ReadmeFinder
48
47
49
48 log = logging.getLogger(__name__)
50 log = logging.getLogger(__name__)
49
51
@@ -63,26 +65,21 b' class SummaryController(BaseRepoControll'
63 readme_data = None
65 readme_data = None
64 readme_file = None
66 readme_file = None
65 try:
67 try:
66 # gets the landing revision or tip if fails
68 # Find the landing commit
67 commit = db_repo.get_landing_commit()
69 commit = db_repo.get_landing_commit()
68 if isinstance(commit, EmptyCommit):
70 if isinstance(commit, EmptyCommit):
69 raise EmptyRepositoryError()
71 raise EmptyRepositoryError()
70 renderer = MarkupRenderer()
72
71 for f in renderer.pick_readme_order(default_renderer):
73 readme_file = ReadmeFinder(default_renderer).search(commit)
72 try:
73 node = commit.get_node(f)
74 except NodeDoesNotExistError:
75 continue
76
74
77 if not node.is_file():
75 # Render the readme if one was found
78 continue
76 if readme_file:
79
77 renderer = MarkupRenderer()
80 readme_file = f
78 node = commit.get_node(readme_file)
81 log.debug('Found README file `%s` rendering...',
79 log.debug('Found README file `%s` rendering...',
82 readme_file)
80 readme_file)
83 readme_data = renderer.render(node.content,
81 readme_data = renderer.render(
84 filename=f)
82 node.content, filename=readme_file)
85 break
86 except CommitError:
83 except CommitError:
87 log.exception(
84 log.exception(
88 "Problem getting commit when trying to render the README.")
85 "Problem getting commit when trying to render the README.")
@@ -40,11 +40,13 b' from rhodecode.lib.auth import HasUserGr'
40 from rhodecode.lib.caching_query import FromCache
40 from rhodecode.lib.caching_query import FromCache
41 from rhodecode.lib.exceptions import AttachedForksError
41 from rhodecode.lib.exceptions import AttachedForksError
42 from rhodecode.lib.hooks_base import log_delete_repository
42 from rhodecode.lib.hooks_base import log_delete_repository
43 from rhodecode.lib.markup_renderer import MarkupRenderer
43 from rhodecode.lib.utils import make_db_config
44 from rhodecode.lib.utils import make_db_config
44 from rhodecode.lib.utils2 import (
45 from rhodecode.lib.utils2 import (
45 safe_str, safe_unicode, remove_prefix, obfuscate_url_pw,
46 safe_str, safe_unicode, remove_prefix, obfuscate_url_pw,
46 get_current_rhodecode_user, safe_int, datetime_to_time, action_logger_generic)
47 get_current_rhodecode_user, safe_int, datetime_to_time, action_logger_generic)
47 from rhodecode.lib.vcs.backends import get_backend
48 from rhodecode.lib.vcs.backends import get_backend
49 from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError
48 from rhodecode.model import BaseModel
50 from rhodecode.model import BaseModel
49 from rhodecode.model.db import (
51 from rhodecode.model.db import (
50 Repository, UserRepoToPerm, UserGroupRepoToPerm, UserRepoGroupToPerm,
52 Repository, UserRepoToPerm, UserGroupRepoToPerm, UserRepoGroupToPerm,
@@ -933,3 +935,34 b' class RepoModel(BaseModel):'
933
935
934 if os.path.isdir(rm_path):
936 if os.path.isdir(rm_path):
935 shutil.move(rm_path, os.path.join(self.repos_path, _d))
937 shutil.move(rm_path, os.path.join(self.repos_path, _d))
938
939
940 class ReadmeFinder:
941 """
942 Utility which knows how to find a readme for a specific commit.
943
944 The main idea is that this is a configurable algorithm. When creating an
945 instance you can define parameters, currently only the `default_renderer`.
946 Based on this configuration the method :meth:`search` behaves slightly
947 different.
948 """
949
950 def __init__(self, default_renderer):
951 self._default_renderer = default_renderer
952
953 def search(self, commit):
954 """
955 Try to find a readme in the given `commit`.
956 """
957 renderer = MarkupRenderer()
958 for f in renderer.pick_readme_order(self._default_renderer):
959 log.debug("Trying README %s", f)
960 try:
961 node = commit.get_node(f)
962 except NodeDoesNotExistError:
963 continue
964
965 if not node.is_file():
966 continue
967
968 return f
General Comments 0
You need to be logged in to leave comments. Login now