Commit fcc17c82 authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

source.py: Stylistic changes in Source.__do_fetch()

Added some comments to make the flow easier to follow, and
removed an annoying 'success' variabled in favor of a for / else
loop statement.
parent 8aec1102
Loading
Loading
Loading
Loading
+15 −3
Original line number Original line Diff line number Diff line
@@ -865,10 +865,12 @@ class Source(Plugin):
    def __do_fetch(self, **kwargs):
    def __do_fetch(self, **kwargs):
        project = self._get_project()
        project = self._get_project()
        source_fetchers = self.get_source_fetchers()
        source_fetchers = self.get_source_fetchers()

        # Use the source fetchers if they are provided
        #
        if source_fetchers:
        if source_fetchers:
            for fetcher in source_fetchers:
            for fetcher in source_fetchers:
                alias = fetcher._get_alias()
                alias = fetcher._get_alias()
                success = False
                for uri in project.get_alias_uris(alias, first_pass=self.__first_pass):
                for uri in project.get_alias_uris(alias, first_pass=self.__first_pass):
                    try:
                    try:
                        fetcher.fetch(uri)
                        fetcher.fetch(uri)
@@ -877,10 +879,16 @@ class Source(Plugin):
                    except BstError as e:
                    except BstError as e:
                        last_error = e
                        last_error = e
                        continue
                        continue
                    success = True

                    # No error, we're done with this fetcher
                    break
                    break
                if not success:

                else:
                    # No break occurred, raise the last detected error
                    raise last_error
                    raise last_error

        # Default codepath is to reinstantiate the Source
        #
        else:
        else:
            alias = self._get_alias()
            alias = self._get_alias()
            if self.__first_pass:
            if self.__first_pass:
@@ -904,7 +912,11 @@ class Source(Plugin):
                except BstError as e:
                except BstError as e:
                    last_error = e
                    last_error = e
                    continue
                    continue

                # No error, we're done here
                return
                return

            # Re raise the last detected error
            raise last_error
            raise last_error


    # Tries to call track for every mirror, stopping once it succeeds
    # Tries to call track for every mirror, stopping once it succeeds