commit:     e44f6726b5162cbc3026e9047878e2def78a562a
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Fri May 30 20:54:12 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Thu Jun 12 21:11:49 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=e44f6726

cvs.py: Adds update() function

---
 layman/overlays/cvs.py | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/layman/overlays/cvs.py b/layman/overlays/cvs.py
index b166dc8..bf54921 100644
--- a/layman/overlays/cvs.py
+++ b/layman/overlays/cvs.py
@@ -27,6 +27,7 @@ __version__ = "$Id$"
 
#-------------------------------------------------------------------------------
 
 import xml.etree.ElementTree as ET # Python 2.5
+import re
 
 from   layman.utils             import path
 from   layman.overlays.source   import OverlaySource, require_supported
@@ -90,6 +91,42 @@ class CvsOverlay(OverlaySource):
                 env=dict(CVSROOT=self.src), cmd=self.type),
             cwd=target)
 
+    def update(self, base, src):
+        '''
+        Updates overlay src-url.
+        
+        @params base: base location where all overlays are installed.
+        @params src: source URL.
+        '''
+        
+        if not self.supported():
+            return 1
+
+        target = path([base, self.parent.name])
+        
+        # First echo the new repository to CVS/Root
+        args = [src, '>', '/CVS/Root']
+        result = self.run_command('echo', args, cmd='echo', cwd=target)
+
+        if result == 0:
+            location = src.split(':')[3]
+            old_location = self.src.split(':/')[3]
+    
+            # Check if the repository location needs to be updated too.
+            if not location == old_location:
+                location = re.sub('/', '\/', location)
+                old_location = re.sub('/', '\/', old_location)
+                
+                expression = 's/' + old_location + '/' + location + '/'
+
+                # sed -i 's/<old_location>/<new_location>/ 
<target>/CVS/Repository
+                args = ['-i', expression, '/CVS/Repository']
+
+                return self.run_command('sed', args, cmd='sed', cwd=target)
+
+        return result        
+        
+
     def sync(self, base):
         '''Sync overlay.'''
 

Reply via email to