Changeset - 4de3fa6290a7
[Not reviewed]
beta
0 7 0
Marcin Kuzminski - 15 years ago 2011-03-05 22:59:41
marcin@python-works.com
#109, added manual pull of changes for repositories that have remote location filled in.
This also logs this action in journal
7 files changed with 69 insertions and 7 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/routing.py
Show inline comments
 
@@ -86,12 +86,16 @@ def make_map(config):
 
        m.connect('repo_cache', "/repos_cache/{repo_name:.*}",
 
             action="repo_cache", conditions=dict(method=["DELETE"],
 
                                                        function=check_repo))
 
        m.connect('repo_public_journal', "/repos_public_journal/{repo_name:.*}",
 
             action="repo_public_journal", conditions=dict(method=["PUT"],
 
                                                        function=check_repo))
 
        m.connect('repo_pull', "/repo_pull/{repo_name:.*}",
 
             action="repo_pull", conditions=dict(method=["PUT"],
 
                                                        function=check_repo))
 

	
 

	
 
    #ADMIN USER REST ROUTES
 
    routes_map.resource('user', 'users', controller='admin/users', path_prefix='/_admin')
 

	
 
    #ADMIN USER REST ROUTES
 
    routes_map.resource('users_group', 'users_groups', controller='admin/users_groups', path_prefix='/_admin')
rhodecode/controllers/admin/repos.py
Show inline comments
 
@@ -371,13 +371,28 @@ class ReposController(BaseController):
 
                        category='error')
 

	
 
        else:
 
            h.flash(_('Token mismatch'), category='error')
 
        return redirect(url('edit_repo', repo_name=repo_name))
 

	
 
    @HasPermissionAllDecorator('hg.admin')
 
    def repo_pull(self, repo_name):
 
        """
 
        Runs task to update given repository with remote changes,
 
        ie. make pull on remote location
 
        
 
        :param repo_name:
 
        """
 
        try:
 
            ScmModel().pull_changes(repo_name, c.rhodecode_user.username)
 
            h.flash(_('Pulled from remote location'), category='success')
 
        except Exception, e:
 
            h.flash(_('An error occurred during pull from remote location'),
 
                    category='error')
 

	
 
        return redirect(url('edit_repo', repo_name=repo_name))
 

	
 
    @HasPermissionAllDecorator('hg.admin')
 
    def show(self, repo_name, format='html'):
 
        """GET /repos/repo_name: Show a specific item"""
 
        # url('repo', repo_name=ID)
 

	
rhodecode/lib/helpers.py
Show inline comments
 
@@ -504,48 +504,51 @@ def action_parser(user_log, feed=False):
 
           'user_updated_repo':(_('[updated] repository'), None),
 
           'admin_deleted_repo':(_('[delete] repository'), None),
 
           'admin_created_repo':(_('[created] repository'), None),
 
           'admin_forked_repo':(_('[forked] repository'), None),
 
           'admin_updated_repo':(_('[updated] repository'), None),
 
           'push':(_('[pushed] into'), get_cs_links),
 
           'push_remote':(_('[pulled from remote] into'), get_cs_links),
 
           'pull':(_('[pulled] from'), None),
 
           'started_following_repo':(_('[started following] repository'), None),
 
           'stopped_following_repo':(_('[stopped following] repository'), None),
 
            }
 

	
 
    action_str = action_map.get(action, action)
 
    if feed:
 
        action = action_str[0].replace('[', '').replace(']', '')
 
    else:
 
        action = action_str[0].replace('[', '<span class="journal_highlight">')\
 
                   .replace(']', '</span>')
 

	
 
    action_params_func = lambda :""
 

	
 
    if action_str[1] is not None:
 
    if callable(action_str[1]):
 
        action_params_func = action_str[1]
 

	
 
    return [literal(action), action_params_func]
 

	
 
def action_parser_icon(user_log):
 
    action = user_log.action
 
    action_params = None
 
    x = action.split(':')
 

	
 
    if len(x) > 1:
 
        action, action_params = x
 

	
 
    tmpl = """<img src="%s/%s" alt="%s"/>"""
 
    tmpl = """<img src="%s%s" alt="%s"/>"""
 
    map = {'user_deleted_repo':'database_delete.png',
 
           'user_created_repo':'database_add.png',
 
           'user_forked_repo':'arrow_divide.png',
 
           'user_updated_repo':'database_edit.png',
 
           'admin_deleted_repo':'database_delete.png',
 
           'admin_created_repo':'database_add.png',
 
           'admin_forked_repo':'arrow_divide.png',
 
           'admin_updated_repo':'database_edit.png',
 
           'push':'script_add.png',
 
           'push_remote':'connect.png',
 
           'pull':'down_16.png',
 
           'started_following_repo':'heart_add.png',
 
           'stopped_following_repo':'heart_delete.png',
 
            }
 
    return literal(tmpl % ((url('/images/icons/')),
 
                           map.get(action, action), action))
rhodecode/lib/hooks.py
Show inline comments
 
@@ -88,13 +88,13 @@ def log_push_action(ui, repo, **kwargs):
 
    :param repo:
 
    """
 

	
 
    extra_params = dict(repo.ui.configitems('rhodecode_extras'))
 
    username = extra_params['username']
 
    repository = extra_params['repository']
 
    action = 'push:%s'
 
    action = extra_params['action'] + ':%s'
 
    node = kwargs['node']
 

	
 
    def get_revs(repo, rev_opt):
 
        if rev_opt:
 
            revs = revrange(repo, rev_opt)
 

	
rhodecode/model/scm.py
Show inline comments
 
@@ -229,14 +229,12 @@ class ScmModel(BaseModel):
 
            dbr = RepoModel().get_full(repo_name, cache=True,
 
                                          invalidate=dbinvalidate)
 

	
 

	
 
        return r, dbr
 

	
 

	
 

	
 
    def mark_for_invalidation(self, repo_name):
 
        """Puts cache invalidation task into db for 
 
        further global cache invalidation
 
        
 
        :param repo_name: this repo that should invalidation take place
 
        """
 
@@ -356,12 +354,31 @@ class ScmModel(BaseModel):
 
        else:
 
            return self.sa.query(Repository)\
 
                .filter(Repository.fork \
 
                        == RepoModel().get_by_repo_name(repo_id)).count()
 

	
 

	
 
    def pull_changes(self, repo_name, username):
 
        repo, dbrepo = self.get(repo_name, retval='all')
 

	
 
        try:
 
            extras = {'ip':'',
 
                      'username':username,
 
                      'action':'push_remote',
 
                      'repository':repo_name}
 

	
 
            #inject ui extra param to log this action via push logger        
 
            for k, v in extras.items():
 
                repo._repo.ui.setconfig('rhodecode_extras', k, v)
 

	
 
            repo.pull(dbrepo.clone_uri)
 
            self.mark_for_invalidation(repo_name)
 
        except:
 
            log.error(traceback.format_exc())
 
            raise
 

	
 
    def get_unread_journal(self):
 
        return self.sa.query(UserLog).count()
 

	
 

	
 
    def _should_invalidate(self, repo_name):
 
        """Looks up database for invalidation signals for this repo_name
rhodecode/public/css/style.css
Show inline comments
 
@@ -1961,12 +1961,20 @@ background:url("../images/icons/arrow_re
 
height:16px;
 
padding-left:20px;
 
padding-top:1px;
 
text-align:left;
 
}
 
 
.pull_icon {
 
background:url("../images/icons/connect.png") no-repeat scroll 3px;
 
height:16px;
 
padding-left:20px;
 
padding-top:1px;
 
text-align:left;
 
}
 
 
.rss_icon {
 
background:url("../images/icons/rss_16.png") no-repeat scroll 3px;
 
height:16px;
 
padding-left:20px;
 
padding-top:1px;
 
text-align:left;
rhodecode/templates/admin/repos/repo_edit.html
Show inline comments
 
@@ -311,28 +311,43 @@
 
<div class="box box-right">
 
    <div class="title">
 
        <h5>${_('Administration')}</h5>    
 
    </div>
 
    
 
        <h3>${_('Statistics')}</h3>
 
        
 
        ${h.form(url('repo_stats', repo_name=c.repo_info.repo_name),method='delete')}
 
        <div class="form">
 
           <div class="fields">
 
               ${h.submit('reset_stats_%s' % c.repo_info.repo_name,_('Reset current statistics'),class_="refresh_icon action_button",onclick="return confirm('Confirm to remove current statistics');")}
 
               <div class="field">
 
               <div class="field" style="border:none">
 
               <ul>
 
                    <li>${_('Fetched to rev')}: ${c.stats_revision}/${c.repo_last_rev}</li>
 
                    <li>${_('Percentage of stats gathered')}: ${c.stats_percentage} %</li>
 
               </ul>
 
               </div>
 
               
 
           </div>
 
        </div>                    
 
        ${h.end_form()}
 
        
 
        %if c.repo_info.clone_uri:
 
        <h3>${_('Remote')}</h3>
 
        ${h.form(url('repo_pull', repo_name=c.repo_info.repo_name),method='put')}
 
        <div class="form">
 
           <div class="fields">
 
               ${h.submit('remote_pull_%s' % c.repo_info.repo_name,_('Pull changes from remote location'),class_="pull_icon action_button",onclick="return confirm('Confirm to pull changes from remote side');")}
 
               <div class="field" style="border:none">
 
               <ul>
 
                    <li><a href="${c.repo_info.clone_uri}">${c.repo_info.clone_uri}</a></li>
 
               </ul> 
 
               </div>              
 
           </div>
 
        </div>                    
 
        ${h.end_form()}
 
        %endif
 
        
 
        <h3>${_('Cache')}</h3>
 
        ${h.form(url('repo_cache', repo_name=c.repo_info.repo_name),method='delete')}
 
        <div class="form">
 
           <div class="fields">
 
               ${h.submit('reset_cache_%s' % c.repo_info.repo_name,_('Invalidate repository cache'),class_="refresh_icon action_button",onclick="return confirm('Confirm to invalidate repository cache');")}
 
           </div>
0 comments (0 inline, 0 general)