commit:     0764934ac9670197a051af437f586d5594235c80
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Fri May 23 21:25:08 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=0764934a

overlay.py: adds update() function

To update local database and overlay source urls, this function
has been created to allow the overlay.type functions to update
their source urls in their own methods.

source.py: Adds a stub update() function for overlay types
that don't have their own update() function.

config.py: Adds a list of supported overlay types that have their
own update() methods.

---
 layman/config.py           |  1 +
 layman/overlays/overlay.py | 34 ++++++++++++++++++++++++++++++++++
 layman/overlays/source.py  |  8 ++++++++
 3 files changed, 43 insertions(+)

diff --git a/layman/config.py b/layman/config.py
index c8fdf4f..40ee90a 100644
--- a/layman/config.py
+++ b/layman/config.py
@@ -165,6 +165,7 @@ class BareConfig(object):
             'g-sorcery_postsync' : '',
             'git_user': 'layman',
             'git_email': 'layman@localhost',
+            'support_url_updates': ['Bzr', 'cvs', 'Git', 'Mercurial', 
'Subversion'],
             }
         self._options = {
             'config': config if config else self._defaults['config'],

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 174518b..d3d81e2 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -422,6 +422,40 @@ class Overlay(object):
         return res
 
 
+    def update(self, base, available_srcs):
+        res = 1
+        first_src = True
+        result = False
+
+        if isinstance(available_srcs, str):
+            available_srcs = [available_srcs]
+
+        if self.sources[0].type in 
self.config.get_option('support_url_updates'):
+            for src in available_srcs:
+                if not first_src:
+                    self.output.info("\nTrying next source of listed 
sources...", 4)
+                try:
+                    res = self.sources[0].update(base, src)
+                    if res == 0:
+                        # Updating it worked, no need to bother 
+                        # checking other sources.
+                        self.sources[0].src = src
+                        result = True
+                        break
+                except Exception as error:
+                    self.output.warn(str(error), 4)
+                first_s = False
+        else:
+            # Update the overlay source with the remote
+            # source, assuming that it's telling the truth
+            # so it can be written to the installed.xml.
+            self.output.debug("overlay.update(); type: %s does not support"\
+                " source URL updating" % self.sources[0].type, 4)
+            self.sources[0].src = available_srcs.pop()
+            result = True
+        return (self.sources, result)
+
+
     def sync(self, base):
         self.output.debug("overlay.sync(); name = %s" % self.name, 4)
         assert len(self.sources) == 1

diff --git a/layman/overlays/source.py b/layman/overlays/source.py
index 5044156..7c9674b 100644
--- a/layman/overlays/source.py
+++ b/layman/overlays/source.py
@@ -95,6 +95,14 @@ class OverlaySource(object):
         os.makedirs(mdir)
         return True
 
+    def update(self, src):
+        '''
+        Updates the overlay source url.
+        
+        @params src: source URL.
+        '''
+        pass
+
     def sync(self, base):
         '''Sync the overlay.'''
         pass

Reply via email to