changeset 1114:4de3fa6290a7 beta

#109, added manual pull of changes for repositories that have remote location filled in. This also logs this action in journal
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 05 Mar 2011 22:59:41 +0100
parents c1eda8ec4a46
children fcb5054937f6
files rhodecode/config/routing.py rhodecode/controllers/admin/repos.py rhodecode/lib/helpers.py rhodecode/lib/hooks.py rhodecode/model/scm.py rhodecode/public/css/style.css rhodecode/templates/admin/repos/repo_edit.html
diffstat 7 files changed, 69 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/config/routing.py	Sat Mar 05 22:00:53 2011 +0100
+++ b/rhodecode/config/routing.py	Sat Mar 05 22:59:41 2011 +0100
@@ -89,6 +89,10 @@
         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')
--- a/rhodecode/controllers/admin/repos.py	Sat Mar 05 22:00:53 2011 +0100
+++ b/rhodecode/controllers/admin/repos.py	Sat Mar 05 22:59:41 2011 +0100
@@ -374,7 +374,22 @@
             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'):
--- a/rhodecode/lib/helpers.py	Sat Mar 05 22:00:53 2011 +0100
+++ b/rhodecode/lib/helpers.py	Sat Mar 05 22:59:41 2011 +0100
@@ -507,6 +507,7 @@
            '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),
@@ -518,9 +519,10 @@
     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]
@@ -533,7 +535,7 @@
     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',
@@ -543,6 +545,7 @@
            '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',
--- a/rhodecode/lib/hooks.py	Sat Mar 05 22:00:53 2011 +0100
+++ b/rhodecode/lib/hooks.py	Sat Mar 05 22:59:41 2011 +0100
@@ -91,7 +91,7 @@
     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):
--- a/rhodecode/model/scm.py	Sat Mar 05 22:00:53 2011 +0100
+++ b/rhodecode/model/scm.py	Sat Mar 05 22:59:41 2011 +0100
@@ -232,8 +232,6 @@
 
         return r, dbr
 
-
-
     def mark_for_invalidation(self, repo_name):
         """Puts cache invalidation task into db for 
         further global cache invalidation
@@ -359,6 +357,25 @@
                         == 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()
 
--- a/rhodecode/public/css/style.css	Sat Mar 05 22:00:53 2011 +0100
+++ b/rhodecode/public/css/style.css	Sat Mar 05 22:59:41 2011 +0100
@@ -1964,6 +1964,14 @@
 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;
--- a/rhodecode/templates/admin/repos/repo_edit.html	Sat Mar 05 22:00:53 2011 +0100
+++ b/rhodecode/templates/admin/repos/repo_edit.html	Sat Mar 05 22:59:41 2011 +0100
@@ -314,12 +314,11 @@
     </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>
@@ -330,6 +329,22 @@
         </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">