aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevan Franchini <twitch153@gentoo.org>2014-05-23 18:07:07 -0400
committerDevan Franchini <twitch153@gentoo.org>2014-06-12 17:11:49 -0400
commitf7896d0585a82f73cb20fb0d5a6e7ea7e50c77b3 (patch)
treeddc1fbc76d5c14eda498a5db8325137079c0565f /layman/api.py
parentcvs.py: Adds update() function (diff)
downloadlayman-f7896d0585a82f73cb20fb0d5a6e7ea7e50c77b3.tar.gz
layman-f7896d0585a82f73cb20fb0d5a6e7ea7e50c77b3.tar.bz2
layman-f7896d0585a82f73cb20fb0d5a6e7ea7e50c77b3.zip
api.py: incorporates db.update() in api.sync()
Diffstat (limited to 'layman/api.py')
-rwxr-xr-xlayman/api.py83
1 files changed, 52 insertions, 31 deletions
diff --git a/layman/api.py b/layman/api.py
index b5b6a2a..413f8d0 100755
--- a/layman/api.py
+++ b/layman/api.py
@@ -342,6 +342,49 @@ class LaymanAPI(object):
return True, msg
return False, ''
+ def _verify_overlay_source(self, odb, ordb)
+ """
+ Verifies the overlay source url against the source url(s)
+ reported by the remote database.
+
+ @param odb: local database of overlay information.
+ @param ordb: remote database of overlay information.
+ @rtype (boolean, msg)
+ """
+ current_src = odb.sources[0].src
+ (available_srcs, valid) = verify_overlay_src(current_src,
+ set(e.src for e in ordb.sources))
+
+ if ordb and odb and not valid:
+ update_url = True
+ if len(available_srcs) == 1:
+ plural = ''
+ candidates = ' %s' % tuple(available_srcs)[0]
+ else:
+ plural = 's'
+ candidates = '\n'.join((' %d. %s' % (ovl + 1, v)) \
+ for ovl, v in enumerate(available_srcs))
+ msg = 'The source of the overlay "%(repo_name)s" seems to have changed.\n'\
+ 'You currently sync from\n'\
+ '\n'\
+ ' %(current_src)s\n'
+ '\n'\
+ 'while the remote lists report\n'\
+ '\n'\
+ '%(candidates)s\n'\
+ '\n'\
+ 'as correct location%(plural)s.\n'\
+ '\n'\
+ 'Repo: "%(repo_name)s" will be updated...' %\
+ ({
+ 'repo_name':odb.name,
+ 'current_src':current_src,
+ 'candidates':candidates,
+ 'plural':plural,
+ })
+ return True, msg
+ return False, ''
+
def sync(self, repos, output_results=True, update_news=False):
"""syncs the specified repo(s) specified by repos
@@ -360,6 +403,7 @@ class LaymanAPI(object):
self.output.debug("API.sync(); starting ovl loop", 5)
for ovl in repos:
+ update_url = False
self.output.debug("API.sync(); starting ovl = %s" %ovl, 5)
try:
#self.output.debug("API.sync(); selecting %s, db = %s" % (ovl, str(db)), 5)
@@ -384,39 +428,9 @@ class LaymanAPI(object):
warnings.append((ovl, message))
else:
self.output.debug("API.sync(); else: self._get_remote_db().select(ovl)", 5)
- current_src = odb.sources[0].src
- (available_srcs, valid) = verify_overlay_src(current_src,
- set(e.src for e in ordb.sources))
(diff_type, type_msg) = self._verify_overlay_type(odb, ordb)
-
- if ordb and odb and not valid:
- if len(available_srcs) == 1:
- plural = ''
- candidates = ' %s' % tuple(available_srcs)[0]
- else:
- plural = 's'
- candidates = '\n'.join((' %d. %s' % (ovl + 1, v)) \
- for ovl, v in enumerate(available_srcs))
-
- warnings.append((ovl,
- 'The source of the overlay "%(repo_name)s" seems to have changed.\n'
- 'You currently sync from\n'
- '\n'
- ' %(current_src)s\n'
- '\n'
- 'while the remote lists report\n'
- '\n'
- '%(candidates)s\n'
- '\n'
- 'as correct location%(plural)s.\n'
- 'Please consider removing and re-adding the overlay.' %
- {
- 'repo_name':ovl,
- 'current_src':current_src,
- 'candidates':candidates,
- 'plural':plural,
- }))
+ (update_url, url_msg) = self._verify_overlay_source(odb, ordb)
try:
if diff_type:
@@ -425,6 +439,13 @@ class LaymanAPI(object):
self.readd_repos(ovl)
success.append((ovl, 'Successfully readded overlay "' + ovl + '".'))
else:
+ if update_url:
+ self.output.debug("API.sync() starting db.update(ovl)", 5)
+ warnings.append((ovl, url_msg))
+ update_success = db.update(ordb, available_srcs)
+ if not update_success:
+ self.output.warn('Failed to update repo...readding', 2)
+ self.readd_repos(ovl)
self.output.debug("API.sync(); starting db.sync(ovl)", 5)
db.sync(ovl)
success.append((ovl,'Successfully synchronized overlay "' + ovl + '".'))