[elbe-devel] [PATCH] cdroms: move retry logic to repomanager

John Ogness john.ogness at linutronix.de
Wed Sep 28 14:38:17 CEST 2016


The retry code from commit 70be9d053872746d6c24086e0a028a49b94cc0ab
was unnecessarily complex. Moving the retry logic into the
repomanager simplifies the code significantly.

Signed-off-by: John Ogness <john.ogness at linutronix.de>
---
 elbepack/cdroms.py      | 59 +++++++++++++++++--------------------------------
 elbepack/repomanager.py | 34 ++++++++++++++++++++++++----
 2 files changed, 50 insertions(+), 43 deletions(-)

diff --git a/elbepack/cdroms.py b/elbepack/cdroms.py
index aebb80b..b1538d3 100644
--- a/elbepack/cdroms.py
+++ b/elbepack/cdroms.py
@@ -27,7 +27,6 @@ from elbepack.aptpkgutils import XMLPackage
 from elbepack.aptprogress import ElbeAcquireProgress
 from elbepack.filesystem  import Filesystem, hostfs
 from elbepack.dump        import get_initvm_pkglist
-from elbepack.shellhelper import CommandError
 from apt import Cache
 
 CDROM_SIZE = 640*1000*1000
@@ -47,22 +46,13 @@ def mk_source_cdrom(rfs, arch, codename, init_codename, target, log, cdrom_size=
     pkglist = cache.get_installed_pkgs()
 
     for pkg in pkglist:
-        retried = False
-        while True:
-            try:
-                dsc = cache.download_source( pkg.name, '/var/cache/elbe/sources' )
-                repo.includedsc( dsc )
-            except ValueError as ve:
-                log.printo( "No sources for Package " + pkg.name + "-" + pkg.installed_version )
-            except FetchError as fe:
-                log.printo( "Source for Package " + pkg.name + "-" + pkg.installed_version + " could not be downloaded" )
-            except CommandError as ce:
-                if retried:
-                    raise ce
-                repo.removesrc(dsc)
-                retried = True
-                continue
-            break
+        try:
+            dsc = cache.download_source( pkg.name, '/var/cache/elbe/sources' )
+            repo.includedsc( dsc, force=True )
+        except ValueError as ve:
+            log.printo( "No sources for Package " + pkg.name + "-" + pkg.installed_version )
+        except FetchError as fe:
+            log.printo( "Source for Package " + pkg.name + "-" + pkg.installed_version + " could not be downloaded" )
 
     repo.finalize ()
 
@@ -150,28 +140,19 @@ def mk_binary_cdrom(rfs, arch, codename, init_codename, xml, target, log, cdrom_
     cache = get_rpcaptcache( rfs, "aptcache.log", arch )
     pkglist = cache.get_installed_pkgs ()
     for pkg in pkglist:
-        retried = False
-        while True:
-            try:
-                deb = cache.download_binary( pkg.name,
-                                            '/var/cache/elbe/binaries/added',
-                                            pkg.installed_version )
-                target_repo.includedeb(deb, 'added')
-            except KeyError as ke:
-                log.printo( str (ke) )
-            except ValueError as ve:
-                log.printo( "No Package " + pkg.name + "-" + pkg.installed_version )
-            except FetchError as fe:
-                log.printo( "Package " + pkg.name + "-" + str (pkg.installed_version) + " could not be downloaded" )
-            except TypeError as te:
-                log.printo( "Package " + pkg.name + "-" + pkg.installed_version + " missing name or version" )
-            except CommandError as ce:
-                if retried:
-                    raise ce
-                target_repo.removedeb(pkg.name, 'added')
-                retried = True
-                continue
-            break
+        try:
+            deb = cache.download_binary( pkg.name,
+                                        '/var/cache/elbe/binaries/added',
+                                        pkg.installed_version )
+            target_repo.includedeb(deb, 'added', pkg.name, True)
+        except KeyError as ke:
+            log.printo( str (ke) )
+        except ValueError as ve:
+            log.printo( "No Package " + pkg.name + "-" + pkg.installed_version )
+        except FetchError as fe:
+            log.printo( "Package " + pkg.name + "-" + str (pkg.installed_version) + " could not be downloaded" )
+        except TypeError as te:
+            log.printo( "Package " + pkg.name + "-" + pkg.installed_version + " missing name or version" )
 
     repo.finalize()
     target_repo.finalize ()
diff --git a/elbepack/repomanager.py b/elbepack/repomanager.py
index 2e93168..d421e9a 100644
--- a/elbepack/repomanager.py
+++ b/elbepack/repomanager.py
@@ -22,6 +22,7 @@ from elbepack.filesystem import Filesystem
 from elbepack.pkgutils import get_dsc_size
 from debian.deb822 import Deb822
 from elbepack.gpg import generate_elbe_internal_key, export_key
+from elbepack.shellhelper import CommandError
 
 class RepoAttributes(object):
     def __init__ (self, codename, arch, components,
@@ -159,8 +160,21 @@ class RepoBase(object):
 
         self.log.do( 'reprepro --keepunreferencedfiles --export=never --basedir "' + self.fs.path + '" -C ' + component + ' includedeb ' + codename + ' ' + path )
 
-    def includedeb (self, path, component="main"):
-        self._includedeb (path, self.repo_attr.codename, component)
+    def includedeb (self, path, component="main", pkgname=None, force=False):
+        # pkgname needs only to be specified if force is enabled
+        try:
+            self._includedeb (path, self.repo_attr.codename, component)
+        except CommandError as ce:
+            if force and not pkgname is None:
+                # Including deb did not work.
+                # Maybe we have the same Version with a
+                # different md5 already.
+                #
+                # Try remove, and add again.
+                self.removedeb(pkgname, component)
+                self._includedeb (path, self.repo_attr.codename, component)
+            else:
+                raise ce
 
     def include_init_deb (self, path, component="main"):
         self._includedeb (path, self.init_attr.codename, component)
@@ -201,8 +215,20 @@ class RepoBase(object):
 
         self.log.do( 'reprepro --keepunreferencedfiles --export=never --basedir "' + self.fs.path  + '" -C ' + component + ' -P normal -S misc includedsc ' + codename + ' ' + path )
 
-    def includedsc( self, path, component="main"):
-        self._includedsc (path, self.repo_attr.codename, component)
+    def includedsc( self, path, component="main", force=False):
+        try:
+            self._includedsc (path, self.repo_attr.codename, component)
+        except CommandError as ce:
+            if force:
+                # Including dsc did not work.
+                # Maybe we have the same Version with a
+                # different md5 already.
+                #
+                # Try remove, and add again.
+                self.removesrc(path, component)
+                self._includedsc (path, self.repo_attr.codename, component)
+            else:
+                raise ce
 
     def include( self, path, component="main"):
         self._include (path, self.repo_attr.codename, component)
-- 
2.9.3




More information about the elbe-devel mailing list