##// 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 44 from rhodecode.lib.vcs.exceptions import (
45 45 CommitError, EmptyRepositoryError, NodeDoesNotExistError)
46 46 from rhodecode.model.db import Statistics, CacheKey, User
47 from rhodecode.model.repo import ReadmeFinder
48
47 49
48 50 log = logging.getLogger(__name__)
49 51
@@ -63,26 +65,21 b' class SummaryController(BaseRepoControll'
63 65 readme_data = None
64 66 readme_file = None
65 67 try:
66 # gets the landing revision or tip if fails
68 # Find the landing commit
67 69 commit = db_repo.get_landing_commit()
68 70 if isinstance(commit, EmptyCommit):
69 71 raise EmptyRepositoryError()
72
73 readme_file = ReadmeFinder(default_renderer).search(commit)
74
75 # Render the readme if one was found
76 if readme_file:
70 77 renderer = MarkupRenderer()
71 for f in renderer.pick_readme_order(default_renderer):
72 try:
73 node = commit.get_node(f)
74 except NodeDoesNotExistError:
75 continue
76
77 if not node.is_file():
78 continue
79
80 readme_file = f
78 node = commit.get_node(readme_file)
81 79 log.debug('Found README file `%s` rendering...',
82 80 readme_file)
83 readme_data = renderer.render(node.content,
84 filename=f)
85 break
81 readme_data = renderer.render(
82 node.content, filename=readme_file)
86 83 except CommitError:
87 84 log.exception(
88 85 "Problem getting commit when trying to render the README.")
@@ -40,11 +40,13 b' from rhodecode.lib.auth import HasUserGr'
40 40 from rhodecode.lib.caching_query import FromCache
41 41 from rhodecode.lib.exceptions import AttachedForksError
42 42 from rhodecode.lib.hooks_base import log_delete_repository
43 from rhodecode.lib.markup_renderer import MarkupRenderer
43 44 from rhodecode.lib.utils import make_db_config
44 45 from rhodecode.lib.utils2 import (
45 46 safe_str, safe_unicode, remove_prefix, obfuscate_url_pw,
46 47 get_current_rhodecode_user, safe_int, datetime_to_time, action_logger_generic)
47 48 from rhodecode.lib.vcs.backends import get_backend
49 from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError
48 50 from rhodecode.model import BaseModel
49 51 from rhodecode.model.db import (
50 52 Repository, UserRepoToPerm, UserGroupRepoToPerm, UserRepoGroupToPerm,
@@ -933,3 +935,34 b' class RepoModel(BaseModel):'
933 935
934 936 if os.path.isdir(rm_path):
935 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