commit: 2c8417794872d797ef816760d5d9161c90f449fc Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org> AuthorDate: Fri May 30 01:19:52 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=2c841779
mercurial.py: Adds update() function Also adds _fix_mercurial_source() function to be used by add() and update(). --- layman/overlays/mercurial.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/layman/overlays/mercurial.py b/layman/overlays/mercurial.py index c188381..74f1934 100644 --- a/layman/overlays/mercurial.py +++ b/layman/overlays/mercurial.py @@ -27,6 +27,7 @@ __version__ = "$Id: mercurial.py 236 2006-09-05 20:39:37Z wrobel $" # #------------------------------------------------------------------------------- +import re from layman.utils import path from layman.overlays.source import OverlaySource, require_supported @@ -49,6 +50,16 @@ class MercurialOverlay(OverlaySource): config, _location, ignore) self.subpath = None + def _fix_mercurial_source(self, source): + ''' + Adds trailing slash to source URL if needed. + + @params source: source URL, string. + ''' + if source.endswith("/"): + return source + return source + '/' + def add(self, base): '''Add overlay.''' @@ -58,10 +69,7 @@ class MercurialOverlay(OverlaySource): cfg_opts = self.config["mercurial_addopts"] target = path([base, self.parent.name]) - if self.src.endswith("/"): - src = self.src - else: - src = self.src + '/' + src = self._fix_mercurial_source(self.src) # hg clone SOURCE TARGET if len(cfg_opts): @@ -73,6 +81,30 @@ class MercurialOverlay(OverlaySource): self.run_command(self.command(), args, 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]) + hgrc = ".hg/hgrc" + + old_src = re.sub('/', '\/', self._fix_mercurial_source(self.src)) + new_src = re.sub('/', '\/', self._fix_mercurial_source(src)) + expression = "s/" + old_src + "/" + new_src + "/" + + # sed -i 's/oldurl/newurl/' <target>/.hg/hgrc + args = ['-i', expression, hgrc] + + # Run sed. + return self.run_command('sed', args, cmd='sed', cwd=target) + def sync(self, base): '''Sync overlay.'''